kernel.lds (1595B)
1 /* arm64 seed kernel link layout. 2 * 3 * QEMU `-machine virt` puts RAM at 0x40000000. With `-kernel` and the arm64 4 * Image header, QEMU loads us at RAM_BASE + text_offset = 0x40080000. 5 * We don't reference absolute addresses in code (the entry stub uses adrp 6 * which is PC-relative), so the link base mostly affects symbol values. 7 */ 8 9 ENTRY(_start) 10 11 SECTIONS { 12 . = 0x40080000; 13 14 /* kernel.S lives entirely in `.text` (the arm64 Image header sits 15 * at its top), and it is linked first, so its contributions land at 16 * file offset 0 — exactly where QEMU's arm64 boot protocol expects 17 * the `ARM\x64` magic at byte 0x38. No `.head.text` indirection 18 * needed; a script-less linker (tcc3) reaches the same layout via 19 * its default input-order section concatenation. */ 20 .text : ALIGN(8) { 21 *(.text .text.*) 22 } 23 24 .rodata : ALIGN(8) { 25 *(.rodata .rodata.*) 26 } 27 28 .data : ALIGN(8) { 29 *(.data .data.*) 30 } 31 32 /* `.bss` includes the 64KB kernel stack, which kernel.S reserves as 33 * plain `.bss` content ending at `kstack_top`. kernel.S references 34 * `__bss_start` and `_end` to bracket the bss-zero loop; both names 35 * are de-facto linker conventions (gnu ld defines them via this 36 * script, and tcc3 synthesizes them automatically via the 37 * bss-start-symbol simple-patch + its built-in `_end` def). */ 38 .bss : ALIGN(16) { 39 __bss_start = .; 40 *(.bss .bss.*) 41 *(COMMON) 42 . = ALIGN(16); 43 } 44 45 _end = .; 46 47 /DISCARD/ : { 48 *(.note.*) *(.comment) *(.eh_frame) 49 } 50 }