diff options
| -rw-r--r-- | elf/header.lua | 14 | ||||
| -rw-r--r-- | elf/section.lua | 4 | ||||
| -rw-r--r-- | elf/segment.lua | 2 | ||||
| -rw-r--r-- | mkelf.lua | 28 |
4 files changed, 25 insertions, 23 deletions
diff --git a/elf/header.lua b/elf/header.lua index de939d9..179e3bd 100644 --- a/elf/header.lua +++ b/elf/header.lua @@ -50,20 +50,6 @@ local M = {} ---@param hdropts HeaderOptions ---@return Header function M.normalize(hdropts) - -- TODO drop these error() and return, let callers report. - if not hdropts.class then error("class is required in header", 3) end - if not hdropts.data then error("data is required in header", 3) end - if not hdropts.type then error("type is required in header", 3) end - if not hdropts.machine then error("machine is required in header", 3) end - - -- Can't pack without these values being valid. - if hdropts.class ~= ec.Class.bit32 and hdropts.class ~= ec.Class.bit64 then - error("class must be Class.bit32 or Class.bit64 in header", 3) - end - if hdropts.data ~= ec.Endian.little and hdropts.data ~= ec.Endian.big then - error("data must be Endian.little or Endian.big in header", 3) - end - local phoff, ehsize, phentsize, shentsize if hdropts.class == ec.Class.bit32 then phoff = hdropts.phoff or 0x34 diff --git a/elf/section.lua b/elf/section.lua index 7849d48..ed625c4 100644 --- a/elf/section.lua +++ b/elf/section.lua @@ -31,10 +31,6 @@ local M = {} ---@param secopts SectionOptions ---@return Section function M.normalize(secopts) - if not secopts.name then error("name is required in section", 3) end - if not secopts.type then error("type is required in section", 3) end - if not secopts.flags then error("flags required in section", 3) end - return { name = secopts.name, type = secopts.type, diff --git a/elf/segment.lua b/elf/segment.lua index 89d0c47..555cc54 100644 --- a/elf/segment.lua +++ b/elf/segment.lua @@ -30,8 +30,6 @@ local M = {} ---@param segopts SegmentOptions ---@return Segment function M.normalize(segopts) - if not segopts.type then error("type is required in segment", 3) end - return { type = segopts.type, flags = segopts.flags or 0, @@ -15,11 +15,21 @@ local function setup_header(state) if type(t) ~= "table" then error("header must be a table", 2) end - if state.hopts == nil then - state.hopts = t - else + if state.hopts ~= nil then error("multiple headers are disallowed", 2) end + if not t.class then error("class is required in header", 2) end + if not t.data then error("data is required in header", 2) end + if not t.type then error("type is required in header", 2) end + if not t.machine then error("machine is required in header", 2) end + -- Can't pack without these values being valid. + if t.class ~= ec.Class.bit32 and t.class ~= ec.Class.bit64 then + error("class must be Class.bit32 or Class.bit64 in header", 2) + end + if t.data ~= ec.Endian.little and t.data ~= ec.Endian.big then + error("data must be Endian.little or Endian.big in header", 2) + end + state.hopts = t end end @@ -32,6 +42,9 @@ local function setup_segments(state) if type(s) ~= "table" then error(("segment #%d must be a table"):format(i), 2) end + if not s.type then + error(("type is required in segment #%d"):format(i), 2) + end table.insert(state.sgopts, s) end end @@ -46,6 +59,15 @@ local function setup_sections(state) if type(s) ~= "table" then error(("section #%d must be a table"):format(i), 2) end + if not s.name then + error(("name is required in section"):format(i), 2) + end + if not s.type then + error(("type is required in section"):format(i), 2) + end + if not s.flags then + error(("flags required in section"):format(i), 2) + end table.insert(state.scopts, s) end end |
