KernOS
linker.ld
Go to the documentation of this file.
1 /*! @brief linker script to specify kernel binary's section locations
2  * @see <a href="https://wiki.osdev.org/Bare_Bones#Linking_the_Kernel">Osdev's Linking the kernel</a>
3  */
4 
5 /* The bootloader will look at this image and start execution at the symbol
6  designated as the entry point. */
7 ENTRY(_start)
8 
9 /* Tell where the various sections of the object files will be put in the final
10  kernel image. */
11 SECTIONS
12 {
13  /* Begin putting sections at 1 MiB, a conventional place for kernels to be
14  loaded at by the bootloader. */
15  . = 1M;
16 
17  /* First put the multiboot header, as it is required to be put very early
18  early in the image or the bootloader won't recognize the file format.
19  Next we'll put the .text section. */
20  .text BLOCK(4K) : ALIGN(4K)
21  {
22  *(.multiboot)
23  *(.page_tables)
24  *(.kheap_mem)
25  *(.text)
26  }
27 
28  /* Read-only data. */
29  .rodata BLOCK(4K) : ALIGN(4K)
30  {
31  /* label start, end of global constructors */
32  start_ctors = .;
33  *(.ctors)
34  end_ctors = .;
35 
36  *(.rodata)
37  }
38 
39  /* Read-write data (initialized) */
40  .data BLOCK(4K) : ALIGN(4K)
41  {
42  *(.data)
43  }
44 
45  /* Read-write data (uninitialized) and stack */
46  .bss BLOCK(4K) : ALIGN(4K)
47  {
48  *(COMMON)
49  *(.bss)
50  }
51 
52  /* The compiler may produce other sections, by default it will put them in
53  a segment with the same name. Simply add stuff here as needed. */
54 }