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/kernel-pgtable.h>
13 #include <asm/memory.h>
24 #define HYPERVISOR_EXTABLE \
26 __start___kvm_ex_table = .; \
28 __stop___kvm_ex_table = .;
30 #define HYPERVISOR_TEXT \
32 * Align to 4 KB so that \
33 * a) the HYP vector table is at its minimum \
34 * alignment of 2048 bytes \
35 * b) the HYP init code will not cross a page \
36 * boundary if its size does not exceed \
37 * 4 KB (see related ASSERT() below) \
40 __hyp_idmap_text_start = .; \
42 __hyp_idmap_text_end = .; \
43 __hyp_text_start = .; \
50 __idmap_text_start = .; \
54 #ifdef CONFIG_HIBERNATION
55 #define HIBERNATE_TEXT \
57 __hibernate_exit_text_start = .; \
58 *(.hibernate_exit.text) \
59 __hibernate_exit_text_end = .;
61 #define HIBERNATE_TEXT
64 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
66 . = ALIGN(PAGE_SIZE); \
67 __entry_tramp_text_start = .; \
68 *(.entry.tramp.text) \
69 . = ALIGN(PAGE_SIZE); \
70 __entry_tramp_text_end = .;
76 * The size of the PE/COFF section that covers the kernel image, which
77 * runs from _stext to _edata, must be a round multiple of the PE/COFF
78 * FileAlignment, which we set to its minimum value of 0x200. '_stext'
79 * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
80 * boundary should be sufficient.
82 PECOFF_FILE_ALIGNMENT = 0x200;
85 #define PECOFF_EDATA_PADDING \
86 .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
88 #define PECOFF_EDATA_PADDING
94 * XXX: The linker does not define how output sections are
95 * assigned to input sections when there are multiple statements
96 * matching the same input section name. There is no documented
104 *(.dynsym .dynstr .hash .gnu.hash)
108 . = KIMAGE_VADDR + TEXT_OFFSET;
114 .text : { /* Real text segment */
115 _stext = .; /* Text and read-only data */
131 *(.got) /* Global offset table */
134 . = ALIGN(SEGMENT_ALIGN);
135 _etext = .; /* End of text section */
137 /* everything from this point to __init_begin will be marked RO NX */
144 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
149 #ifdef CONFIG_ARM64_SW_TTBR0_PAN
151 . += RESERVED_TTBR0_SIZE;
157 . = ALIGN(SEGMENT_ALIGN);
159 __inittext_begin = .;
163 __exittext_begin = .;
171 __alt_instructions = .;
173 __alt_instructions_end = .;
176 . = ALIGN(SEGMENT_ALIGN);
178 __initdata_begin = .;
186 *(.init.rodata.* .init.bss) /* from the EFI stub */
192 PERCPU_SECTION(L1_CACHE_BYTES)
194 .rela.dyn : ALIGN(8) {
198 __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR);
199 __rela_size = SIZEOF(.rela.dyn);
202 .relr.dyn : ALIGN(8) {
206 __relr_offset = ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR);
207 __relr_size = SIZEOF(.relr.dyn);
210 . = ALIGN(SEGMENT_ALIGN);
216 RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
219 * Data written with the MMU off but read with the MMU on requires
220 * cache lines to be invalidated, discarding up to a Cache Writeback
221 * Granule (CWG) of data from the cache. Keep the section that
222 * requires this type of maintenance to be in its own Cache Writeback
223 * Granule (CWG) area so the cache maintenance operations don't
224 * interfere with adjacent data.
226 .mmuoff.data.write : ALIGN(SZ_2K) {
227 __mmuoff_data_start = .;
228 *(.mmuoff.data.write)
231 .mmuoff.data.read : {
233 __mmuoff_data_end = .;
237 __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
242 . = ALIGN(PAGE_SIZE);
247 . = ALIGN(SEGMENT_ALIGN);
248 __pecoff_data_size = ABSOLUTE(. - __initdata_begin);
256 #include "image-vars.h"
259 * The HYP init code and ID map text can't be longer than a page each,
260 * and should not cross a page boundary.
262 ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
263 "HYP init code too big or misaligned")
264 ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
265 "ID map text too big or misaligned")
266 #ifdef CONFIG_HIBERNATION
267 ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
268 <= SZ_4K, "Hibernate exit text too big or misaligned")
270 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
271 ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE,
272 "Entry trampoline text too big")
275 * If padding is applied before .head.text, virt<->phys conversions will fail.
277 ASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned")