/ src / linker.ld
linker.ld
 1  /* The bootloader will look at kernel and start execution at the symbol
 2     designated as the entry point. */
 3  ENTRY(_start)
 4  
 5  /* Tell where the various sections of the object files will be put in the
 6     final kernel image. */
 7  SECTIONS {
 8      /* It used to be universally recommended to use 1M as a start offset,
 9         as it was effectively guaranteed to be available under BIOS systems.
10         However, UEFI has made things more complicated, and experimental data
11         strongly suggests that 2M is a safer place to load. In 2016, a new
12         feature was introduced to the multiboot2 spec to inform bootloaders
13         that a kernel can be loaded anywhere within a range of addresses and
14         will be able to relocate itself to run from such a loader-selected
15         address, in order to give the loader freedom in selecting a span of
16         memory which is verified to be available by the firmware, in order to
17         work around this issue. This does not use that feature, so 2M was
18         chosen as a safer option than the traditional 1M. */
19      . = 2M;
20  
21      /* First put the multiboot header, as it is required to be put very early
22         in the image or the bootloader won't recognize the file format. Next
23         we'll put the .text section. */
24      .text : ALIGN(4K) {
25          /* We need to specify KEEP to prevent the linker from removing the
26             multiboot section. */
27          KEEP(*(.multiboot))
28          *(.text)
29      }
30  
31      /* Read-only data. */
32      .rodata : ALIGN(4K) {
33          *(.rodata)
34      }
35  
36      /* Read-write data (initialized) */
37      .data : ALIGN(4K) {
38          *(.data)
39      }
40  
41      /* Read-write data (uninitialized i.e. undefined) */
42      .bss : ALIGN(4K) {
43          *(COMMON)
44          *(.bss)
45      }
46  
47      /* The compiler may produce other sections, by default it will put them
48         in a segment with the same name. Simply add stuff here as needed. */
49  }