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/thread_info.h>
14 #include <asm/memory.h>
16 #include <asm/pgtable.h>
20 /* .exit.text needed in case of alternative patching */
21 #define ARM_EXIT_KEEP(x) x
22 #define ARM_EXIT_DISCARD(x)
29 #define HYPERVISOR_TEXT \
31 * Align to 4 KB so that \
32 * a) the HYP vector table is at its minimum \
33 * alignment of 2048 bytes \
34 * b) the HYP init code will not cross a page \
35 * boundary if its size does not exceed \
36 * 4 KB (see related ASSERT() below) \
39 __hyp_idmap_text_start = .; \
41 __hyp_idmap_text_end = .; \
42 __hyp_text_start = .; \
48 __idmap_text_start = .; \
52 #ifdef CONFIG_HIBERNATION
53 #define HIBERNATE_TEXT \
55 __hibernate_exit_text_start = .; \
56 *(.hibernate_exit.text) \
57 __hibernate_exit_text_end = .;
59 #define HIBERNATE_TEXT
62 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
64 . = ALIGN(PAGE_SIZE); \
65 __entry_tramp_text_start = .; \
66 *(.entry.tramp.text) \
67 . = ALIGN(PAGE_SIZE); \
68 __entry_tramp_text_end = .;
74 * The size of the PE/COFF section that covers the kernel image, which
75 * runs from stext to _edata, must be a round multiple of the PE/COFF
76 * FileAlignment, which we set to its minimum value of 0x200. 'stext'
77 * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
78 * boundary should be sufficient.
80 PECOFF_FILE_ALIGNMENT = 0x200;
83 #define PECOFF_EDATA_PADDING \
84 .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
86 #define PECOFF_EDATA_PADDING
92 * XXX: The linker does not define how output sections are
93 * assigned to input sections when there are multiple statements
94 * matching the same input section name. There is no documented
98 ARM_EXIT_DISCARD(EXIT_TEXT)
99 ARM_EXIT_DISCARD(EXIT_DATA)
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 */
143 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
148 #ifdef CONFIG_ARM64_SW_TTBR0_PAN
150 . += RESERVED_TTBR0_SIZE;
156 . = ALIGN(SEGMENT_ALIGN);
158 __inittext_begin = .;
162 __exittext_begin = .;
164 ARM_EXIT_KEEP(EXIT_TEXT)
170 __alt_instructions = .;
172 __alt_instructions_end = .;
174 .altinstr_replacement : {
175 *(.altinstr_replacement)
178 . = ALIGN(PAGE_SIZE);
180 __initdata_begin = .;
188 *(.init.rodata.* .init.bss) /* from the EFI stub */
191 ARM_EXIT_KEEP(EXIT_DATA)
194 PERCPU_SECTION(L1_CACHE_BYTES)
196 .rela.dyn : ALIGN(8) {
200 __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR);
201 __rela_size = SIZEOF(.rela.dyn);
204 .relr.dyn : ALIGN(8) {
208 __relr_offset = ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR);
209 __relr_size = SIZEOF(.relr.dyn);
212 . = ALIGN(SEGMENT_ALIGN);
218 RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
221 * Data written with the MMU off but read with the MMU on requires
222 * cache lines to be invalidated, discarding up to a Cache Writeback
223 * Granule (CWG) of data from the cache. Keep the section that
224 * requires this type of maintenance to be in its own Cache Writeback
225 * Granule (CWG) area so the cache maintenance operations don't
226 * interfere with adjacent data.
228 .mmuoff.data.write : ALIGN(SZ_2K) {
229 __mmuoff_data_start = .;
230 *(.mmuoff.data.write)
233 .mmuoff.data.read : {
235 __mmuoff_data_end = .;
239 __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
244 . = ALIGN(PAGE_SIZE);
249 __pecoff_data_size = ABSOLUTE(. - __initdata_begin);
257 #include "image-vars.h"
260 * The HYP init code and ID map text can't be longer than a page each,
261 * and should not cross a page boundary.
263 ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
264 "HYP init code too big or misaligned")
265 ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
266 "ID map text too big or misaligned")
267 #ifdef CONFIG_HIBERNATION
268 ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
269 <= SZ_4K, "Hibernate exit text too big or misaligned")
271 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
272 ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE,
273 "Entry trampoline text too big")
276 * If padding is applied before .head.text, virt<->phys conversions will fail.
278 ASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned")