···11+/* Tell the linker that we want an aarch64 ELF64 output file */
22+OUTPUT_FORMAT(elf64-littleaarch64)
33+44+/* We want the symbol kmain to be our entry point */
55+ENTRY(kmain)
66+77+/* Define the program headers we want so the bootloader gives us the right */
88+/* MMU permissions; this also allows us to exert more control over the linking */
99+/* process. */
1010+PHDRS
1111+{
1212+ limine_requests PT_LOAD;
1313+ text PT_LOAD;
1414+ rodata PT_LOAD;
1515+ data PT_LOAD;
1616+}
1717+1818+SECTIONS
1919+{
2020+ /* We want to be placed in the topmost 2GiB of the address space, for optimisations */
2121+ /* and because that is what the Limine spec mandates. */
2222+ /* Any address in this region will do, but often 0xffffffff80000000 is chosen as */
2323+ /* that is the beginning of the region. */
2424+ . = 0xffffffff80000000;
2525+2626+ /* Define a section to contain the Limine requests and assign it to its own PHDR */
2727+ .limine_requests : {
2828+ KEEP(*(.limine_requests_start))
2929+ KEEP(*(.limine_requests))
3030+ KEEP(*(.limine_requests_end))
3131+ } :limine_requests
3232+3333+ /* Move to the next memory page for .text */
3434+ . = ALIGN(CONSTANT(MAXPAGESIZE));
3535+3636+ .text : {
3737+ *(.text .text.*)
3838+ } :text
3939+4040+ /* Move to the next memory page for .rodata */
4141+ . = ALIGN(CONSTANT(MAXPAGESIZE));
4242+4343+ .rodata : {
4444+ *(.rodata .rodata.*)
4545+ } :rodata
4646+4747+ /* Add a .note.gnu.build-id output section in case a build ID flag is added to the */
4848+ /* linker command. */
4949+ .note.gnu.build-id : {
5050+ *(.note.gnu.build-id)
5151+ } :rodata
5252+5353+ /* Move to the next memory page for .data */
5454+ . = ALIGN(CONSTANT(MAXPAGESIZE));
5555+5656+ .data : {
5757+ *(.data .data.*)
5858+ } :data
5959+6060+ /* NOTE: .bss needs to be the last thing mapped to :data, otherwise lots of */
6161+ /* unnecessary zeros will be written to the binary. */
6262+ /* If you need, for example, .init_array and .fini_array, those should be placed */
6363+ /* above this. */
6464+ .bss : {
6565+ *(.bss .bss.*)
6666+ *(COMMON)
6767+ } :data
6868+6969+ /* Discard .note.* and .eh_frame* since they may cause issues on some hosts. */
7070+ /DISCARD/ : {
7171+ *(.eh_frame*)
7272+ *(.note .note.*)
7373+ }
7474+}
+74
kernel/link/x86_64.lds
···11+/* Tell the linker that we want an x86_64 ELF64 output file */
22+OUTPUT_FORMAT(elf64-x86-64)
33+44+/* We want the symbol kmain to be our entry point */
55+ENTRY(kmain)
66+77+/* Define the program headers we want so the bootloader gives us the right */
88+/* MMU permissions; this also allows us to exert more control over the linking */
99+/* process. */
1010+PHDRS
1111+{
1212+ limine_requests PT_LOAD;
1313+ text PT_LOAD;
1414+ rodata PT_LOAD;
1515+ data PT_LOAD;
1616+}
1717+1818+SECTIONS
1919+{
2020+ /* We want to be placed in the topmost 2GiB of the address space, for optimisations */
2121+ /* and because that is what the Limine spec mandates. */
2222+ /* Any address in this region will do, but often 0xffffffff80000000 is chosen as */
2323+ /* that is the beginning of the region. */
2424+ . = 0xffffffff80000000;
2525+2626+ /* Define a section to contain the Limine requests and assign it to its own PHDR */
2727+ .limine_requests : {
2828+ KEEP(*(.limine_requests_start))
2929+ KEEP(*(.limine_requests))
3030+ KEEP(*(.limine_requests_end))
3131+ } :limine_requests
3232+3333+ /* Move to the next memory page for .text */
3434+ . = ALIGN(CONSTANT(MAXPAGESIZE));
3535+3636+ .text : {
3737+ *(.text .text.*)
3838+ } :text
3939+4040+ /* Move to the next memory page for .rodata */
4141+ . = ALIGN(CONSTANT(MAXPAGESIZE));
4242+4343+ .rodata : {
4444+ *(.rodata .rodata.*)
4545+ } :rodata
4646+4747+ /* Add a .note.gnu.build-id output section in case a build ID flag is added to the */
4848+ /* linker command. */
4949+ .note.gnu.build-id : {
5050+ *(.note.gnu.build-id)
5151+ } :rodata
5252+5353+ /* Move to the next memory page for .data */
5454+ . = ALIGN(CONSTANT(MAXPAGESIZE));
5555+5656+ .data : {
5757+ *(.data .data.*)
5858+ } :data
5959+6060+ /* NOTE: .bss needs to be the last thing mapped to :data, otherwise lots of */
6161+ /* unnecessary zeros will be written to the binary. */
6262+ /* If you need, for example, .init_array and .fini_array, those should be placed */
6363+ /* above this. */
6464+ .bss : {
6565+ *(.bss .bss.*)
6666+ *(COMMON)
6767+ } :data
6868+6969+ /* Discard .note.* and .eh_frame* since they may cause issues on some hosts. */
7070+ /DISCARD/ : {
7171+ *(.eh_frame*)
7272+ *(.note .note.*)
7373+ }
7474+}