summaryrefslogtreecommitdiff
path: root/mkelf.lua
diff options
context:
space:
mode:
Diffstat (limited to 'mkelf.lua')
-rw-r--r--mkelf.lua22
1 files changed, 11 insertions, 11 deletions
diff --git a/mkelf.lua b/mkelf.lua
index 3775956..6edeebb 100644
--- a/mkelf.lua
+++ b/mkelf.lua
@@ -11,9 +11,9 @@ local function usage()
end
---@param fn string|nil
----@return {header: Header, sections: Section[], segments: Segment[]}
+---@return Header, Segment[], Section[]
local function loadconfig(fn)
- local spec = {}
+ local header, segments, sections = {}, {}, {}
local env = {
-- Keep in sync with types/elf.d.lua
Class = elf.Class,
@@ -25,16 +25,16 @@ local function loadconfig(fn)
SegmentFlags = elf.SegmentFlags,
ELFVERSION = elf.VERSION,
- header = function(t) spec.header = t end,
- sections = function(t) spec.sections = t end,
- segments = function(t) spec.segments = t end,
+ header = function(t) header = t end,
+ segments = function(t) segments = t end,
+ sections = function(t) sections = t end,
}
-- TODO error check for multiple headers
local chunk, err = loadfile(fn, "t", env)
if not chunk then die("%s", err) end
local ok, perr = pcall(chunk)
if not ok then die("%s", perr) end
- return spec
+ return header, segments, sections
end
local function main()
@@ -51,13 +51,13 @@ local function main()
end
i = i + 1
end
- local c = loadconfig(infn)
- c.header.phnum = #c.segments
- c.header.phentsize = (c.header.class == ec.Class.bit64) and 0x38 or 0x20
+ local header, segments, sections = loadconfig(infn)
+ header.phnum = #segments
+ header.phentsize = (header.class == ec.Class.bit64) and 0x38 or 0x20
-- TODO write to a temp file and atomic rename to outfn.
local out <close> = assert(io.open(outfn, "wb"))
- out:write(elf.header.pack(c.header))
- out:write(elf.segment.pack(c.segments, c.header.data, c.header.class))
+ out:write(elf.header.pack(header))
+ out:write(elf.segment.pack(segments, header.data, header.class))
-- TODO finish section.pack
-- out:write(elf.section.pack(c.sections, c.header.data))
end