diff options
Diffstat (limited to 'mkelf.lua')
| -rw-r--r-- | mkelf.lua | 21 |
1 files changed, 14 insertions, 7 deletions
@@ -86,6 +86,17 @@ local function loadconfig(fn) return state.header, state.segments, state.sections end +local function elf_pack(header, segments, sections) + local binary = elf.header.pack(header) + for _, segment in ipairs(segments) do + binary = binary .. elf.segment.pack(segment, header.class, header.endian) + end + for _, section in ipairs(sections) do + binary = binary .. elf.section.pack(section, header.class, header.endian) + end + return binary +end + local M = {} function M.main() @@ -109,14 +120,10 @@ function M.main() -- if header.phnum == 0 then header.phnum = #segments end -- if header.shnum == 0 then header.shnum = #sections end local out <close>, err = io.open(outfn, "wb") + local binary = elf_pack(header, segments, sections) if out == nil then die("failed to open: %s", outfn, err) end - out:write(elf.header.pack(header)) - for _, segment in ipairs(segments) do - out:write(elf.segment.pack(segment, header.data, header.class)) - end - for _, section in ipairs(sections) do - out:write(elf.section.pack(section, header.data, header.class)) - end + local ok, werr = out:write(binary) + if not ok then die("write failed: %s", werr) end end return M |
