1 /* SPDX-License-Identifier: GPL-2.0 */
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>
8 #include <asm/hyp_image.h>
10 #define HYPERVISOR_EXTABLE \
12 __start___kvm_ex_table = .; \
14 __stop___kvm_ex_table = .;
16 #define HYPERVISOR_DATA_SECTIONS \
17 HYP_SECTION_NAME(.rodata) : { \
18 . = ALIGN(PAGE_SIZE); \
19 __hyp_rodata_start = .; \
20 *(HYP_SECTION_NAME(.data..ro_after_init)) \
21 *(HYP_SECTION_NAME(.rodata)) \
22 . = ALIGN(PAGE_SIZE); \
23 __hyp_rodata_end = .; \
26 #define HYPERVISOR_PERCPU_SECTION \
27 . = ALIGN(PAGE_SIZE); \
28 HYP_SECTION_NAME(.data..percpu) : { \
29 *(HYP_SECTION_NAME(.data..percpu)) \
32 #define HYPERVISOR_RELOC_SECTION \
33 .hyp.reloc : ALIGN(4) { \
34 __hyp_reloc_begin = .; \
36 __hyp_reloc_end = .; \
39 #define BSS_FIRST_SECTIONS \
40 __hyp_bss_start = .; \
41 *(HYP_SECTION_NAME(.bss)) \
42 . = ALIGN(PAGE_SIZE); \
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.
51 #define SBSS_ALIGN PAGE_SIZE
52 #else /* CONFIG_KVM */
53 #define HYPERVISOR_EXTABLE
54 #define HYPERVISOR_DATA_SECTIONS
55 #define HYPERVISOR_PERCPU_SECTION
56 #define HYPERVISOR_RELOC_SECTION
60 #define RO_EXCEPTION_TABLE_ALIGN 8
61 #define RUNTIME_DISCARD_EXIT
63 #include <asm-generic/vmlinux.lds.h>
64 #include <asm/cache.h>
65 #include <asm/kernel-pgtable.h>
66 #include <asm/memory.h>
76 #define HYPERVISOR_TEXT \
77 . = ALIGN(PAGE_SIZE); \
78 __hyp_idmap_text_start = .; \
80 __hyp_idmap_text_end = .; \
81 __hyp_text_start = .; \
84 . = ALIGN(PAGE_SIZE); \
89 __idmap_text_start = .; \
93 #ifdef CONFIG_HIBERNATION
94 #define HIBERNATE_TEXT \
96 __hibernate_exit_text_start = .; \
97 *(.hibernate_exit.text) \
98 __hibernate_exit_text_end = .;
100 #define HIBERNATE_TEXT
103 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
105 . = ALIGN(PAGE_SIZE); \
106 __entry_tramp_text_start = .; \
107 *(.entry.tramp.text) \
108 . = ALIGN(PAGE_SIZE); \
109 __entry_tramp_text_end = .;
115 * The size of the PE/COFF section that covers the kernel image, which
116 * runs from _stext to _edata, must be a round multiple of the PE/COFF
117 * FileAlignment, which we set to its minimum value of 0x200. '_stext'
118 * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
119 * boundary should be sufficient.
121 PECOFF_FILE_ALIGNMENT = 0x200;
124 #define PECOFF_EDATA_PADDING \
125 .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
127 #define PECOFF_EDATA_PADDING
133 * XXX: The linker does not define how output sections are
134 * assigned to input sections when there are multiple statements
135 * matching the same input section name. There is no documented
141 *(.dynsym .dynstr .hash .gnu.hash)
150 .text : ALIGN(SEGMENT_ALIGN) { /* Real text segment */
151 _stext = .; /* Text and read-only data */
167 *(.got) /* Global offset table */
171 * Make sure that the .got.plt is either completely empty or it
172 * contains only the lazy dispatch entries.
174 .got.plt : { *(.got.plt) }
175 ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18,
176 "Unexpected GOT/PLT entries detected!")
178 . = ALIGN(SEGMENT_ALIGN);
179 _etext = .; /* End of text section */
181 /* everything from this point to __init_begin will be marked RO NX */
184 HYPERVISOR_DATA_SECTIONS
190 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
201 . = ALIGN(SEGMENT_ALIGN);
203 __inittext_begin = .;
207 __exittext_begin = .;
215 __alt_instructions = .;
217 __alt_instructions_end = .;
220 . = ALIGN(SEGMENT_ALIGN);
222 __initdata_begin = .;
230 *(.init.altinstructions .init.bss) /* from the EFI stub */
236 PERCPU_SECTION(L1_CACHE_BYTES)
237 HYPERVISOR_PERCPU_SECTION
239 HYPERVISOR_RELOC_SECTION
241 .rela.dyn : ALIGN(8) {
245 __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR);
246 __rela_size = SIZEOF(.rela.dyn);
249 .relr.dyn : ALIGN(8) {
253 __relr_offset = ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR);
254 __relr_size = SIZEOF(.relr.dyn);
257 . = ALIGN(SEGMENT_ALIGN);
263 RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
266 * Data written with the MMU off but read with the MMU on requires
267 * cache lines to be invalidated, discarding up to a Cache Writeback
268 * Granule (CWG) of data from the cache. Keep the section that
269 * requires this type of maintenance to be in its own Cache Writeback
270 * Granule (CWG) area so the cache maintenance operations don't
271 * interfere with adjacent data.
273 .mmuoff.data.write : ALIGN(SZ_2K) {
274 __mmuoff_data_start = .;
275 *(.mmuoff.data.write)
278 .mmuoff.data.read : {
280 __mmuoff_data_end = .;
284 __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
287 BSS_SECTION(SBSS_ALIGN, 0, 0)
289 . = ALIGN(PAGE_SIZE);
294 . = ALIGN(SEGMENT_ALIGN);
295 __pecoff_data_size = ABSOLUTE(. - __initdata_begin);
305 * Sections that should stay zero sized, which is safer to
306 * explicitly check instead of blindly discarding.
309 *(.plt) *(.plt.*) *(.iplt) *(.igot .igot.plt)
311 ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!")
313 .data.rel.ro : { *(.data.rel.ro) }
314 ASSERT(SIZEOF(.data.rel.ro) == 0, "Unexpected RELRO detected!")
317 #include "image-vars.h"
320 * The HYP init code and ID map text can't be longer than a page each. The
321 * former is page-aligned, but the latter may not be with 16K or 64K pages, so
322 * it should also not cross a page boundary.
324 ASSERT(__hyp_idmap_text_end - __hyp_idmap_text_start <= PAGE_SIZE,
325 "HYP init code too big")
326 ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
327 "ID map text too big or misaligned")
328 #ifdef CONFIG_HIBERNATION
329 ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
330 <= SZ_4K, "Hibernate exit text too big or misaligned")
332 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
333 ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) <= 3*PAGE_SIZE,
334 "Entry trampoline text too big")
337 ASSERT(__hyp_bss_start == __bss_start, "HYP and Host BSS are misaligned")
340 * If padding is applied before .head.text, virt<->phys conversions will fail.
342 ASSERT(_text == KIMAGE_VADDR, "HEAD is misaligned")
344 ASSERT(swapper_pg_dir - reserved_pg_dir == RESERVED_SWAPPER_OFFSET,
345 "RESERVED_SWAPPER_OFFSET is wrong!")
347 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
348 ASSERT(swapper_pg_dir - tramp_pg_dir == TRAMP_SWAPPER_OFFSET,
349 "TRAMP_SWAPPER_OFFSET is wrong!")