nx_elf_exec.nx
buildroot/runtime/nx_elf_exec.nx
about
nx_elf_exec.nx -- executable ELF writer.
Consumes the layout output from nx_link.nx (or any caller that
provides aligned text/rodata/data/bss segments + entry vaddr) and
emits a complete static ELF64 executable suitable for nx_loader
to consume.
Output layout (file offsets):
0x00 - 0x40 Elf64_Ehdr 64 bytes
0x40 - 0x? Program header table 2 * 56 bytes (RX, RW)
page boundary
0x1000+ RX segment (text + rodata)
page boundary
0xN000+ RW segment (data; bss is NOBITS)
We emit STATIC executables only (no dynamic linker, no PT_INTERP,
no PT_DYNAMIC, no PHDR self-reference). That matches what the
off-C path produces today.
Pairs with nx_link (provides the layout) + nx_loader (consumes
the output) + nx_rv64_sim (executes the loaded image).
dependencies 1 imports · 0 importers
imports: syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 31 | const NX_MAGIC_65536: i64 = 65536 |
| 35 | const NX_ELFEXEC_PAGE: i64 = 0x1000 |
| 37 | const NX_ELFEXEC_EHDR_BYTES: i64 = 64 |
| 38 | const NX_ELFEXEC_PHDR_BYTES: i64 = 56 |
| 41 | const NX_ELFEXEC_EI_MAG0: i64 = 0x7F |
| 42 | const NX_ELFEXEC_EI_MAG1: i64 = 0x45 |
| 43 | const NX_ELFEXEC_EI_MAG2: i64 = 0x4C |
| 44 | const NX_ELFEXEC_EI_MAG3: i64 = 0x46 |
| 45 | const NX_ELFEXEC_EI_CLASS_64: i64 = 2 |
| 46 | const NX_ELFEXEC_EI_DATA_LSB: i64 = 1 |
| 47 | const NX_ELFEXEC_EI_VERSION: i64 = 1 |
| 50 | const NX_ELFEXEC_ET_EXEC: i64 = 2 |
| 53 | const NX_ELFEXEC_EM_RISCV: i64 = 0xF3 |
| 56 | const NX_ELFEXEC_PT_LOAD: i64 = 1 |
| 57 | const NX_ELFEXEC_PF_X: i64 = 1 |
| 58 | const NX_ELFEXEC_PF_W: i64 = 2 |
| 59 | const NX_ELFEXEC_PF_R: i64 = 4 |
functions
| 63 | func nx_elfexec_write_u8(buf: *u8, off: i64, v: i64) -> i64 called by 1: nx_elfexec_write_ehdr |
| 68 | func nx_elfexec_write_u16(buf: *u8, off: i64, v: i64) -> i64 called by 1: nx_elfexec_write_ehdr |
| 74 | func nx_elfexec_write_u32(buf: *u8, off: i64, v: i64) -> i64 |
| 82 | func nx_elfexec_write_u64(buf: *u8, off: i64, v: i64) -> i64 |
| 96 | func nx_elfexec_write_ehdr(buf: *u8, entry_vaddr: i64, e_phoff: i64, e_phnum: i64) -> i64 |
| 127 | func nx_elfexec_write_phdr( |
| 162 | func nx_elfexec_emit( |
| 233 | func main() -> i64 calls 1: nx_elfexec_emit |