aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSunil Nimmagadda <sunil@nimmagadda.net>2026-10-30 14:41:56 +0530
committerSunil Nimmagadda <sunil@nimmagadda.net>2026-10-30 14:50:21 +0530
commit540d161bcb526efef2152f8e791a02e0361f2aae (patch)
treeb8769e66496039235707973ea213e4442f12a9e6
parentd7520a75f01194a22f433c682e99b4482808f443 (diff)
header: Set some correct defaults.
-rw-r--r--elf/header.lua8
-rw-r--r--mkelf.lua1
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 <close> = assert(io.open(outfn, "wb"))
out:write(header:pack())
for _, segment in ipairs(segments) do