Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
8c2c3df3 CM |
2 | /* |
3 | * ld script to make ARM Linux kernel | |
4 | * taken from the i386 version by Russell King | |
5 | * Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz> | |
6 | */ | |
7 | ||
19f6bc32 | 8 | #define RO_EXCEPTION_TABLE_ALIGN 8 |
2883352b | 9 | #define RUNTIME_DISCARD_EXIT |
19f6bc32 | 10 | |
8c2c3df3 | 11 | #include <asm-generic/vmlinux.lds.h> |
98fb7548 | 12 | #include <asm/cache.h> |
ce492a16 | 13 | #include <asm/hyp_image.h> |
87d1587b | 14 | #include <asm/kernel-pgtable.h> |
8c2c3df3 CM |
15 | #include <asm/memory.h> |
16 | #include <asm/page.h> | |
17 | ||
a2c1d73b MR |
18 | #include "image.h" |
19 | ||
8c2c3df3 | 20 | OUTPUT_ARCH(aarch64) |
af885f40 | 21 | ENTRY(_text) |
8c2c3df3 CM |
22 | |
23 | jiffies = jiffies_64; | |
24 | ||
e9ee186b | 25 | |
3471ee06 | 26 | #ifdef CONFIG_KVM |
e9ee186b JM |
27 | #define HYPERVISOR_EXTABLE \ |
28 | . = ALIGN(SZ_8); \ | |
29 | __start___kvm_ex_table = .; \ | |
30 | *(__kvm_ex_table) \ | |
31 | __stop___kvm_ex_table = .; | |
32 | ||
30c95391 DB |
33 | #define HYPERVISOR_PERCPU_SECTION \ |
34 | . = ALIGN(PAGE_SIZE); \ | |
35 | HYP_SECTION_NAME(.data..percpu) : { \ | |
36 | *(HYP_SECTION_NAME(.data..percpu)) \ | |
37 | } | |
3471ee06 DB |
38 | #else /* CONFIG_KVM */ |
39 | #define HYPERVISOR_EXTABLE | |
30c95391 | 40 | #define HYPERVISOR_PERCPU_SECTION |
3471ee06 | 41 | #endif |
e9ee186b | 42 | |
2240bbb6 MZ |
43 | #define HYPERVISOR_TEXT \ |
44 | /* \ | |
06f75a1f AB |
45 | * Align to 4 KB so that \ |
46 | * a) the HYP vector table is at its minimum \ | |
47 | * alignment of 2048 bytes \ | |
48 | * b) the HYP init code will not cross a page \ | |
49 | * boundary if its size does not exceed \ | |
50 | * 4 KB (see related ASSERT() below) \ | |
2240bbb6 | 51 | */ \ |
06f75a1f | 52 | . = ALIGN(SZ_4K); \ |
5c636aa0 | 53 | __hyp_idmap_text_start = .; \ |
2240bbb6 | 54 | *(.hyp.idmap.text) \ |
5c636aa0 MY |
55 | __hyp_idmap_text_end = .; \ |
56 | __hyp_text_start = .; \ | |
2240bbb6 | 57 | *(.hyp.text) \ |
e9ee186b | 58 | HYPERVISOR_EXTABLE \ |
5c636aa0 | 59 | __hyp_text_end = .; |
2240bbb6 | 60 | |
5dfe9d7d AB |
61 | #define IDMAP_TEXT \ |
62 | . = ALIGN(SZ_4K); \ | |
5c636aa0 | 63 | __idmap_text_start = .; \ |
5dfe9d7d | 64 | *(.idmap.text) \ |
5c636aa0 | 65 | __idmap_text_end = .; |
5dfe9d7d | 66 | |
82869ac5 JM |
67 | #ifdef CONFIG_HIBERNATION |
68 | #define HIBERNATE_TEXT \ | |
69 | . = ALIGN(SZ_4K); \ | |
5c636aa0 | 70 | __hibernate_exit_text_start = .; \ |
82869ac5 | 71 | *(.hibernate_exit.text) \ |
5c636aa0 | 72 | __hibernate_exit_text_end = .; |
82869ac5 JM |
73 | #else |
74 | #define HIBERNATE_TEXT | |
75 | #endif | |
76 | ||
c7b9adaf WD |
77 | #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 |
78 | #define TRAMP_TEXT \ | |
79 | . = ALIGN(PAGE_SIZE); \ | |
5c636aa0 | 80 | __entry_tramp_text_start = .; \ |
c7b9adaf WD |
81 | *(.entry.tramp.text) \ |
82 | . = ALIGN(PAGE_SIZE); \ | |
5c636aa0 | 83 | __entry_tramp_text_end = .; |
c7b9adaf WD |
84 | #else |
85 | #define TRAMP_TEXT | |
86 | #endif | |
87 | ||
a352ea3e AB |
88 | /* |
89 | * The size of the PE/COFF section that covers the kernel image, which | |
348a625d AB |
90 | * runs from _stext to _edata, must be a round multiple of the PE/COFF |
91 | * FileAlignment, which we set to its minimum value of 0x200. '_stext' | |
a352ea3e AB |
92 | * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned |
93 | * boundary should be sufficient. | |
94 | */ | |
95 | PECOFF_FILE_ALIGNMENT = 0x200; | |
96 | ||
97 | #ifdef CONFIG_EFI | |
98 | #define PECOFF_EDATA_PADDING \ | |
99 | .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); } | |
100 | #else | |
101 | #define PECOFF_EDATA_PADDING | |
102 | #endif | |
103 | ||
8c2c3df3 CM |
104 | SECTIONS |
105 | { | |
106 | /* | |
107 | * XXX: The linker does not define how output sections are | |
108 | * assigned to input sections when there are multiple statements | |
109 | * matching the same input section name. There is no documented | |
110 | * order of matching. | |
111 | */ | |
2883352b | 112 | DISCARDS |
8c2c3df3 | 113 | /DISCARD/ : { |
1e48ef7f | 114 | *(.interp .dynamic) |
3bbd3db8 | 115 | *(.dynsym .dynstr .hash .gnu.hash) |
8c2c3df3 CM |
116 | } |
117 | ||
120dc60d | 118 | . = KIMAGE_VADDR; |
8c2c3df3 CM |
119 | |
120 | .head.text : { | |
121 | _text = .; | |
122 | HEAD_TEXT | |
123 | } | |
124 | .text : { /* Real text segment */ | |
125 | _stext = .; /* Text and read-only data */ | |
8c2c3df3 | 126 | IRQENTRY_TEXT |
be7635e7 | 127 | SOFTIRQENTRY_TEXT |
888b3c87 | 128 | ENTRY_TEXT |
8c2c3df3 CM |
129 | TEXT_TEXT |
130 | SCHED_TEXT | |
6727ad9e | 131 | CPUIDLE_TEXT |
8c2c3df3 | 132 | LOCK_TEXT |
2dd0e8d2 | 133 | KPROBES_TEXT |
2240bbb6 | 134 | HYPERVISOR_TEXT |
5dfe9d7d | 135 | IDMAP_TEXT |
82869ac5 | 136 | HIBERNATE_TEXT |
c7b9adaf | 137 | TRAMP_TEXT |
8c2c3df3 CM |
138 | *(.fixup) |
139 | *(.gnu.warning) | |
140 | . = ALIGN(16); | |
141 | *(.got) /* Global offset table */ | |
142 | } | |
143 | ||
be288182 KC |
144 | /* |
145 | * Make sure that the .got.plt is either completely empty or it | |
146 | * contains only the lazy dispatch entries. | |
147 | */ | |
148 | .got.plt : { *(.got.plt) } | |
149 | ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18, | |
150 | "Unexpected GOT/PLT entries detected!") | |
151 | ||
97740051 | 152 | . = ALIGN(SEGMENT_ALIGN); |
9fdc14c5 AB |
153 | _etext = .; /* End of text section */ |
154 | ||
19f6bc32 KC |
155 | /* everything from this point to __init_begin will be marked RO NX */ |
156 | RO_DATA(PAGE_SIZE) | |
8c2c3df3 | 157 | |
8eb7e28d JY |
158 | idmap_pg_dir = .; |
159 | . += IDMAP_DIR_SIZE; | |
9d2d75ed | 160 | idmap_pg_end = .; |
8eb7e28d JY |
161 | |
162 | #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 | |
163 | tramp_pg_dir = .; | |
164 | . += PAGE_SIZE; | |
165 | #endif | |
166 | ||
167 | #ifdef CONFIG_ARM64_SW_TTBR0_PAN | |
168 | reserved_ttbr0 = .; | |
169 | . += RESERVED_TTBR0_SIZE; | |
170 | #endif | |
171 | swapper_pg_dir = .; | |
172 | . += PAGE_SIZE; | |
173 | swapper_pg_end = .; | |
174 | ||
97740051 | 175 | . = ALIGN(SEGMENT_ALIGN); |
8c2c3df3 | 176 | __init_begin = .; |
2ebe088b | 177 | __inittext_begin = .; |
8c2c3df3 CM |
178 | |
179 | INIT_TEXT_SECTION(8) | |
ca2ef4ff MR |
180 | |
181 | __exittext_begin = .; | |
8c2c3df3 | 182 | .exit.text : { |
1eae811d | 183 | EXIT_TEXT |
8c2c3df3 | 184 | } |
ca2ef4ff | 185 | __exittext_end = .; |
da141706 | 186 | |
2ebe088b AB |
187 | . = ALIGN(4); |
188 | .altinstructions : { | |
189 | __alt_instructions = .; | |
190 | *(.altinstructions) | |
191 | __alt_instructions_end = .; | |
192 | } | |
2ebe088b | 193 | |
76085aff | 194 | . = ALIGN(SEGMENT_ALIGN); |
2ebe088b AB |
195 | __inittext_end = .; |
196 | __initdata_begin = .; | |
197 | ||
8c2c3df3 CM |
198 | .init.data : { |
199 | INIT_DATA | |
200 | INIT_SETUP(16) | |
201 | INIT_CALLS | |
202 | CON_INITCALL | |
8c2c3df3 | 203 | INIT_RAM_FS |
e35123d8 | 204 | *(.init.altinstructions .init.rodata.* .init.bss) /* from the EFI stub */ |
8c2c3df3 CM |
205 | } |
206 | .exit.data : { | |
1eae811d | 207 | EXIT_DATA |
8c2c3df3 CM |
208 | } |
209 | ||
98fb7548 | 210 | PERCPU_SECTION(L1_CACHE_BYTES) |
30c95391 | 211 | HYPERVISOR_PERCPU_SECTION |
8c2c3df3 | 212 | |
3bbd3db8 | 213 | .rela.dyn : ALIGN(8) { |
1e48ef7f | 214 | *(.rela .rela*) |
1e48ef7f | 215 | } |
e039ee4e | 216 | |
3bbd3db8 AB |
217 | __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR); |
218 | __rela_size = SIZEOF(.rela.dyn); | |
0cd3defe | 219 | |
5cf896fb PC |
220 | #ifdef CONFIG_RELR |
221 | .relr.dyn : ALIGN(8) { | |
222 | *(.relr.dyn) | |
223 | } | |
224 | ||
225 | __relr_offset = ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR); | |
226 | __relr_size = SIZEOF(.relr.dyn); | |
227 | #endif | |
228 | ||
97740051 | 229 | . = ALIGN(SEGMENT_ALIGN); |
2ebe088b | 230 | __initdata_end = .; |
9aa4ec15 MR |
231 | __init_end = .; |
232 | ||
3c620626 | 233 | _data = .; |
3c620626 | 234 | _sdata = .; |
c9174047 | 235 | RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN) |
b6113038 JM |
236 | |
237 | /* | |
238 | * Data written with the MMU off but read with the MMU on requires | |
239 | * cache lines to be invalidated, discarding up to a Cache Writeback | |
240 | * Granule (CWG) of data from the cache. Keep the section that | |
241 | * requires this type of maintenance to be in its own Cache Writeback | |
242 | * Granule (CWG) area so the cache maintenance operations don't | |
243 | * interfere with adjacent data. | |
244 | */ | |
245 | .mmuoff.data.write : ALIGN(SZ_2K) { | |
246 | __mmuoff_data_start = .; | |
247 | *(.mmuoff.data.write) | |
248 | } | |
249 | . = ALIGN(SZ_2K); | |
250 | .mmuoff.data.read : { | |
251 | *(.mmuoff.data.read) | |
252 | __mmuoff_data_end = .; | |
253 | } | |
254 | ||
a352ea3e | 255 | PECOFF_EDATA_PADDING |
cad27ef2 | 256 | __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin); |
3c620626 | 257 | _edata = .; |
8c2c3df3 | 258 | |
8c2c3df3 | 259 | BSS_SECTION(0, 0, 0) |
bd00cd5f MR |
260 | |
261 | . = ALIGN(PAGE_SIZE); | |
2b5548b6 JY |
262 | init_pg_dir = .; |
263 | . += INIT_DIR_SIZE; | |
264 | init_pg_end = .; | |
265 | ||
76085aff | 266 | . = ALIGN(SEGMENT_ALIGN); |
cad27ef2 | 267 | __pecoff_data_size = ABSOLUTE(. - __initdata_begin); |
8c2c3df3 CM |
268 | _end = .; |
269 | ||
270 | STABS_DEBUG | |
578d7f0f | 271 | DWARF_DEBUG |
c604abc3 | 272 | ELF_DETAILS |
a2c1d73b MR |
273 | |
274 | HEAD_SYMBOLS | |
be288182 KC |
275 | |
276 | /* | |
277 | * Sections that should stay zero sized, which is safer to | |
278 | * explicitly check instead of blindly discarding. | |
279 | */ | |
280 | .plt : { | |
5f692a81 | 281 | *(.plt) *(.plt.*) *(.iplt) *(.igot .igot.plt) |
be288182 KC |
282 | } |
283 | ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!") | |
284 | ||
285 | .data.rel.ro : { *(.data.rel.ro) } | |
286 | ASSERT(SIZEOF(.data.rel.ro) == 0, "Unexpected RELRO detected!") | |
8c2c3df3 | 287 | } |
2240bbb6 | 288 | |
90776dd1 KC |
289 | #include "image-vars.h" |
290 | ||
2240bbb6 | 291 | /* |
5dfe9d7d | 292 | * The HYP init code and ID map text can't be longer than a page each, |
06f75a1f | 293 | * and should not cross a page boundary. |
2240bbb6 | 294 | */ |
06f75a1f AB |
295 | ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, |
296 | "HYP init code too big or misaligned") | |
5dfe9d7d AB |
297 | ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, |
298 | "ID map text too big or misaligned") | |
82869ac5 JM |
299 | #ifdef CONFIG_HIBERNATION |
300 | ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1)) | |
301 | <= SZ_4K, "Hibernate exit text too big or misaligned") | |
302 | #endif | |
6c27c408 WD |
303 | #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 |
304 | ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE, | |
305 | "Entry trampoline text too big") | |
306 | #endif | |
da57a369 MR |
307 | /* |
308 | * If padding is applied before .head.text, virt<->phys conversions will fail. | |
309 | */ | |
120dc60d | 310 | ASSERT(_text == KIMAGE_VADDR, "HEAD is misaligned") |