-
Notifications
You must be signed in to change notification settings - Fork 0
/
linker.ld
87 lines (74 loc) · 2.54 KB
/
linker.ld
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* Tell the linker that we want an x86_64 ELF64 output file */
OUTPUT_FORMAT(elf64-x86-64)
OUTPUT_ARCH(i386:x86-64)
/* We want the symbol _start to be our entry point */
ENTRY(_start)
/* Define the program headers we want so the bootloader gives us the right */
/* MMU permissions */
PHDRS
{
text PT_LOAD FLAGS(0x05); /* Execute + Read */
rodata PT_LOAD FLAGS(0x04); /* Read only */
data PT_LOAD FLAGS(0x06); /* Write + Read */
dynamic PT_DYNAMIC FLAGS(0x06); /* Dynamic PHDR for relocations */
}
SECTIONS
{
/* We wanna be placed in the topmost 2GiB of the address space, for optimisations */
/* 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;
TEXT_START = .;
.text : {
*(.text .text.*)
} :text
TEXT_END = .;
/* Move to the next memory page for .rodata */
. = ALIGN(CONSTANT(MAXPAGESIZE));
RODATA_START = .;
.rodata : {
*(.rodata .rodata.*)
} :rodata
RODATA_END = .;
/* Move to the next memory page for .data */
. = ALIGN(CONSTANT(MAXPAGESIZE));
DATA_START = .;
.data : {
*(.data .data.*)
/* Place the sections that contain the Limine requests as part of the .data */
/* output section. */
KEEP(*(.requests_start_marker))
KEEP(*(.requests))
KEEP(*(.requests_end_marker))
} :data
DATA_END = .;
/* Global offset table section, explicitly created because it may cause issues */
/* if left as an orphaned section. */
.got : {
*(.got .got.*)
} :data
/* Dynamic section for relocations, both in its own PHDR and inside data PHDR */
.dynamic : {
*(.dynamic)
} :data :dynamic
/* 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. */
BSS_START = .;
.bss : {
*(.bss .bss.*)
*(COMMON)
} :data
BSS_END = .;
/* Discard .note.* and .eh_frame since they may cause issues on some hosts. */
/* Also discard the program interpreter section since we do not need one. This is */
/* more or less equivalent to the --no-dynamic-linker linker flag, except that it */
/* works with ld.gold. */
/DISCARD/ : {
*(.eh_frame)
*(.note .note.*)
*(.interp)
}
}