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>
23 #define HYPERVISOR_TEXT \
25 * Align to 4 KB so that \
26 * a) the HYP vector table is at its minimum \
27 * alignment of 2048 bytes \
28 * b) the HYP init code will not cross a page \
29 * boundary if its size does not exceed \
30 * 4 KB (see related ASSERT() below) \
33 __hyp_idmap_text_start = .; \
35 __hyp_idmap_text_end = .; \
36 __hyp_text_start = .; \
42 __idmap_text_start = .; \
46 #ifdef CONFIG_HIBERNATION
47 #define HIBERNATE_TEXT \
49 __hibernate_exit_text_start = .; \
50 *(.hibernate_exit.text) \
51 __hibernate_exit_text_end = .;
53 #define HIBERNATE_TEXT
56 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
58 . = ALIGN(PAGE_SIZE); \
59 __entry_tramp_text_start = .; \
60 *(.entry.tramp.text) \
61 . = ALIGN(PAGE_SIZE); \
62 __entry_tramp_text_end = .;
68 * The size of the PE/COFF section that covers the kernel image, which
69 * runs from _stext to _edata, must be a round multiple of the PE/COFF
70 * FileAlignment, which we set to its minimum value of 0x200. '_stext'
71 * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
72 * boundary should be sufficient.
74 PECOFF_FILE_ALIGNMENT = 0x200;
77 #define PECOFF_EDATA_PADDING \
78 .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
80 #define PECOFF_EDATA_PADDING
86 * XXX: The linker does not define how output sections are
87 * assigned to input sections when there are multiple statements
88 * matching the same input section name. There is no documented
96 *(.dynsym .dynstr .hash .gnu.hash)
100 . = KIMAGE_VADDR + TEXT_OFFSET;
106 .text : { /* Real text segment */
107 _stext = .; /* Text and read-only data */
123 *(.got) /* Global offset table */
126 . = ALIGN(SEGMENT_ALIGN);
127 _etext = .; /* End of text section */
129 /* everything from this point to __init_begin will be marked RO NX */
136 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
141 #ifdef CONFIG_ARM64_SW_TTBR0_PAN
143 . += RESERVED_TTBR0_SIZE;
149 . = ALIGN(SEGMENT_ALIGN);
151 __inittext_begin = .;
155 __exittext_begin = .;
163 __alt_instructions = .;
165 __alt_instructions_end = .;
168 . = ALIGN(SEGMENT_ALIGN);
170 __initdata_begin = .;
178 *(.init.rodata.* .init.bss) /* from the EFI stub */
184 PERCPU_SECTION(L1_CACHE_BYTES)
186 .rela.dyn : ALIGN(8) {
190 __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR);
191 __rela_size = SIZEOF(.rela.dyn);
194 .relr.dyn : ALIGN(8) {
198 __relr_offset = ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR);
199 __relr_size = SIZEOF(.relr.dyn);
202 . = ALIGN(SEGMENT_ALIGN);
208 RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
211 * Data written with the MMU off but read with the MMU on requires
212 * cache lines to be invalidated, discarding up to a Cache Writeback
213 * Granule (CWG) of data from the cache. Keep the section that
214 * requires this type of maintenance to be in its own Cache Writeback
215 * Granule (CWG) area so the cache maintenance operations don't
216 * interfere with adjacent data.
218 .mmuoff.data.write : ALIGN(SZ_2K) {
219 __mmuoff_data_start = .;
220 *(.mmuoff.data.write)
223 .mmuoff.data.read : {
225 __mmuoff_data_end = .;
229 __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
234 . = ALIGN(PAGE_SIZE);
239 . = ALIGN(SEGMENT_ALIGN);
240 __pecoff_data_size = ABSOLUTE(. - __initdata_begin);
248 #include "image-vars.h"
251 * The HYP init code and ID map text can't be longer than a page each,
252 * and should not cross a page boundary.
254 ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
255 "HYP init code too big or misaligned")
256 ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
257 "ID map text too big or misaligned")
258 #ifdef CONFIG_HIBERNATION
259 ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
260 <= SZ_4K, "Hibernate exit text too big or misaligned")
262 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
263 ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE,
264 "Entry trampoline text too big")
267 * If padding is applied before .head.text, virt<->phys conversions will fail.
269 ASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned")