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 #define RO_EXCEPTION_TABLE_ALIGN 8
9 #define RUNTIME_DISCARD_EXIT
11 #include <asm-generic/vmlinux.lds.h>
12 #include <asm/cache.h>
13 #include <asm/hyp_image.h>
14 #include <asm/kernel-pgtable.h>
15 #include <asm/memory.h>
27 #define HYPERVISOR_EXTABLE \
29 __start___kvm_ex_table = .; \
31 __stop___kvm_ex_table = .;
33 #define HYPERVISOR_DATA_SECTIONS \
34 HYP_SECTION_NAME(.rodata) : { \
35 __hyp_rodata_start = .; \
36 *(HYP_SECTION_NAME(.data..ro_after_init)) \
37 *(HYP_SECTION_NAME(.rodata)) \
38 __hyp_rodata_end = .; \
41 #define HYPERVISOR_PERCPU_SECTION \
42 . = ALIGN(PAGE_SIZE); \
43 HYP_SECTION_NAME(.data..percpu) : { \
44 *(HYP_SECTION_NAME(.data..percpu)) \
46 #else /* CONFIG_KVM */
47 #define HYPERVISOR_EXTABLE
48 #define HYPERVISOR_DATA_SECTIONS
49 #define HYPERVISOR_PERCPU_SECTION
52 #define HYPERVISOR_TEXT \
54 * Align to 4 KB so that \
55 * a) the HYP vector table is at its minimum \
56 * alignment of 2048 bytes \
57 * b) the HYP init code will not cross a page \
58 * boundary if its size does not exceed \
59 * 4 KB (see related ASSERT() below) \
62 __hyp_idmap_text_start = .; \
64 __hyp_idmap_text_end = .; \
65 __hyp_text_start = .; \
72 __idmap_text_start = .; \
76 #ifdef CONFIG_HIBERNATION
77 #define HIBERNATE_TEXT \
79 __hibernate_exit_text_start = .; \
80 *(.hibernate_exit.text) \
81 __hibernate_exit_text_end = .;
83 #define HIBERNATE_TEXT
86 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
88 . = ALIGN(PAGE_SIZE); \
89 __entry_tramp_text_start = .; \
90 *(.entry.tramp.text) \
91 . = ALIGN(PAGE_SIZE); \
92 __entry_tramp_text_end = .;
98 * The size of the PE/COFF section that covers the kernel image, which
99 * runs from _stext to _edata, must be a round multiple of the PE/COFF
100 * FileAlignment, which we set to its minimum value of 0x200. '_stext'
101 * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
102 * boundary should be sufficient.
104 PECOFF_FILE_ALIGNMENT = 0x200;
107 #define PECOFF_EDATA_PADDING \
108 .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
110 #define PECOFF_EDATA_PADDING
116 * XXX: The linker does not define how output sections are
117 * assigned to input sections when there are multiple statements
118 * matching the same input section name. There is no documented
124 *(.dynsym .dynstr .hash .gnu.hash)
133 .text : ALIGN(SEGMENT_ALIGN) { /* Real text segment */
134 _stext = .; /* Text and read-only data */
150 *(.got) /* Global offset table */
154 * Make sure that the .got.plt is either completely empty or it
155 * contains only the lazy dispatch entries.
157 .got.plt : { *(.got.plt) }
158 ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18,
159 "Unexpected GOT/PLT entries detected!")
161 . = ALIGN(SEGMENT_ALIGN);
162 _etext = .; /* End of text section */
164 /* everything from this point to __init_begin will be marked RO NX */
171 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
182 . = ALIGN(SEGMENT_ALIGN);
184 __inittext_begin = .;
188 __exittext_begin = .;
196 __alt_instructions = .;
198 __alt_instructions_end = .;
201 . = ALIGN(SEGMENT_ALIGN);
203 __initdata_begin = .;
211 *(.init.altinstructions .init.bss) /* from the EFI stub */
217 PERCPU_SECTION(L1_CACHE_BYTES)
218 HYPERVISOR_PERCPU_SECTION
220 .rela.dyn : ALIGN(8) {
224 __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR);
225 __rela_size = SIZEOF(.rela.dyn);
228 .relr.dyn : ALIGN(8) {
232 __relr_offset = ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR);
233 __relr_size = SIZEOF(.relr.dyn);
236 . = ALIGN(SEGMENT_ALIGN);
242 RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
244 HYPERVISOR_DATA_SECTIONS
247 * Data written with the MMU off but read with the MMU on requires
248 * cache lines to be invalidated, discarding up to a Cache Writeback
249 * Granule (CWG) of data from the cache. Keep the section that
250 * requires this type of maintenance to be in its own Cache Writeback
251 * Granule (CWG) area so the cache maintenance operations don't
252 * interfere with adjacent data.
254 .mmuoff.data.write : ALIGN(SZ_2K) {
255 __mmuoff_data_start = .;
256 *(.mmuoff.data.write)
259 .mmuoff.data.read : {
261 __mmuoff_data_end = .;
265 __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
270 . = ALIGN(PAGE_SIZE);
275 . = ALIGN(SEGMENT_ALIGN);
276 __pecoff_data_size = ABSOLUTE(. - __initdata_begin);
286 * Sections that should stay zero sized, which is safer to
287 * explicitly check instead of blindly discarding.
290 *(.plt) *(.plt.*) *(.iplt) *(.igot .igot.plt)
292 ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!")
294 .data.rel.ro : { *(.data.rel.ro) }
295 ASSERT(SIZEOF(.data.rel.ro) == 0, "Unexpected RELRO detected!")
298 #include "image-vars.h"
301 * The HYP init code and ID map text can't be longer than a page each,
302 * and should not cross a page boundary.
304 ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
305 "HYP init code too big or misaligned")
306 ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
307 "ID map text too big or misaligned")
308 #ifdef CONFIG_HIBERNATION
309 ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
310 <= SZ_4K, "Hibernate exit text too big or misaligned")
312 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
313 ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE,
314 "Entry trampoline text too big")
317 * If padding is applied before .head.text, virt<->phys conversions will fail.
319 ASSERT(_text == KIMAGE_VADDR, "HEAD is misaligned")