aboutsummaryrefslogtreecommitdiff
path: root/mkelf.lua
diff options
context:
space:
mode:
authorSunil Nimmagadda <sunil@nimmagadda.net>2026-11-04 21:45:34 +0530
committerSunil Nimmagadda <sunil@nimmagadda.net>2026-11-04 21:45:34 +0530
commiteb4ed34d7dfa5ce0e4cb0f24a3ec9c2115406b9e (patch)
tree333bc2cebead238fa1bc6255ead7ffe4405f5edb /mkelf.lua
parentc0902ae3446e479c7d8e616b33a04c42d396d413 (diff)
Make it a proper module and call main accordingly.
Diffstat (limited to 'mkelf.lua')
-rw-r--r--mkelf.lua10
1 files changed, 6 insertions, 4 deletions
diff --git a/mkelf.lua b/mkelf.lua
index 2b8310f..2fcd207 100644
--- a/mkelf.lua
+++ b/mkelf.lua
@@ -86,7 +86,9 @@ local function loadconfig(fn)
return state.header, state.segments, state.sections
end
-local function main()
+local M = {}
+
+function M.main()
local outfn = "a.out"
local infn
local i = 1
@@ -106,8 +108,8 @@ local function main()
-- TODO check against headerOptions not normalized header.
if header.phnum == 0 then header.phnum = #segments end
if header.shnum == 0 then header.shnum = #sections end
- local out <close> = io.open(outfn, "wb")
- if out == nil then die("failed to open %s", outfn) end
+ local out <close>, err = io.open(outfn, "wb")
+ 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))
@@ -117,4 +119,4 @@ local function main()
end
end
-main()
+return M