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/kernel-pgtable.h>
14 #include <asm/memory.h>
25 #define HYPERVISOR_EXTABLE \
27 __start___kvm_ex_table = .; \
29 __stop___kvm_ex_table = .;
31 #define HYPERVISOR_TEXT \
33 * Align to 4 KB so that \
34 * a) the HYP vector table is at its minimum \
35 * alignment of 2048 bytes \
36 * b) the HYP init code will not cross a page \
37 * boundary if its size does not exceed \
38 * 4 KB (see related ASSERT() below) \
41 __hyp_idmap_text_start = .; \
43 __hyp_idmap_text_end = .; \
44 __hyp_text_start = .; \
51 __idmap_text_start = .; \
55 #ifdef CONFIG_HIBERNATION
56 #define HIBERNATE_TEXT \
58 __hibernate_exit_text_start = .; \
59 *(.hibernate_exit.text) \
60 __hibernate_exit_text_end = .;
62 #define HIBERNATE_TEXT
65 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
67 . = ALIGN(PAGE_SIZE); \
68 __entry_tramp_text_start = .; \
69 *(.entry.tramp.text) \
70 . = ALIGN(PAGE_SIZE); \
71 __entry_tramp_text_end = .;
77 * The size of the PE/COFF section that covers the kernel image, which
78 * runs from _stext to _edata, must be a round multiple of the PE/COFF
79 * FileAlignment, which we set to its minimum value of 0x200. '_stext'
80 * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
81 * boundary should be sufficient.
83 PECOFF_FILE_ALIGNMENT = 0x200;
86 #define PECOFF_EDATA_PADDING \
87 .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
89 #define PECOFF_EDATA_PADDING
95 * XXX: The linker does not define how output sections are
96 * assigned to input sections when there are multiple statements
97 * matching the same input section name. There is no documented
103 *(.dynsym .dynstr .hash .gnu.hash)
112 .text : { /* Real text segment */
113 _stext = .; /* Text and read-only data */
129 *(.got) /* Global offset table */
133 * Make sure that the .got.plt is either completely empty or it
134 * contains only the lazy dispatch entries.
136 .got.plt : { *(.got.plt) }
137 ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18,
138 "Unexpected GOT/PLT entries detected!")
140 . = ALIGN(SEGMENT_ALIGN);
141 _etext = .; /* End of text section */
143 /* everything from this point to __init_begin will be marked RO NX */
150 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
155 #ifdef CONFIG_ARM64_SW_TTBR0_PAN
157 . += RESERVED_TTBR0_SIZE;
163 . = ALIGN(SEGMENT_ALIGN);
165 __inittext_begin = .;
169 __exittext_begin = .;
177 __alt_instructions = .;
179 __alt_instructions_end = .;
182 . = ALIGN(SEGMENT_ALIGN);
184 __initdata_begin = .;
192 *(.init.rodata.* .init.bss) /* from the EFI stub */
198 PERCPU_SECTION(L1_CACHE_BYTES)
200 .rela.dyn : ALIGN(8) {
204 __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR);
205 __rela_size = SIZEOF(.rela.dyn);
208 .relr.dyn : ALIGN(8) {
212 __relr_offset = ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR);
213 __relr_size = SIZEOF(.relr.dyn);
216 . = ALIGN(SEGMENT_ALIGN);
222 RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
225 * Data written with the MMU off but read with the MMU on requires
226 * cache lines to be invalidated, discarding up to a Cache Writeback
227 * Granule (CWG) of data from the cache. Keep the section that
228 * requires this type of maintenance to be in its own Cache Writeback
229 * Granule (CWG) area so the cache maintenance operations don't
230 * interfere with adjacent data.
232 .mmuoff.data.write : ALIGN(SZ_2K) {
233 __mmuoff_data_start = .;
234 *(.mmuoff.data.write)
237 .mmuoff.data.read : {
239 __mmuoff_data_end = .;
243 __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
248 . = ALIGN(PAGE_SIZE);
253 . = ALIGN(SEGMENT_ALIGN);
254 __pecoff_data_size = ABSOLUTE(. - __initdata_begin);
264 * Sections that should stay zero sized, which is safer to
265 * explicitly check instead of blindly discarding.
268 *(.plt) *(.plt.*) *(.iplt) *(.igot)
270 ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!")
272 .data.rel.ro : { *(.data.rel.ro) }
273 ASSERT(SIZEOF(.data.rel.ro) == 0, "Unexpected RELRO detected!")
276 #include "image-vars.h"
279 * The HYP init code and ID map text can't be longer than a page each,
280 * and should not cross a page boundary.
282 ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
283 "HYP init code too big or misaligned")
284 ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
285 "ID map text too big or misaligned")
286 #ifdef CONFIG_HIBERNATION
287 ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
288 <= SZ_4K, "Hibernate exit text too big or misaligned")
290 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
291 ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE,
292 "Entry trampoline text too big")
295 * If padding is applied before .head.text, virt<->phys conversions will fail.
297 ASSERT(_text == KIMAGE_VADDR, "HEAD is misaligned")