From 540d161bcb526efef2152f8e791a02e0361f2aae Mon Sep 17 00:00:00 2001 From: Sunil Nimmagadda Date: Fri, 30 Oct 2026 14:41:56 +0530 Subject: header: Set some correct defaults. --- elf/header.lua | 8 +++++--- mkelf.lua | 1 - 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/elf/header.lua b/elf/header.lua index c0b8eab..a5fc78a 100644 --- a/elf/header.lua +++ b/elf/header.lua @@ -37,13 +37,15 @@ function M.normalize(hdr) hdr.abiversion = hdr.abiversion or 0 hdr.version = hdr.version or ec.VERSION hdr.entry = hdr.entry or 0 - hdr.phoff = hdr.phoff or 0 + hdr.phoff = hdr.phoff or ((hdr.class == ec.Class.bit32) and 0x34 or 0x40) hdr.shoff = hdr.shoff or 0 hdr.flags = hdr.flags or 0 hdr.ehsize = hdr.ehsize or ((hdr.class == ec.Class.bit32) and 0x34 or 0x40) - hdr.phentsize = hdr.phentsize or 0 + hdr.phentsize = hdr.phentsize or + ((hdr.class == ec.Class.bit32) and 0x20 or 0x38) hdr.phnum = hdr.phnum or 0 - hdr.shentsize = hdr.shentsize or 0 + hdr.shentsize = hdr.shentsize or + ((hdr.class == ec.Class.bit32) and 0x28 or 0x40) hdr.shnum = hdr.shnum or 0 hdr.shstrndx = hdr.shstrndx or 0 end diff --git a/mkelf.lua b/mkelf.lua index 0ff68b9..b22f064 100644 --- a/mkelf.lua +++ b/mkelf.lua @@ -89,7 +89,6 @@ local function main() end local header, segments, sections = loadconfig(infn) header.phnum = #segments - header.phentsize = (header.class == ec.Class.bit64) and 0x38 or 0x20 local out = assert(io.open(outfn, "wb")) out:write(header:pack()) for _, segment in ipairs(segments) do -- cgit v1.3