diff options
| author | Sunil Nimmagadda <sunil@nimmagadda.net> | 2026-10-24 10:12:51 +0530 |
|---|---|---|
| committer | Sunil Nimmagadda <sunil@nimmagadda.net> | 2026-10-24 10:12:51 +0530 |
| commit | 4676bb3a05d89bb3c282da2ed8b2072e163093ff (patch) | |
| tree | 66bb61052b552aefe9df7ace9067b4b1878e0ef3 /mkelf.lua | |
| parent | 79f6b161f892f621a909ce1df99b3c680f3682a2 (diff) | |
Multi return values instead of a table.
Diffstat (limited to 'mkelf.lua')
| -rw-r--r-- | mkelf.lua | 22 |
1 files changed, 11 insertions, 11 deletions
@@ -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 |
