code wiki / (root) / nx_elf_read.nx

nx_elf_read.nx

buildroot/runtime/nx_elf_read.nx

8356 B234 linesdepth 3pulls 3 transitivereach 16 importersview sourcekind tooltopic elf
docsdependenciesstructsconstsfunctions

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

syscalls.nx nx_elf_read.nx nx_addr2line.nx nx_byte_diff.nx nx_loader.nx nx_nm.nx nx_nxc_native_wrap.nx nx_objdump.nx nx_readelf.nx nx_size.nx nx_smoke_objdump.nx nx_strip.nx

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

main nx_elf_parse_header nx_elf_get_u16_le nx_elf_get_u64_le nx_elf_get_u32_le nx_elf_get_u16_le ↻ nx_elf_get_u32_le ↻ nx_elf_get_u64_le ↻

structs

61struct NxElfHeader
112struct NxElfShdr
157struct NxElfSym

consts

78const NX_ELF_HEADER_BYTES: i64 = 112
125const NX_ELF_SHDR_BYTES: i64 = 80
166const NX_ELF_SYM_BYTES: i64 = 56

functions

39func nx_elf_get_u16_le(buf: *u8, off: i64) -> i64
45func nx_elf_get_u32_le(buf: *u8, off: i64) -> i64
53func nx_elf_get_u64_le(buf: *u8, off: i64) -> i64
80func nx_elf_parse_header(buf: *u8, len: i64) -> *NxElfHeader
129func nx_elf_read_shdr(buf: *u8, h: *NxElfHeader, idx: i64) -> *NxElfShdr
150func nx_elf_strtab_at(buf: *u8, strtab_off: i64, name_off: i64) -> *u8
169func nx_elf_read_sym(buf: *u8, sym_section: *NxElfShdr, idx: i64) -> *NxElfSym
182func nx_elf_sym_bind(s: *NxElfSym) -> i64 { return (s.st_info >> 4) & 0xF }
183func nx_elf_sym_type(s: *NxElfSym) -> i64 { return s.st_info & 0xF }
185func nx_elf_sym_count(sym_section: *NxElfShdr) -> i64
192func main() -> i64