aboutsummaryrefslogtreecommitdiff
path: root/mkelf.lua
diff options
context:
space:
mode:
Diffstat (limited to 'mkelf.lua')
-rw-r--r--mkelf.lua33
1 files changed, 24 insertions, 9 deletions
diff --git a/mkelf.lua b/mkelf.lua
index 518b765..97530b4 100644
--- a/mkelf.lua
+++ b/mkelf.lua
@@ -11,12 +11,12 @@ local function usage()
end
---@param fn string|nil
----@return Header, Segments, Sections
+---@return Header, Segment[], Section[]
local function loadconfig(fn)
local header, segments, sections = {}, {}, {}
local header_mt = { __index = elf.header }
- local segments_mt = { __index = elf.segment }
- local sections_mt = { __index = elf.section }
+ local segment_mt = { __index = elf.segment }
+ local section_mt = { __index = elf.section }
local env = setmetatable({}, {
__index = {
-- Keep in sync with types/elf.d.lua
@@ -41,11 +41,22 @@ local function loadconfig(fn)
if type(t) ~= "table" then
error("segments must be a table", 2)
end
- segments = setmetatable(t, segments_mt)
- t:normalize()
- t:validate()
+ for _, segment in ipairs(t) do
+ segment = setmetatable(segment, segment_mt)
+ segment:normalize()
+ segment:validate()
+ end
+ end,
+ sections = function(t)
+ if type(t) ~= "table" then
+ error("sections must be a table", 2)
+ end
+ for _, section in ipairs(t) do
+ section = setmetatable(t, section_mt)
+ section:normalize()
+ section:validate()
+ end
end,
- sections = function(t) sections = setmetatable(t, sections_mt) end,
},
__newindex = function(_, name)
error(("may not define global %q"):format(name), 2)
@@ -80,8 +91,12 @@ local function main()
header.phentsize = (header.class == ec.Class.bit64) and 0x38 or 0x20
local out <close> = assert(io.open(outfn, "wb"))
out:write(header:pack())
- out:write(segments:pack(header.data, header.class))
- -- out:write(sections:pack(header.data, header.class))
+ for _, segment in ipairs(segments) do
+ out:write(segment:pack(header.data, header.class))
+ end
+ for _, section in ipairs(sections) do
+ out:write(section:pack(header.data, header.class))
+ end
end
main()