From afeffe84a8c2867327618782385da2a42763101a Mon Sep 17 00:00:00 2001 From: Sunil Nimmagadda Date: Thu, 5 Nov 2026 22:18:37 +0530 Subject: Wrap pack inside a pack and simplify error reporting. --- mkelf.lua | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/mkelf.lua b/mkelf.lua index 407bd42..86dbe16 100644 --- a/mkelf.lua +++ b/mkelf.lua @@ -99,12 +99,18 @@ end ---@param sections Section[] ---@return string local function elf_pack(header, segments, sections) - local parts = { elf.header.pack(header) } - for _, sg in ipairs(segments) do - parts[#parts + 1] = elf.segment.pack(sg, header.data, header.class) + local ok, b = pcall(elf.header.pack, header) + if not ok then error(("header: %s"):format(b), 0) end + local parts = { b } + for i, sg in ipairs(segments) do + local sgok, sgb = pcall(elf.segment.pack, sg, header.data, header.class) + if not sgok then error(("segment #%d: %s"):format(i, sgb), 0) end + parts[#parts + 1] = sgb end - for _, sc in ipairs(sections) do - parts[#parts + 1] = elf.section.pack(sc, header.data, header.class) + for i, sc in ipairs(sections) do + local scok, scb = pcall(elf.section.pack, sc, header.data, header.class) + if not scok then error(("section #%d: %s"):format(i, scb), 0) end + parts[#parts + 1] = scb end return table.concat(parts) end -- cgit v1.3