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
10 #include <asm-generic/vmlinux.lds.h>
11 #include <asm/cache.h>
12 #include <asm/hyp_image.h>
13 #include <asm/kernel-pgtable.h>
14 #include <asm/memory.h>
26 #define HYPERVISOR_EXTABLE \
28 __start___kvm_ex_table = .; \
30 __stop___kvm_ex_table = .;
32 #define HYPERVISOR_PERCPU_SECTION \
33 . = ALIGN(PAGE_SIZE); \
34 HYP_SECTION_NAME(.data..percpu) : { \
35 *(HYP_SECTION_NAME(.data..percpu)) \
37 #else /* CONFIG_KVM */
38 #define HYPERVISOR_EXTABLE
39 #define HYPERVISOR_PERCPU_SECTION
42 #define HYPERVISOR_TEXT \
44 * Align to 4 KB so that \
45 * a) the HYP vector table is at its minimum \
46 * alignment of 2048 bytes \
47 * b) the HYP init code will not cross a page \
48 * boundary if its size does not exceed \
49 * 4 KB (see related ASSERT() below) \
52 __hyp_idmap_text_start = .; \
54 __hyp_idmap_text_end = .; \
55 __hyp_text_start = .; \
62 __idmap_text_start = .; \
66 #ifdef CONFIG_HIBERNATION
67 #define HIBERNATE_TEXT \
69 __hibernate_exit_text_start = .; \
70 *(.hibernate_exit.text) \
71 __hibernate_exit_text_end = .;
73 #define HIBERNATE_TEXT
76 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
78 . = ALIGN(PAGE_SIZE); \
79 __entry_tramp_text_start = .; \
80 *(.entry.tramp.text) \
81 . = ALIGN(PAGE_SIZE); \
82 __entry_tramp_text_end = .;
88 * The size of the PE/COFF section that covers the kernel image, which
89 * runs from _stext to _edata, must be a round multiple of the PE/COFF
90 * FileAlignment, which we set to its minimum value of 0x200. '_stext'
91 * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
92 * boundary should be sufficient.
94 PECOFF_FILE_ALIGNMENT = 0x200;
97 #define PECOFF_EDATA_PADDING \
98 .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
100 #define PECOFF_EDATA_PADDING
106 * XXX: The linker does not define how output sections are
107 * assigned to input sections when there are multiple statements
108 * matching the same input section name. There is no documented
116 *(.dynsym .dynstr .hash .gnu.hash)
120 . = KIMAGE_VADDR + TEXT_OFFSET;
126 .text : { /* Real text segment */
127 _stext = .; /* Text and read-only data */
143 *(.got) /* Global offset table */
146 . = ALIGN(SEGMENT_ALIGN);
147 _etext = .; /* End of text section */
149 /* everything from this point to __init_begin will be marked RO NX */
156 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
161 #ifdef CONFIG_ARM64_SW_TTBR0_PAN
163 . += RESERVED_TTBR0_SIZE;
169 . = ALIGN(SEGMENT_ALIGN);
171 __inittext_begin = .;
175 __exittext_begin = .;
183 __alt_instructions = .;
185 __alt_instructions_end = .;
188 . = ALIGN(SEGMENT_ALIGN);
190 __initdata_begin = .;
198 *(.init.rodata.* .init.bss) /* from the EFI stub */
204 PERCPU_SECTION(L1_CACHE_BYTES)
205 HYPERVISOR_PERCPU_SECTION
207 .rela.dyn : ALIGN(8) {
211 __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR);
212 __rela_size = SIZEOF(.rela.dyn);
215 .relr.dyn : ALIGN(8) {
219 __relr_offset = ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR);
220 __relr_size = SIZEOF(.relr.dyn);
223 . = ALIGN(SEGMENT_ALIGN);
229 RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
232 * Data written with the MMU off but read with the MMU on requires
233 * cache lines to be invalidated, discarding up to a Cache Writeback
234 * Granule (CWG) of data from the cache. Keep the section that
235 * requires this type of maintenance to be in its own Cache Writeback
236 * Granule (CWG) area so the cache maintenance operations don't
237 * interfere with adjacent data.
239 .mmuoff.data.write : ALIGN(SZ_2K) {
240 __mmuoff_data_start = .;
241 *(.mmuoff.data.write)
244 .mmuoff.data.read : {
246 __mmuoff_data_end = .;
250 __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
255 . = ALIGN(PAGE_SIZE);
260 . = ALIGN(SEGMENT_ALIGN);
261 __pecoff_data_size = ABSOLUTE(. - __initdata_begin);
269 #include "image-vars.h"
272 * The HYP init code and ID map text can't be longer than a page each,
273 * and should not cross a page boundary.
275 ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
276 "HYP init code too big or misaligned")
277 ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
278 "ID map text too big or misaligned")
279 #ifdef CONFIG_HIBERNATION
280 ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
281 <= SZ_4K, "Hibernate exit text too big or misaligned")
283 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
284 ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE,
285 "Entry trampoline text too big")
288 * If padding is applied before .head.text, virt<->phys conversions will fail.
290 ASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned")