2022-08-20 00:54:34 +01:00
|
|
|
/* Tell the linker that we want an x86_64 ELF64 output file */
|
|
|
|
OUTPUT_FORMAT(elf64-x86-64)
|
|
|
|
|
2024-08-14 20:19:14 +01:00
|
|
|
/* We want the symbol kmain to be our entry point */
|
|
|
|
ENTRY(kmain)
|
2022-08-20 00:54:34 +01:00
|
|
|
|
|
|
|
/* Define the program headers we want so the bootloader gives us the right */
|
2024-08-14 20:19:14 +01:00
|
|
|
/* MMU permissions; this also allows us to exert more control over the linking */
|
|
|
|
/* process. */
|
2022-08-20 00:54:34 +01:00
|
|
|
PHDRS
|
|
|
|
{
|
2024-09-30 19:07:33 +01:00
|
|
|
requests PT_LOAD;
|
|
|
|
text PT_LOAD;
|
|
|
|
rodata PT_LOAD;
|
|
|
|
data PT_LOAD;
|
2022-08-20 00:54:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTIONS
|
|
|
|
{
|
2024-08-14 20:19:14 +01:00
|
|
|
/* We want to be placed in the topmost 2GiB of the address space, for optimisations */
|
2022-08-20 00:54:34 +01:00
|
|
|
/* and because that is what the Limine spec mandates. */
|
|
|
|
/* Any address in this region will do, but often 0xffffffff80000000 is chosen as */
|
|
|
|
/* that is the beginning of the region. */
|
|
|
|
. = 0xffffffff80000000;
|
|
|
|
|
2024-09-30 19:07:33 +01:00
|
|
|
/* Define a section to contain the Limine requests and assign it to its own PHDR */
|
|
|
|
.requests : {
|
|
|
|
KEEP(*(.requests_start_marker))
|
|
|
|
KEEP(*(.requests))
|
|
|
|
KEEP(*(.requests_end_marker))
|
|
|
|
} :requests
|
|
|
|
|
|
|
|
/* Move to the next memory page for .text */
|
|
|
|
. = ALIGN(CONSTANT(MAXPAGESIZE));
|
|
|
|
|
2022-08-20 00:54:34 +01:00
|
|
|
.text : {
|
|
|
|
*(.text .text.*)
|
|
|
|
} :text
|
|
|
|
|
|
|
|
/* Move to the next memory page for .rodata */
|
2024-08-14 20:19:14 +01:00
|
|
|
. = ALIGN(CONSTANT(MAXPAGESIZE));
|
2022-08-20 00:54:34 +01:00
|
|
|
|
|
|
|
.rodata : {
|
|
|
|
*(.rodata .rodata.*)
|
|
|
|
} :rodata
|
|
|
|
|
|
|
|
/* Move to the next memory page for .data */
|
2024-08-14 20:19:14 +01:00
|
|
|
. = ALIGN(CONSTANT(MAXPAGESIZE));
|
2022-08-20 00:54:34 +01:00
|
|
|
|
|
|
|
.data : {
|
|
|
|
*(.data .data.*)
|
|
|
|
} :data
|
|
|
|
|
2023-03-28 23:04:07 +01:00
|
|
|
/* NOTE: .bss needs to be the last thing mapped to :data, otherwise lots of */
|
|
|
|
/* unnecessary zeros will be written to the binary. */
|
|
|
|
/* If you need, for example, .init_array and .fini_array, those should be placed */
|
|
|
|
/* above this. */
|
2022-08-20 00:54:34 +01:00
|
|
|
.bss : {
|
|
|
|
*(.bss .bss.*)
|
2023-07-15 07:12:16 +01:00
|
|
|
*(COMMON)
|
2022-08-20 00:54:34 +01:00
|
|
|
} :data
|
|
|
|
|
2024-08-14 20:19:14 +01:00
|
|
|
/* Discard .note.* and .eh_frame* since they may cause issues on some hosts. */
|
2022-08-20 00:54:34 +01:00
|
|
|
/DISCARD/ : {
|
2024-08-14 20:19:14 +01:00
|
|
|
*(.eh_frame*)
|
2022-08-20 00:54:34 +01:00
|
|
|
*(.note .note.*)
|
|
|
|
}
|
|
|
|
}
|