-
Notifications
You must be signed in to change notification settings - Fork 1
/
linker.ld
69 lines (52 loc) · 1.56 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
/* 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
{
null PT_NULL FLAGS(0) ; /* Null segment */
text PT_LOAD FLAGS((1 << 0) | (1 << 2)) ; /* Execute + Read */
rodata PT_LOAD FLAGS((1 << 2)) ; /* Read only */
data PT_LOAD FLAGS((1 << 1) | (1 << 2)) ; /* Write + Read */
dynamic PT_DYNAMIC FLAGS((1 << 1) | (1 << 2)) ; /* Dynamic segment needed for PIE */
}
SECTIONS
{
/* We wanna be placed in the higher half, 2MiB above 0 in physical memory. */
/* Since we are going to use PIE, this is just the base load address, but the */
/* bootloader will be able to relocate us as it sees fit. */
. = 0xffffffff80000000;
text_start_addr = .;
.text : {
*(.text*)
} :text
text_end_addr = .;
/* Move to the next memory page for .rodata */
. += 0x1000;
rodata_start_addr = .;
.rodata : {
*(.rodata*)
} :rodata
rodata_end_addr = .;
/* Move to the next memory page for .data */
. += 0x1000;
data_start_addr = .;
.data : {
*(.data*)
} :data
/* Dynamic section needed for PIE */
.dynamic : {
*(.dynamic)
} :data :dynamic
.bss : {
*(COMMON)
*(.bss*)
} :data
data_end_addr = .;
/DISCARD/ : {
*(.note .note.*)
}
}