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 | ||
ce492a16 | 8 | #include <asm/hyp_image.h> |
3471ee06 | 9 | #ifdef CONFIG_KVM |
e9ee186b JM |
10 | #define HYPERVISOR_EXTABLE \ |
11 | . = ALIGN(SZ_8); \ | |
12 | __start___kvm_ex_table = .; \ | |
13 | *(__kvm_ex_table) \ | |
14 | __stop___kvm_ex_table = .; | |
30c95391 | 15 | |
2d7bf218 | 16 | #define HYPERVISOR_DATA_SECTIONS \ |
16174eea | 17 | HYP_SECTION_NAME(.rodata) : { \ |
b83042f0 | 18 | . = ALIGN(PAGE_SIZE); \ |
16174eea | 19 | __hyp_rodata_start = .; \ |
2d7bf218 | 20 | *(HYP_SECTION_NAME(.data..ro_after_init)) \ |
16174eea | 21 | *(HYP_SECTION_NAME(.rodata)) \ |
b83042f0 | 22 | . = ALIGN(PAGE_SIZE); \ |
16174eea | 23 | __hyp_rodata_end = .; \ |
2d7bf218 DB |
24 | } |
25 | ||
30c95391 DB |
26 | #define HYPERVISOR_PERCPU_SECTION \ |
27 | . = ALIGN(PAGE_SIZE); \ | |
28 | HYP_SECTION_NAME(.data..percpu) : { \ | |
29 | *(HYP_SECTION_NAME(.data..percpu)) \ | |
30 | } | |
8c49b5d4 DB |
31 | |
32 | #define HYPERVISOR_RELOC_SECTION \ | |
33 | .hyp.reloc : ALIGN(4) { \ | |
34 | __hyp_reloc_begin = .; \ | |
35 | *(.hyp.reloc) \ | |
36 | __hyp_reloc_end = .; \ | |
37 | } | |
38 | ||
380e18ad QP |
39 | #define BSS_FIRST_SECTIONS \ |
40 | __hyp_bss_start = .; \ | |
41 | *(HYP_SECTION_NAME(.bss)) \ | |
42 | . = ALIGN(PAGE_SIZE); \ | |
43 | __hyp_bss_end = .; | |
44 | ||
45 | /* | |
46 | * We require that __hyp_bss_start and __bss_start are aligned, and enforce it | |
47 | * with an assertion. But the BSS_SECTION macro places an empty .sbss section | |
48 | * between them, which can in some cases cause the linker to misalign them. To | |
49 | * work around the issue, force a page alignment for __bss_start. | |
50 | */ | |
51 | #define SBSS_ALIGN PAGE_SIZE | |
3471ee06 DB |
52 | #else /* CONFIG_KVM */ |
53 | #define HYPERVISOR_EXTABLE | |
2d7bf218 | 54 | #define HYPERVISOR_DATA_SECTIONS |
30c95391 | 55 | #define HYPERVISOR_PERCPU_SECTION |
8c49b5d4 | 56 | #define HYPERVISOR_RELOC_SECTION |
380e18ad | 57 | #define SBSS_ALIGN 0 |
3471ee06 | 58 | #endif |
e9ee186b | 59 | |
d6e2cc56 | 60 | #define RO_EXCEPTION_TABLE_ALIGN 4 |
380e18ad QP |
61 | #define RUNTIME_DISCARD_EXIT |
62 | ||
63 | #include <asm-generic/vmlinux.lds.h> | |
64 | #include <asm/cache.h> | |
65 | #include <asm/kernel-pgtable.h> | |
19a046f0 | 66 | #include <asm/kexec.h> |
380e18ad QP |
67 | #include <asm/memory.h> |
68 | #include <asm/page.h> | |
69 | ||
70 | #include "image.h" | |
71 | ||
72 | OUTPUT_ARCH(aarch64) | |
73 | ENTRY(_text) | |
74 | ||
75 | jiffies = jiffies_64; | |
76 | ||
2240bbb6 | 77 | #define HYPERVISOR_TEXT \ |
b83042f0 | 78 | . = ALIGN(PAGE_SIZE); \ |
5c636aa0 | 79 | __hyp_idmap_text_start = .; \ |
2240bbb6 | 80 | *(.hyp.idmap.text) \ |
5c636aa0 MY |
81 | __hyp_idmap_text_end = .; \ |
82 | __hyp_text_start = .; \ | |
2240bbb6 | 83 | *(.hyp.text) \ |
e9ee186b | 84 | HYPERVISOR_EXTABLE \ |
b83042f0 | 85 | . = ALIGN(PAGE_SIZE); \ |
5c636aa0 | 86 | __hyp_text_end = .; |
2240bbb6 | 87 | |
5dfe9d7d AB |
88 | #define IDMAP_TEXT \ |
89 | . = ALIGN(SZ_4K); \ | |
5c636aa0 | 90 | __idmap_text_start = .; \ |
5dfe9d7d | 91 | *(.idmap.text) \ |
5c636aa0 | 92 | __idmap_text_end = .; |
5dfe9d7d | 93 | |
82869ac5 JM |
94 | #ifdef CONFIG_HIBERNATION |
95 | #define HIBERNATE_TEXT \ | |
5c636aa0 | 96 | __hibernate_exit_text_start = .; \ |
82869ac5 | 97 | *(.hibernate_exit.text) \ |
5c636aa0 | 98 | __hibernate_exit_text_end = .; |
82869ac5 JM |
99 | #else |
100 | #define HIBERNATE_TEXT | |
101 | #endif | |
102 | ||
19a046f0 PT |
103 | #ifdef CONFIG_KEXEC_CORE |
104 | #define KEXEC_TEXT \ | |
19a046f0 PT |
105 | __relocate_new_kernel_start = .; \ |
106 | *(.kexec_relocate.text) \ | |
107 | __relocate_new_kernel_end = .; | |
108 | #else | |
109 | #define KEXEC_TEXT | |
110 | #endif | |
111 | ||
c7b9adaf WD |
112 | #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 |
113 | #define TRAMP_TEXT \ | |
114 | . = ALIGN(PAGE_SIZE); \ | |
5c636aa0 | 115 | __entry_tramp_text_start = .; \ |
c7b9adaf WD |
116 | *(.entry.tramp.text) \ |
117 | . = ALIGN(PAGE_SIZE); \ | |
5c636aa0 | 118 | __entry_tramp_text_end = .; |
c7b9adaf WD |
119 | #else |
120 | #define TRAMP_TEXT | |
121 | #endif | |
122 | ||
a352ea3e AB |
123 | /* |
124 | * The size of the PE/COFF section that covers the kernel image, which | |
348a625d AB |
125 | * runs from _stext to _edata, must be a round multiple of the PE/COFF |
126 | * FileAlignment, which we set to its minimum value of 0x200. '_stext' | |
a352ea3e AB |
127 | * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned |
128 | * boundary should be sufficient. | |
129 | */ | |
130 | PECOFF_FILE_ALIGNMENT = 0x200; | |
131 | ||
132 | #ifdef CONFIG_EFI | |
133 | #define PECOFF_EDATA_PADDING \ | |
134 | .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); } | |
135 | #else | |
136 | #define PECOFF_EDATA_PADDING | |
137 | #endif | |
138 | ||
8c2c3df3 CM |
139 | SECTIONS |
140 | { | |
141 | /* | |
142 | * XXX: The linker does not define how output sections are | |
143 | * assigned to input sections when there are multiple statements | |
144 | * matching the same input section name. There is no documented | |
145 | * order of matching. | |
146 | */ | |
2883352b | 147 | DISCARDS |
8c2c3df3 | 148 | /DISCARD/ : { |
1e48ef7f | 149 | *(.interp .dynamic) |
3bbd3db8 | 150 | *(.dynsym .dynstr .hash .gnu.hash) |
8c2c3df3 CM |
151 | } |
152 | ||
120dc60d | 153 | . = KIMAGE_VADDR; |
8c2c3df3 CM |
154 | |
155 | .head.text : { | |
156 | _text = .; | |
157 | HEAD_TEXT | |
158 | } | |
e2a073dd | 159 | .text : ALIGN(SEGMENT_ALIGN) { /* Real text segment */ |
8c2c3df3 | 160 | _stext = .; /* Text and read-only data */ |
8c2c3df3 | 161 | IRQENTRY_TEXT |
be7635e7 | 162 | SOFTIRQENTRY_TEXT |
888b3c87 | 163 | ENTRY_TEXT |
8c2c3df3 CM |
164 | TEXT_TEXT |
165 | SCHED_TEXT | |
6727ad9e | 166 | CPUIDLE_TEXT |
8c2c3df3 | 167 | LOCK_TEXT |
2dd0e8d2 | 168 | KPROBES_TEXT |
2240bbb6 | 169 | HYPERVISOR_TEXT |
5dfe9d7d | 170 | IDMAP_TEXT |
8c2c3df3 CM |
171 | *(.gnu.warning) |
172 | . = ALIGN(16); | |
173 | *(.got) /* Global offset table */ | |
174 | } | |
175 | ||
be288182 KC |
176 | /* |
177 | * Make sure that the .got.plt is either completely empty or it | |
178 | * contains only the lazy dispatch entries. | |
179 | */ | |
180 | .got.plt : { *(.got.plt) } | |
181 | ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18, | |
182 | "Unexpected GOT/PLT entries detected!") | |
183 | ||
97740051 | 184 | . = ALIGN(SEGMENT_ALIGN); |
9fdc14c5 AB |
185 | _etext = .; /* End of text section */ |
186 | ||
19f6bc32 KC |
187 | /* everything from this point to __init_begin will be marked RO NX */ |
188 | RO_DATA(PAGE_SIZE) | |
8c2c3df3 | 189 | |
eb48d154 MZ |
190 | HYPERVISOR_DATA_SECTIONS |
191 | ||
6ee3cf6a AB |
192 | /* code sections that are never executed via the kernel mapping */ |
193 | .rodata.text : { | |
194 | TRAMP_TEXT | |
195 | HIBERNATE_TEXT | |
196 | KEXEC_TEXT | |
197 | . = ALIGN(PAGE_SIZE); | |
198 | } | |
199 | ||
8eb7e28d JY |
200 | idmap_pg_dir = .; |
201 | . += IDMAP_DIR_SIZE; | |
9d2d75ed | 202 | idmap_pg_end = .; |
8eb7e28d JY |
203 | |
204 | #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 | |
205 | tramp_pg_dir = .; | |
206 | . += PAGE_SIZE; | |
207 | #endif | |
208 | ||
833be850 MR |
209 | reserved_pg_dir = .; |
210 | . += PAGE_SIZE; | |
211 | ||
8eb7e28d JY |
212 | swapper_pg_dir = .; |
213 | . += PAGE_SIZE; | |
8eb7e28d | 214 | |
97740051 | 215 | . = ALIGN(SEGMENT_ALIGN); |
8c2c3df3 | 216 | __init_begin = .; |
2ebe088b | 217 | __inittext_begin = .; |
8c2c3df3 CM |
218 | |
219 | INIT_TEXT_SECTION(8) | |
ca2ef4ff MR |
220 | |
221 | __exittext_begin = .; | |
8c2c3df3 | 222 | .exit.text : { |
1eae811d | 223 | EXIT_TEXT |
8c2c3df3 | 224 | } |
ca2ef4ff | 225 | __exittext_end = .; |
da141706 | 226 | |
2ebe088b AB |
227 | . = ALIGN(4); |
228 | .altinstructions : { | |
229 | __alt_instructions = .; | |
230 | *(.altinstructions) | |
231 | __alt_instructions_end = .; | |
232 | } | |
2ebe088b | 233 | |
76085aff | 234 | . = ALIGN(SEGMENT_ALIGN); |
2ebe088b AB |
235 | __inittext_end = .; |
236 | __initdata_begin = .; | |
237 | ||
8c2c3df3 CM |
238 | .init.data : { |
239 | INIT_DATA | |
240 | INIT_SETUP(16) | |
241 | INIT_CALLS | |
242 | CON_INITCALL | |
8c2c3df3 | 243 | INIT_RAM_FS |
ba4259a6 | 244 | *(.init.altinstructions .init.bss) /* from the EFI stub */ |
8c2c3df3 CM |
245 | } |
246 | .exit.data : { | |
1eae811d | 247 | EXIT_DATA |
8c2c3df3 CM |
248 | } |
249 | ||
98fb7548 | 250 | PERCPU_SECTION(L1_CACHE_BYTES) |
30c95391 | 251 | HYPERVISOR_PERCPU_SECTION |
8c2c3df3 | 252 | |
8c49b5d4 DB |
253 | HYPERVISOR_RELOC_SECTION |
254 | ||
3bbd3db8 | 255 | .rela.dyn : ALIGN(8) { |
1e48ef7f | 256 | *(.rela .rela*) |
1e48ef7f | 257 | } |
e039ee4e | 258 | |
3bbd3db8 AB |
259 | __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR); |
260 | __rela_size = SIZEOF(.rela.dyn); | |
0cd3defe | 261 | |
5cf896fb PC |
262 | #ifdef CONFIG_RELR |
263 | .relr.dyn : ALIGN(8) { | |
264 | *(.relr.dyn) | |
265 | } | |
266 | ||
267 | __relr_offset = ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR); | |
268 | __relr_size = SIZEOF(.relr.dyn); | |
269 | #endif | |
270 | ||
97740051 | 271 | . = ALIGN(SEGMENT_ALIGN); |
2ebe088b | 272 | __initdata_end = .; |
9aa4ec15 MR |
273 | __init_end = .; |
274 | ||
3c620626 | 275 | _data = .; |
3c620626 | 276 | _sdata = .; |
c9174047 | 277 | RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN) |
b6113038 JM |
278 | |
279 | /* | |
280 | * Data written with the MMU off but read with the MMU on requires | |
281 | * cache lines to be invalidated, discarding up to a Cache Writeback | |
282 | * Granule (CWG) of data from the cache. Keep the section that | |
283 | * requires this type of maintenance to be in its own Cache Writeback | |
284 | * Granule (CWG) area so the cache maintenance operations don't | |
285 | * interfere with adjacent data. | |
286 | */ | |
287 | .mmuoff.data.write : ALIGN(SZ_2K) { | |
288 | __mmuoff_data_start = .; | |
289 | *(.mmuoff.data.write) | |
290 | } | |
291 | . = ALIGN(SZ_2K); | |
292 | .mmuoff.data.read : { | |
293 | *(.mmuoff.data.read) | |
294 | __mmuoff_data_end = .; | |
295 | } | |
296 | ||
a352ea3e | 297 | PECOFF_EDATA_PADDING |
cad27ef2 | 298 | __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin); |
3c620626 | 299 | _edata = .; |
8c2c3df3 | 300 | |
380e18ad | 301 | BSS_SECTION(SBSS_ALIGN, 0, 0) |
bd00cd5f MR |
302 | |
303 | . = ALIGN(PAGE_SIZE); | |
2b5548b6 JY |
304 | init_pg_dir = .; |
305 | . += INIT_DIR_SIZE; | |
306 | init_pg_end = .; | |
307 | ||
76085aff | 308 | . = ALIGN(SEGMENT_ALIGN); |
cad27ef2 | 309 | __pecoff_data_size = ABSOLUTE(. - __initdata_begin); |
8c2c3df3 CM |
310 | _end = .; |
311 | ||
312 | STABS_DEBUG | |
578d7f0f | 313 | DWARF_DEBUG |
c604abc3 | 314 | ELF_DETAILS |
a2c1d73b MR |
315 | |
316 | HEAD_SYMBOLS | |
be288182 KC |
317 | |
318 | /* | |
319 | * Sections that should stay zero sized, which is safer to | |
320 | * explicitly check instead of blindly discarding. | |
321 | */ | |
322 | .plt : { | |
5f692a81 | 323 | *(.plt) *(.plt.*) *(.iplt) *(.igot .igot.plt) |
be288182 KC |
324 | } |
325 | ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!") | |
326 | ||
327 | .data.rel.ro : { *(.data.rel.ro) } | |
328 | ASSERT(SIZEOF(.data.rel.ro) == 0, "Unexpected RELRO detected!") | |
8c2c3df3 | 329 | } |
2240bbb6 | 330 | |
90776dd1 KC |
331 | #include "image-vars.h" |
332 | ||
2240bbb6 | 333 | /* |
b83042f0 QP |
334 | * The HYP init code and ID map text can't be longer than a page each. The |
335 | * former is page-aligned, but the latter may not be with 16K or 64K pages, so | |
336 | * it should also not cross a page boundary. | |
2240bbb6 | 337 | */ |
b83042f0 QP |
338 | ASSERT(__hyp_idmap_text_end - __hyp_idmap_text_start <= PAGE_SIZE, |
339 | "HYP init code too big") | |
5dfe9d7d AB |
340 | ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, |
341 | "ID map text too big or misaligned") | |
82869ac5 | 342 | #ifdef CONFIG_HIBERNATION |
6ee3cf6a AB |
343 | ASSERT(__hibernate_exit_text_end - __hibernate_exit_text_start <= SZ_4K, |
344 | "Hibernate exit text is bigger than 4 KiB") | |
82869ac5 | 345 | #endif |
6c27c408 | 346 | #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 |
a9c406e6 | 347 | ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) <= 3*PAGE_SIZE, |
6c27c408 WD |
348 | "Entry trampoline text too big") |
349 | #endif | |
380e18ad QP |
350 | #ifdef CONFIG_KVM |
351 | ASSERT(__hyp_bss_start == __bss_start, "HYP and Host BSS are misaligned") | |
352 | #endif | |
da57a369 MR |
353 | /* |
354 | * If padding is applied before .head.text, virt<->phys conversions will fail. | |
355 | */ | |
120dc60d | 356 | ASSERT(_text == KIMAGE_VADDR, "HEAD is misaligned") |
00ef5434 JG |
357 | |
358 | ASSERT(swapper_pg_dir - reserved_pg_dir == RESERVED_SWAPPER_OFFSET, | |
359 | "RESERVED_SWAPPER_OFFSET is wrong!") | |
0188a894 JG |
360 | |
361 | #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 | |
362 | ASSERT(swapper_pg_dir - tramp_pg_dir == TRAMP_SWAPPER_OFFSET, | |
363 | "TRAMP_SWAPPER_OFFSET is wrong!") | |
364 | #endif | |
19a046f0 PT |
365 | |
366 | #ifdef CONFIG_KEXEC_CORE | |
367 | /* kexec relocation code should fit into one KEXEC_CONTROL_PAGE_SIZE */ | |
6ee3cf6a AB |
368 | ASSERT(__relocate_new_kernel_end - __relocate_new_kernel_start <= SZ_4K, |
369 | "kexec relocation code is bigger than 4 KiB") | |
19a046f0 PT |
370 | ASSERT(KEXEC_CONTROL_PAGE_SIZE >= SZ_4K, "KEXEC_CONTROL_PAGE_SIZE is broken") |
371 | #endif |