aboutsummaryrefslogtreecommitdiff
path: root/elf/section.lua
diff options
context:
space:
mode:
authorSunil Nimmagadda <sunil@nimmagadda.net>2026-10-30 14:51:07 +0530
committerSunil Nimmagadda <sunil@nimmagadda.net>2026-10-30 14:51:07 +0530
commit93849ae98ad5d518319c43a6ba6548650c500c22 (patch)
tree11db5c15466f59b7f9038fe08862b4677261f9ac /elf/section.lua
parent540d161bcb526efef2152f8e791a02e0361f2aae (diff)
section: Normalize and have stub name to index function.
Diffstat (limited to 'elf/section.lua')
-rw-r--r--elf/section.lua21
1 files changed, 19 insertions, 2 deletions
diff --git a/elf/section.lua b/elf/section.lua
index 8f84b35..801a1d8 100644
--- a/elf/section.lua
+++ b/elf/section.lua
@@ -14,13 +14,30 @@ local fmt = require("elf.fmt")
local M = {}
function M.normalize(section)
- -- TODO
+ if type(section) ~= "table" then error("section must be a table", 3) end
+ if not section.name then error("name is required in section", 3) end
+ if not section.type then error("type is required in section", 3) end
+ if not section.flags then error("flags required in section", 3) end
+
+ section.addr = section.addr or 0
+ section.offset = section.offset or 0
+ section.size = section.size or 0
+ section.link = section.link or 0
+ section.info = section.info or 0
+ section.addralign = section.addralign or 0
+ section.entsize = section.entsize or 0
end
function M.validate(section)
--TODO
end
+local function section_index(name)
+ -- TODO
+
+ return 42
+end
+
---@param section Section
---@param endian Endian
---@return string
@@ -31,7 +48,7 @@ function M.pack(section, endian, class)
string.rep(fmt.word(class), 4) ..
"I4I4" ..
string.rep(fmt.word(class), 2),
- section.name,
+ section_index(section.name),
section.type,
section.flags,
section.addr,