diff options
| author | Sunil Nimmagadda <sunil@nimmagadda.net> | 2026-11-05 23:25:40 +0530 |
|---|---|---|
| committer | Sunil Nimmagadda <sunil@nimmagadda.net> | 2026-11-05 23:25:40 +0530 |
| commit | 763930302205c61e4909dc429d61e33624d61d6b (patch) | |
| tree | e5b134e786b38cc9566221b9ca33195e70821a87 /mkelf.lua | |
| parent | 6f83d9020a1788b0fa1d1b1fac658f2c8d704bd9 (diff) | |
Move all the validations to correct place.
Diffstat (limited to 'mkelf.lua')
| -rw-r--r-- | mkelf.lua | 28 |
1 files changed, 25 insertions, 3 deletions
@@ -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 |
