aboutsummaryrefslogtreecommitdiff
path: root/mkelf.lua
diff options
context:
space:
mode:
authorSunil Nimmagadda <sunil@nimmagadda.net>2026-11-05 11:00:16 +0530
committerSunil Nimmagadda <sunil@nimmagadda.net>2026-11-05 11:00:16 +0530
commitc59e6b284b519007f8adf6cfb23d949f83c1a13a (patch)
tree6b6aeee096f8bec7d2785a6260fd695901fa98fb /mkelf.lua
parent0ea23536cd0959ebcdb19b036310cdf455f4219d (diff)
Move header check to loadconfig.
Diffstat (limited to 'mkelf.lua')
-rw-r--r--mkelf.lua11
1 files changed, 9 insertions, 2 deletions
diff --git a/mkelf.lua b/mkelf.lua
index 6ab42e0..d6f4655 100644
--- a/mkelf.lua
+++ b/mkelf.lua
@@ -75,14 +75,22 @@ local function setup_env(state)
})
end
+---@param fn string | nil
+---@return Header, Segment[], Section[]
local function loadconfig(fn)
- local state = { header = nil, segments = {}, sections = {} }
+ local state = {
+ ---@type Header?
+ header = nil,
+ segments = {},
+ sections = {},
+ }
local env = setup_env(state)
local chunk, err = loadfile(fn, "t", env)
if not chunk then die("%s", err) end
-- TODO sandbox against malformed configs
local ok, perr = pcall(chunk)
if not ok then die("%s", perr) end
+ if not state.header then die("header missing") end
return state.header, state.segments, state.sections
end
@@ -119,7 +127,6 @@ function M.main()
i = i + 1
end
local header, segments, sections = loadconfig(infn)
- if not header then die("header missing") end
-- 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