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 #include <asm-generic/vmlinux.lds.h>
10 #include <asm/kernel-pgtable.h>
11 #include <asm/thread_info.h>
12 #include <asm/memory.h>
14 #include <asm/pgtable.h>
18 /* .exit.text needed in case of alternative patching */
19 #define ARM_EXIT_KEEP(x) x
20 #define ARM_EXIT_DISCARD(x)
27 #define HYPERVISOR_TEXT \
29 * Align to 4 KB so that \
30 * a) the HYP vector table is at its minimum \
31 * alignment of 2048 bytes \
32 * b) the HYP init code will not cross a page \
33 * boundary if its size does not exceed \
34 * 4 KB (see related ASSERT() below) \
37 VMLINUX_SYMBOL(__hyp_idmap_text_start) = .; \
39 VMLINUX_SYMBOL(__hyp_idmap_text_end) = .; \
40 VMLINUX_SYMBOL(__hyp_text_start) = .; \
42 VMLINUX_SYMBOL(__hyp_text_end) = .;
46 VMLINUX_SYMBOL(__idmap_text_start) = .; \
48 VMLINUX_SYMBOL(__idmap_text_end) = .;
50 #ifdef CONFIG_HIBERNATION
51 #define HIBERNATE_TEXT \
53 VMLINUX_SYMBOL(__hibernate_exit_text_start) = .;\
54 *(.hibernate_exit.text) \
55 VMLINUX_SYMBOL(__hibernate_exit_text_end) = .;
57 #define HIBERNATE_TEXT
61 * The size of the PE/COFF section that covers the kernel image, which
62 * runs from stext to _edata, must be a round multiple of the PE/COFF
63 * FileAlignment, which we set to its minimum value of 0x200. 'stext'
64 * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
65 * boundary should be sufficient.
67 PECOFF_FILE_ALIGNMENT = 0x200;
70 #define PECOFF_EDATA_PADDING \
71 .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
73 #define PECOFF_EDATA_PADDING
79 * XXX: The linker does not define how output sections are
80 * assigned to input sections when there are multiple statements
81 * matching the same input section name. There is no documented
85 ARM_EXIT_DISCARD(EXIT_TEXT)
86 ARM_EXIT_DISCARD(EXIT_DATA)
91 *(.dynsym .dynstr .hash)
94 . = KIMAGE_VADDR + TEXT_OFFSET;
100 .text : { /* Real text segment */
101 _stext = .; /* Text and read-only data */
102 __exception_text_start = .;
104 __exception_text_end = .;
119 *(.got) /* Global offset table */
122 . = ALIGN(SEGMENT_ALIGN);
123 _etext = .; /* End of text section */
125 RO_DATA(PAGE_SIZE) /* everything from this point to */
126 EXCEPTION_TABLE(8) /* __init_begin will be marked RO NX */
129 . = ALIGN(SEGMENT_ALIGN);
131 __inittext_begin = .;
135 ARM_EXIT_KEEP(EXIT_TEXT)
140 __alt_instructions = .;
142 __alt_instructions_end = .;
144 .altinstr_replacement : {
145 *(.altinstr_replacement)
148 . = ALIGN(PAGE_SIZE);
150 __initdata_begin = .;
159 *(.init.rodata.* .init.bss) /* from the EFI stub */
162 ARM_EXIT_KEEP(EXIT_DATA)
165 PERCPU_SECTION(L1_CACHE_BYTES)
171 __rela_offset = ABSOLUTE(ADDR(.rela) - KIMAGE_VADDR);
172 __rela_size = SIZEOF(.rela);
174 . = ALIGN(SEGMENT_ALIGN);
180 RW_DATA_SECTION(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
183 * Data written with the MMU off but read with the MMU on requires
184 * cache lines to be invalidated, discarding up to a Cache Writeback
185 * Granule (CWG) of data from the cache. Keep the section that
186 * requires this type of maintenance to be in its own Cache Writeback
187 * Granule (CWG) area so the cache maintenance operations don't
188 * interfere with adjacent data.
190 .mmuoff.data.write : ALIGN(SZ_2K) {
191 __mmuoff_data_start = .;
192 *(.mmuoff.data.write)
195 .mmuoff.data.read : {
197 __mmuoff_data_end = .;
201 __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
206 . = ALIGN(PAGE_SIZE);
210 . += SWAPPER_DIR_SIZE;
212 #ifdef CONFIG_ARM64_SW_TTBR0_PAN
214 . += RESERVED_TTBR0_SIZE;
217 __pecoff_data_size = ABSOLUTE(. - __initdata_begin);
226 * The HYP init code and ID map text can't be longer than a page each,
227 * and should not cross a page boundary.
229 ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
230 "HYP init code too big or misaligned")
231 ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
232 "ID map text too big or misaligned")
233 #ifdef CONFIG_HIBERNATION
234 ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
235 <= SZ_4K, "Hibernate exit text too big or misaligned")
239 * If padding is applied before .head.text, virt<->phys conversions will fail.
241 ASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned")