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)) \
47 #define HYPERVISOR_RELOC_SECTION \
48 .hyp.reloc : ALIGN(4) { \
49 __hyp_reloc_begin = .; \
51 __hyp_reloc_end = .; \
54 #else /* CONFIG_KVM */
55 #define HYPERVISOR_EXTABLE
56 #define HYPERVISOR_DATA_SECTIONS
57 #define HYPERVISOR_PERCPU_SECTION
58 #define HYPERVISOR_RELOC_SECTION
61 #define HYPERVISOR_TEXT \
63 * Align to 4 KB so that \
64 * a) the HYP vector table is at its minimum \
65 * alignment of 2048 bytes \
66 * b) the HYP init code will not cross a page \
67 * boundary if its size does not exceed \
68 * 4 KB (see related ASSERT() below) \
71 __hyp_idmap_text_start = .; \
73 __hyp_idmap_text_end = .; \
74 __hyp_text_start = .; \
81 __idmap_text_start = .; \
85 #ifdef CONFIG_HIBERNATION
86 #define HIBERNATE_TEXT \
88 __hibernate_exit_text_start = .; \
89 *(.hibernate_exit.text) \
90 __hibernate_exit_text_end = .;
92 #define HIBERNATE_TEXT
95 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
97 . = ALIGN(PAGE_SIZE); \
98 __entry_tramp_text_start = .; \
99 *(.entry.tramp.text) \
100 . = ALIGN(PAGE_SIZE); \
101 __entry_tramp_text_end = .;
107 * The size of the PE/COFF section that covers the kernel image, which
108 * runs from _stext to _edata, must be a round multiple of the PE/COFF
109 * FileAlignment, which we set to its minimum value of 0x200. '_stext'
110 * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
111 * boundary should be sufficient.
113 PECOFF_FILE_ALIGNMENT = 0x200;
116 #define PECOFF_EDATA_PADDING \
117 .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
119 #define PECOFF_EDATA_PADDING
125 * XXX: The linker does not define how output sections are
126 * assigned to input sections when there are multiple statements
127 * matching the same input section name. There is no documented
133 *(.dynsym .dynstr .hash .gnu.hash)
142 .text : ALIGN(SEGMENT_ALIGN) { /* Real text segment */
143 _stext = .; /* Text and read-only data */
159 *(.got) /* Global offset table */
163 * Make sure that the .got.plt is either completely empty or it
164 * contains only the lazy dispatch entries.
166 .got.plt : { *(.got.plt) }
167 ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18,
168 "Unexpected GOT/PLT entries detected!")
170 . = ALIGN(SEGMENT_ALIGN);
171 _etext = .; /* End of text section */
173 /* everything from this point to __init_begin will be marked RO NX */
180 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
191 . = ALIGN(SEGMENT_ALIGN);
193 __inittext_begin = .;
197 __exittext_begin = .;
205 __alt_instructions = .;
207 __alt_instructions_end = .;
210 . = ALIGN(SEGMENT_ALIGN);
212 __initdata_begin = .;
220 *(.init.altinstructions .init.bss) /* from the EFI stub */
226 PERCPU_SECTION(L1_CACHE_BYTES)
227 HYPERVISOR_PERCPU_SECTION
229 HYPERVISOR_RELOC_SECTION
231 .rela.dyn : ALIGN(8) {
235 __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR);
236 __rela_size = SIZEOF(.rela.dyn);
239 .relr.dyn : ALIGN(8) {
243 __relr_offset = ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR);
244 __relr_size = SIZEOF(.relr.dyn);
247 . = ALIGN(SEGMENT_ALIGN);
253 RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
255 HYPERVISOR_DATA_SECTIONS
258 * Data written with the MMU off but read with the MMU on requires
259 * cache lines to be invalidated, discarding up to a Cache Writeback
260 * Granule (CWG) of data from the cache. Keep the section that
261 * requires this type of maintenance to be in its own Cache Writeback
262 * Granule (CWG) area so the cache maintenance operations don't
263 * interfere with adjacent data.
265 .mmuoff.data.write : ALIGN(SZ_2K) {
266 __mmuoff_data_start = .;
267 *(.mmuoff.data.write)
270 .mmuoff.data.read : {
272 __mmuoff_data_end = .;
276 __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
281 . = ALIGN(PAGE_SIZE);
286 . = ALIGN(SEGMENT_ALIGN);
287 __pecoff_data_size = ABSOLUTE(. - __initdata_begin);
297 * Sections that should stay zero sized, which is safer to
298 * explicitly check instead of blindly discarding.
301 *(.plt) *(.plt.*) *(.iplt) *(.igot .igot.plt)
303 ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!")
305 .data.rel.ro : { *(.data.rel.ro) }
306 ASSERT(SIZEOF(.data.rel.ro) == 0, "Unexpected RELRO detected!")
309 #include "image-vars.h"
312 * The HYP init code and ID map text can't be longer than a page each,
313 * and should not cross a page boundary.
315 ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
316 "HYP init code too big or misaligned")
317 ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
318 "ID map text too big or misaligned")
319 #ifdef CONFIG_HIBERNATION
320 ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
321 <= SZ_4K, "Hibernate exit text too big or misaligned")
323 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
324 ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE,
325 "Entry trampoline text too big")
328 * If padding is applied before .head.text, virt<->phys conversions will fail.
330 ASSERT(_text == KIMAGE_VADDR, "HEAD is misaligned")
332 ASSERT(swapper_pg_dir - reserved_pg_dir == RESERVED_SWAPPER_OFFSET,
333 "RESERVED_SWAPPER_OFFSET is wrong!")
335 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
336 ASSERT(swapper_pg_dir - tramp_pg_dir == TRAMP_SWAPPER_OFFSET,
337 "TRAMP_SWAPPER_OFFSET is wrong!")