nx_elf_read.nx
buildroot/runtime/nx_elf_read.nx
about
nx_elf_read.nx -- read & parse ELF64 binaries we produce.
Closes the loop with elf_writer + nx_strtab + nx_symtab + nx_shtab
+ nx_dwarf_line: this module READS what those modules WRITE.
Foundation for sovereign objdump, nm, readelf, and (future)
nx_dbg.nx debugger.
Without nx_elf_read we depend on third-party tools to inspect our
output -- a sovereignty hole. With it, every byte produced is
also auditable in pure NishiLang.
What we parse:
* ELF header (64 bytes): magic, class, machine, entry, phoff,
shoff, ehsize, phentsize, phnum, shentsize, shnum, shstrndx.
* Program headers (each 56 bytes): PT_LOAD segments etc.
* Section headers (each 64 bytes): name, type, flags, addr,
offset, size, link, info, align, entsize.
* Symbol tables (each Elf64_Sym = 24 bytes).
* String tables (lookup by offset).
NOT YET (separate commits):
* .debug_line VM execution (decode line-program back to
(addr -> file/line) tuples). Land with nx_dbg.nx.
* .debug_info DIE walker.
* Relocations (.rela parsing) -- when nx_reloc.nx ships.
dependencies 1 imports · 12 importers
diagram shows first 10 each side; +0 more imports, +2 more importers in the complete lists below.
imports: syscalls.nx
imported by: nx_addr2line.nxnx_byte_diff.nxnx_loader.nxnx_nm.nxnx_nxc_native_wrap.nxnx_objdump.nxnx_readelf.nxnx_size.nxnx_smoke_objdump.nxnx_strip.nxnx_toolchain.nxnxc_native_wrap.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 61 | struct NxElfHeader |
| 112 | struct NxElfShdr |
| 157 | struct NxElfSym |
consts
| 78 | const NX_ELF_HEADER_BYTES: i64 = 112 |
| 125 | const NX_ELF_SHDR_BYTES: i64 = 80 |
| 166 | const NX_ELF_SYM_BYTES: i64 = 56 |
functions
| 39 | func nx_elf_get_u16_le(buf: *u8, off: i64) -> i64 |
| 45 | func nx_elf_get_u32_le(buf: *u8, off: i64) -> i64 |
| 53 | func nx_elf_get_u64_le(buf: *u8, off: i64) -> i64 |
| 80 | func nx_elf_parse_header(buf: *u8, len: i64) -> *NxElfHeader called by 15: bd_comparemainnx_loader_loadnx_nm_printmainnx_objdump_elf_header+9 calls 2: nx_elf_get_u16_lenx_elf_get_u64_le |
| 129 | func nx_elf_read_shdr(buf: *u8, h: *NxElfHeader, idx: i64) -> *NxElfShdr |
| 150 | func nx_elf_strtab_at(buf: *u8, strtab_off: i64, name_off: i64) -> *u8 |
| 169 | func nx_elf_read_sym(buf: *u8, sym_section: *NxElfShdr, idx: i64) -> *NxElfSym called by 2: nx_nm_printnx_objdump_symbols calls 3: nx_elf_get_u32_lenx_elf_get_u16_lenx_elf_get_u64_le |
| 182 | func nx_elf_sym_bind(s: *NxElfSym) -> i64 { return (s.st_info >> 4) & 0xF } |
| 183 | func nx_elf_sym_type(s: *NxElfSym) -> i64 { return s.st_info & 0xF } |
| 185 | func nx_elf_sym_count(sym_section: *NxElfShdr) -> i64 |
| 192 | func main() -> i64 |