From 763930302205c61e4909dc429d61e33624d61d6b Mon Sep 17 00:00:00 2001 From: Sunil Nimmagadda Date: Thu, 5 Nov 2026 23:25:40 +0530 Subject: Move all the validations to correct place. --- mkelf.lua | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'mkelf.lua') diff --git a/mkelf.lua b/mkelf.lua index f4dd67d..51927d0 100644 --- a/mkelf.lua +++ b/mkelf.lua @@ -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 -- cgit v1.3