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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
/* $OpenBSD: ld.script,v 1.14 2018/07/13 08:30:34 sf Exp $ */
/*
* Copyright (c) 2009 Tobias Weingartner <weingart@tepid.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64")
OUTPUT_ARCH(i386:x86-64)
/* Define how we want out ELF binary to look like. */
PHDRS
{
text PT_LOAD FILEHDR PHDRS;
rodata PT_LOAD FLAGS (4);
data PT_LOAD;
bss PT_LOAD;
openbsd_randomize PT_OPENBSD_RANDOMIZE;
}
/*
* If we want the text/rodata/data sections aligned on 2M boundaries,
* we could use the following instead. Note, file size would increase
* due to necessary padding.
*
*__ALIGN_SIZE = 0x200000;
*/
__ALIGN_SIZE = 0x1000;
__kernel_base = 0xffffffff80000000;
__kernel_virt_base = __kernel_base + 0x1000000;
__kernel_phys_base = 0x1000000;
__kernel_base_phys = __kernel_phys_base + SIZEOF_HEADERS;
__kernel_virt_to_phys = __kernel_phys_base - __kernel_virt_base;
ENTRY(start)
SECTIONS
{
.text (__kernel_virt_base + SIZEOF_HEADERS) : AT (__kernel_base_phys)
{
start = .;
locore0.o(.text)
*(.text .text.*)
. = ALIGN(__ALIGN_SIZE);
__text_page_start = ABSOLUTE(.);
*(.ktext.page)
__text_page_end = ABSOLUTE(.);
} :text =0xcccccccc
. = ALIGN(__ALIGN_SIZE);
__kernel_kutext_phys = . + __kernel_virt_to_phys;
.kutext : AT (__kernel_kutext_phys)
{
__kutext_start = ABSOLUTE(.);
*(.kutext)
__kutext_end = ABSOLUTE(.);
} :text =0xcccccccc
. = ALIGN(__ALIGN_SIZE);
__kernel_cptext_phys = . + __kernel_virt_to_phys;
.cptext : AT (__kernel_cptext_phys)
{
__cptext_start = ABSOLUTE(.);
*(.cptext)
__cptext_end = ABSOLUTE(.);
} :text =0xcccccccc
PROVIDE (etext = .);
_etext = .;
/* Move rodata to the next page, so we can nuke X and W bit on them */
. = ALIGN(__ALIGN_SIZE);
__kernel_rodata_phys = . + __kernel_virt_to_phys;
.rodata : AT (__kernel_rodata_phys)
{
__rodata_start = ABSOLUTE(.);
*(.rodata .rodata.*)
*(.codepatch)
*(.codepatchend)
} :rodata =0xcccccccc
. = ALIGN(__ALIGN_SIZE);
__kernel_kutext_page_phys = . + __kernel_virt_to_phys;
.kutext.page : AT (__kernel_kutext_page_phys)
{
*(SORT_BY_ALIGNMENT(.kutext.page))
} :rodata =0xcccccccc
. = ALIGN(0x1000);
__kernel_randomdata_phys = . + __kernel_virt_to_phys;
.openbsd.randomdata : AT (__kernel_randomdata_phys)
{
__retguard_start = ABSOLUTE(.);
__retguard_start_phys = . + __kernel_virt_to_phys;
*(.openbsd.randomdata.retguard)
. = ALIGN(0x1000);
__retguard_end = ABSOLUTE(.);
__retguard_end_phys = . + __kernel_virt_to_phys;
*(.openbsd.randomdata .openbsd.randomdata.*)
} :rodata :openbsd_randomize =0xcccccccc
. = ALIGN(0x1000);
PROVIDE (erodata = .);
_erodata = .;
/* Move data to the next page, so we can add W bit on them */
. = ALIGN(__ALIGN_SIZE);
__kernel_data_phys = . + __kernel_virt_to_phys;
.data : AT (__kernel_data_phys)
{
__data_start = ABSOLUTE(.);
*(.data .data.*)
} :data =0xcccccccc
. = ALIGN(__ALIGN_SIZE);
__kernel_kudata_phys = . + __kernel_virt_to_phys;
.kudata : AT (__kernel_kudata_phys)
{
__kudata_start = ABSOLUTE(.);
*(.kudata)
__kudata_end = ABSOLUTE(.);
} :data =0xcccccccc
. = ALIGN(0x1000);
PROVIDE (edata = .);
_edata = .;
/* BSS starts right after padded data */
__kernel_bss_phys = . + __kernel_virt_to_phys;
.bss : AT (__kernel_bss_phys)
{
*(.bss .bss.*)
*(COMMON)
/* Align after .bss to ensure correct alignment even if the
* .bss section disappears because there are no input sections.
*/
. = ALIGN(0x1000);
} :bss
__kernel_bss_end = .;
. = ALIGN(0x200000);
_end = .;
PROVIDE (end = .);
__kernel_end_phys = . + __kernel_virt_to_phys;
/* XXX - hack alert, since we are not C++, nuke these */
/DISCARD/ :
{
*(.note.GNU-stack)
*(.eh_frame)
}
}
|