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>
24 #define HYPERVISOR_TEXT \
26 * Align to 4 KB so that \
27 * a) the HYP vector table is at its minimum \
28 * alignment of 2048 bytes \
29 * b) the HYP init code will not cross a page \
30 * boundary if its size does not exceed \
31 * 4 KB (see related ASSERT() below) \
34 __hyp_idmap_text_start = .; \
36 __hyp_idmap_text_end = .; \
37 __hyp_text_start = .; \
43 __idmap_text_start = .; \
47 #ifdef CONFIG_HIBERNATION
48 #define HIBERNATE_TEXT \
50 __hibernate_exit_text_start = .; \
51 *(.hibernate_exit.text) \
52 __hibernate_exit_text_end = .;
54 #define HIBERNATE_TEXT
57 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
59 . = ALIGN(PAGE_SIZE); \
60 __entry_tramp_text_start = .; \
61 *(.entry.tramp.text) \
62 . = ALIGN(PAGE_SIZE); \
63 __entry_tramp_text_end = .;
69 * The size of the PE/COFF section that covers the kernel image, which
70 * runs from _stext to _edata, must be a round multiple of the PE/COFF
71 * FileAlignment, which we set to its minimum value of 0x200. '_stext'
72 * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
73 * boundary should be sufficient.
75 PECOFF_FILE_ALIGNMENT = 0x200;
78 #define PECOFF_EDATA_PADDING \
79 .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
81 #define PECOFF_EDATA_PADDING
87 * XXX: The linker does not define how output sections are
88 * assigned to input sections when there are multiple statements
89 * matching the same input section name. There is no documented
97 *(.dynsym .dynstr .hash .gnu.hash)
101 . = KIMAGE_VADDR + TEXT_OFFSET;
107 .text : { /* Real text segment */
108 _stext = .; /* Text and read-only data */
124 *(.got) /* Global offset table */
127 . = ALIGN(SEGMENT_ALIGN);
128 _etext = .; /* End of text section */
130 /* everything from this point to __init_begin will be marked RO NX */
137 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
142 #ifdef CONFIG_ARM64_SW_TTBR0_PAN
144 . += RESERVED_TTBR0_SIZE;
150 . = ALIGN(SEGMENT_ALIGN);
152 __inittext_begin = .;
156 __exittext_begin = .;
164 __alt_instructions = .;
166 __alt_instructions_end = .;
168 .altinstr_replacement : {
169 *(.altinstr_replacement)
172 . = ALIGN(SEGMENT_ALIGN);
174 __initdata_begin = .;
182 *(.init.rodata.* .init.bss) /* from the EFI stub */
188 PERCPU_SECTION(L1_CACHE_BYTES)
190 .rela.dyn : ALIGN(8) {
194 __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR);
195 __rela_size = SIZEOF(.rela.dyn);
198 .relr.dyn : ALIGN(8) {
202 __relr_offset = ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR);
203 __relr_size = SIZEOF(.relr.dyn);
206 . = ALIGN(SEGMENT_ALIGN);
212 RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
215 * Data written with the MMU off but read with the MMU on requires
216 * cache lines to be invalidated, discarding up to a Cache Writeback
217 * Granule (CWG) of data from the cache. Keep the section that
218 * requires this type of maintenance to be in its own Cache Writeback
219 * Granule (CWG) area so the cache maintenance operations don't
220 * interfere with adjacent data.
222 .mmuoff.data.write : ALIGN(SZ_2K) {
223 __mmuoff_data_start = .;
224 *(.mmuoff.data.write)
227 .mmuoff.data.read : {
229 __mmuoff_data_end = .;
233 __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
238 . = ALIGN(PAGE_SIZE);
243 . = ALIGN(SEGMENT_ALIGN);
244 __pecoff_data_size = ABSOLUTE(. - __initdata_begin);
252 #include "image-vars.h"
255 * The HYP init code and ID map text can't be longer than a page each,
256 * and should not cross a page boundary.
258 ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
259 "HYP init code too big or misaligned")
260 ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
261 "ID map text too big or misaligned")
262 #ifdef CONFIG_HIBERNATION
263 ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
264 <= SZ_4K, "Hibernate exit text too big or misaligned")
266 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
267 ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE,
268 "Entry trampoline text too big")
271 * If padding is applied before .head.text, virt<->phys conversions will fail.
273 ASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned")