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(.data..ro_after_init) : { \
35 __hyp_data_ro_after_init_start = .; \
36 *(HYP_SECTION_NAME(.data..ro_after_init)) \
37 __hyp_data_ro_after_init_end = .; \
40 #define HYPERVISOR_PERCPU_SECTION \
41 . = ALIGN(PAGE_SIZE); \
42 HYP_SECTION_NAME(.data..percpu) : { \
43 *(HYP_SECTION_NAME(.data..percpu)) \
45 #else /* CONFIG_KVM */
46 #define HYPERVISOR_EXTABLE
47 #define HYPERVISOR_DATA_SECTIONS
48 #define HYPERVISOR_PERCPU_SECTION
51 #define HYPERVISOR_TEXT \
53 * Align to 4 KB so that \
54 * a) the HYP vector table is at its minimum \
55 * alignment of 2048 bytes \
56 * b) the HYP init code will not cross a page \
57 * boundary if its size does not exceed \
58 * 4 KB (see related ASSERT() below) \
61 __hyp_idmap_text_start = .; \
63 __hyp_idmap_text_end = .; \
64 __hyp_text_start = .; \
71 __idmap_text_start = .; \
75 #ifdef CONFIG_HIBERNATION
76 #define HIBERNATE_TEXT \
78 __hibernate_exit_text_start = .; \
79 *(.hibernate_exit.text) \
80 __hibernate_exit_text_end = .;
82 #define HIBERNATE_TEXT
85 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
87 . = ALIGN(PAGE_SIZE); \
88 __entry_tramp_text_start = .; \
89 *(.entry.tramp.text) \
90 . = ALIGN(PAGE_SIZE); \
91 __entry_tramp_text_end = .;
97 * The size of the PE/COFF section that covers the kernel image, which
98 * runs from _stext to _edata, must be a round multiple of the PE/COFF
99 * FileAlignment, which we set to its minimum value of 0x200. '_stext'
100 * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
101 * boundary should be sufficient.
103 PECOFF_FILE_ALIGNMENT = 0x200;
106 #define PECOFF_EDATA_PADDING \
107 .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
109 #define PECOFF_EDATA_PADDING
115 * XXX: The linker does not define how output sections are
116 * assigned to input sections when there are multiple statements
117 * matching the same input section name. There is no documented
123 *(.dynsym .dynstr .hash .gnu.hash)
132 .text : ALIGN(SEGMENT_ALIGN) { /* Real text segment */
133 _stext = .; /* Text and read-only data */
149 *(.got) /* Global offset table */
153 * Make sure that the .got.plt is either completely empty or it
154 * contains only the lazy dispatch entries.
156 .got.plt : { *(.got.plt) }
157 ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18,
158 "Unexpected GOT/PLT entries detected!")
160 . = ALIGN(SEGMENT_ALIGN);
161 _etext = .; /* End of text section */
163 /* everything from this point to __init_begin will be marked RO NX */
170 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
181 . = ALIGN(SEGMENT_ALIGN);
183 __inittext_begin = .;
187 __exittext_begin = .;
195 __alt_instructions = .;
197 __alt_instructions_end = .;
200 . = ALIGN(SEGMENT_ALIGN);
202 __initdata_begin = .;
210 *(.init.altinstructions .init.bss) /* from the EFI stub */
216 PERCPU_SECTION(L1_CACHE_BYTES)
217 HYPERVISOR_PERCPU_SECTION
219 .rela.dyn : ALIGN(8) {
223 __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR);
224 __rela_size = SIZEOF(.rela.dyn);
227 .relr.dyn : ALIGN(8) {
231 __relr_offset = ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR);
232 __relr_size = SIZEOF(.relr.dyn);
235 . = ALIGN(SEGMENT_ALIGN);
241 RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
243 HYPERVISOR_DATA_SECTIONS
246 * Data written with the MMU off but read with the MMU on requires
247 * cache lines to be invalidated, discarding up to a Cache Writeback
248 * Granule (CWG) of data from the cache. Keep the section that
249 * requires this type of maintenance to be in its own Cache Writeback
250 * Granule (CWG) area so the cache maintenance operations don't
251 * interfere with adjacent data.
253 .mmuoff.data.write : ALIGN(SZ_2K) {
254 __mmuoff_data_start = .;
255 *(.mmuoff.data.write)
258 .mmuoff.data.read : {
260 __mmuoff_data_end = .;
264 __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
269 . = ALIGN(PAGE_SIZE);
274 . = ALIGN(SEGMENT_ALIGN);
275 __pecoff_data_size = ABSOLUTE(. - __initdata_begin);
285 * Sections that should stay zero sized, which is safer to
286 * explicitly check instead of blindly discarding.
289 *(.plt) *(.plt.*) *(.iplt) *(.igot .igot.plt)
291 ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!")
293 .data.rel.ro : { *(.data.rel.ro) }
294 ASSERT(SIZEOF(.data.rel.ro) == 0, "Unexpected RELRO detected!")
297 #include "image-vars.h"
300 * The HYP init code and ID map text can't be longer than a page each,
301 * and should not cross a page boundary.
303 ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
304 "HYP init code too big or misaligned")
305 ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
306 "ID map text too big or misaligned")
307 #ifdef CONFIG_HIBERNATION
308 ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
309 <= SZ_4K, "Hibernate exit text too big or misaligned")
311 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
312 ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE,
313 "Entry trampoline text too big")
316 * If padding is applied before .head.text, virt<->phys conversions will fail.
318 ASSERT(_text == KIMAGE_VADDR, "HEAD is misaligned")