Move sections, change the start address and the stack, and watch the symbol addresses, the program headers (filesz versus memsz) and the exact bytes of the flat binary change together.
Runs in browser
Linker map: the primer's program, from ELF to flat binary to guest memory
The default layout. The linker places .text (56 bytes, _start first) at 0x4008_0000, .rodata (GREETING, 6 bytes) at 0x4008_0038, .data (BOOTS, 4 bytes) at 0x4008_0040, and .bss (COUNTER plus a 16 KiB stack, 16,400 bytes, NOLOAD) at 0x4008_0050 up to __stack_top at 0x4008_4060. Three PT_LOAD headers: read-execute 56 bytes, read-only 6 bytes, and read-write with FileSize 4 and MemSize 16,416. objcopy -O binary writes 68 bytes: the code, the text hello and a newline, two bytes of padding, and the value 7. The BSS is not in the file; after --raw bare.bin@0x40080000, everything above byte 68 holds whatever RAM held before, so _start must zero it.
bare: where the linker puts every byte (default layout)
ELF program headers
PT_LOAD R X 0x4008_0000 filesz 56 memsz 56
PT_LOAD R 0x4008_0038 filesz 6 memsz 6
PT_LOAD R W 0x4008_0040 filesz 4 memsz 16,416
bare.bin: 68 bytes
0x00 .text _start, 14 instructions
0x38 .rodata "hello\n"
0x3e padding (2 bytes)
0x40 .data 07 00 00 00 (BOOTS)
Guest memory after --raw bare.bin@0x40080000
copied from the file (68 B)
gap
.bss + stack (16,400 B): old contents of RAM. Zero it yourself!
0x4008_0000
0x4008_0044
0x4008_0050
0x4008_4060
With JavaScript, the lab lets you move sections, add .far, store a pointer and change the load address.
This lab needs JavaScript. Everything else on this page works without it.
All labs