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_PERCPU_SECTION \
34 . = ALIGN(PAGE_SIZE); \
35 HYP_SECTION_NAME(.data..percpu) : { \
36 *(HYP_SECTION_NAME(.data..percpu)) \
38 #else /* CONFIG_KVM */
39 #define HYPERVISOR_EXTABLE
40 #define HYPERVISOR_PERCPU_SECTION
43 #define HYPERVISOR_TEXT \
45 * Align to 4 KB so that \
46 * a) the HYP vector table is at its minimum \
47 * alignment of 2048 bytes \
48 * b) the HYP init code will not cross a page \
49 * boundary if its size does not exceed \
50 * 4 KB (see related ASSERT() below) \
53 __hyp_idmap_text_start = .; \
55 __hyp_idmap_text_end = .; \
56 __hyp_text_start = .; \
63 __idmap_text_start = .; \
67 #ifdef CONFIG_HIBERNATION
68 #define HIBERNATE_TEXT \
70 __hibernate_exit_text_start = .; \
71 *(.hibernate_exit.text) \
72 __hibernate_exit_text_end = .;
74 #define HIBERNATE_TEXT
77 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
79 . = ALIGN(PAGE_SIZE); \
80 __entry_tramp_text_start = .; \
81 *(.entry.tramp.text) \
82 . = ALIGN(PAGE_SIZE); \
83 __entry_tramp_text_end = .;
89 * The size of the PE/COFF section that covers the kernel image, which
90 * runs from _stext to _edata, must be a round multiple of the PE/COFF
91 * FileAlignment, which we set to its minimum value of 0x200. '_stext'
92 * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
93 * boundary should be sufficient.
95 PECOFF_FILE_ALIGNMENT = 0x200;
98 #define PECOFF_EDATA_PADDING \
99 .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
101 #define PECOFF_EDATA_PADDING
107 * XXX: The linker does not define how output sections are
108 * assigned to input sections when there are multiple statements
109 * matching the same input section name. There is no documented
115 *(.dynsym .dynstr .hash .gnu.hash)
124 .text : { /* Real text segment */
125 _stext = .; /* Text and read-only data */
141 *(.got) /* Global offset table */
145 * Make sure that the .got.plt is either completely empty or it
146 * contains only the lazy dispatch entries.
148 .got.plt : { *(.got.plt) }
149 ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18,
150 "Unexpected GOT/PLT entries detected!")
152 . = ALIGN(SEGMENT_ALIGN);
153 _etext = .; /* End of text section */
155 /* everything from this point to __init_begin will be marked RO NX */
162 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
167 #ifdef CONFIG_ARM64_SW_TTBR0_PAN
169 . += RESERVED_TTBR0_SIZE;
175 . = ALIGN(SEGMENT_ALIGN);
177 __inittext_begin = .;
181 __exittext_begin = .;
189 __alt_instructions = .;
191 __alt_instructions_end = .;
194 . = ALIGN(SEGMENT_ALIGN);
196 __initdata_begin = .;
204 *(.init.rodata.* .init.bss) /* from the EFI stub */
210 PERCPU_SECTION(L1_CACHE_BYTES)
211 HYPERVISOR_PERCPU_SECTION
213 .rela.dyn : ALIGN(8) {
217 __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR);
218 __rela_size = SIZEOF(.rela.dyn);
221 .relr.dyn : ALIGN(8) {
225 __relr_offset = ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR);
226 __relr_size = SIZEOF(.relr.dyn);
229 . = ALIGN(SEGMENT_ALIGN);
235 RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
238 * Data written with the MMU off but read with the MMU on requires
239 * cache lines to be invalidated, discarding up to a Cache Writeback
240 * Granule (CWG) of data from the cache. Keep the section that
241 * requires this type of maintenance to be in its own Cache Writeback
242 * Granule (CWG) area so the cache maintenance operations don't
243 * interfere with adjacent data.
245 .mmuoff.data.write : ALIGN(SZ_2K) {
246 __mmuoff_data_start = .;
247 *(.mmuoff.data.write)
250 .mmuoff.data.read : {
252 __mmuoff_data_end = .;
256 __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
261 . = ALIGN(PAGE_SIZE);
266 . = ALIGN(SEGMENT_ALIGN);
267 __pecoff_data_size = ABSOLUTE(. - __initdata_begin);
277 * Sections that should stay zero sized, which is safer to
278 * explicitly check instead of blindly discarding.
281 *(.plt) *(.plt.*) *(.iplt) *(.igot .igot.plt)
283 ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!")
285 .data.rel.ro : { *(.data.rel.ro) }
286 ASSERT(SIZEOF(.data.rel.ro) == 0, "Unexpected RELRO detected!")
289 #include "image-vars.h"
292 * The HYP init code and ID map text can't be longer than a page each,
293 * and should not cross a page boundary.
295 ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
296 "HYP init code too big or misaligned")
297 ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
298 "ID map text too big or misaligned")
299 #ifdef CONFIG_HIBERNATION
300 ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
301 <= SZ_4K, "Hibernate exit text too big or misaligned")
303 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
304 ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE,
305 "Entry trampoline text too big")
308 * If padding is applied before .head.text, virt<->phys conversions will fail.
310 ASSERT(_text == KIMAGE_VADDR, "HEAD is misaligned")