1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* ld script to make ARM Linux kernel
3 * taken from the i386 version by Russell King
4 * Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>
7 /* No __ro_after_init data in the .rodata section - which will always be ro */
8 #define RO_AFTER_INIT_DATA
10 #include <linux/sizes.h>
12 #include <asm-generic/vmlinux.lds.h>
13 #include <asm/cache.h>
14 #include <asm/thread_info.h>
15 #include <asm/memory.h>
20 VMLINUX_SYMBOL(__proc_info_begin) = .; \
22 VMLINUX_SYMBOL(__proc_info_end) = .;
26 VMLINUX_SYMBOL(__idmap_text_start) = .; \
28 VMLINUX_SYMBOL(__idmap_text_end) = .; \
29 . = ALIGN(PAGE_SIZE); \
30 VMLINUX_SYMBOL(__hyp_idmap_text_start) = .; \
32 VMLINUX_SYMBOL(__hyp_idmap_text_end) = .;
34 #ifdef CONFIG_HOTPLUG_CPU
35 #define ARM_CPU_DISCARD(x)
36 #define ARM_CPU_KEEP(x) x
38 #define ARM_CPU_DISCARD(x) x
39 #define ARM_CPU_KEEP(x)
42 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
43 defined(CONFIG_GENERIC_BUG)
44 #define ARM_EXIT_KEEP(x) x
45 #define ARM_EXIT_DISCARD(x)
47 #define ARM_EXIT_KEEP(x)
48 #define ARM_EXIT_DISCARD(x) x
57 jiffies = jiffies_64 + 4;
63 * XXX: The linker does not define how output sections are
64 * assigned to input sections when there are multiple statements
65 * matching the same input section name. There is no documented
68 * unwind exit sections must be discarded before the rest of the
69 * unwind sections get included.
72 *(.ARM.exidx.exit.text)
73 *(.ARM.extab.exit.text)
74 ARM_CPU_DISCARD(*(.ARM.exidx.cpuexit.text))
75 ARM_CPU_DISCARD(*(.ARM.extab.cpuexit.text))
76 ARM_EXIT_DISCARD(EXIT_TEXT)
77 ARM_EXIT_DISCARD(EXIT_DATA)
88 . = XIP_VIRT_ADDR(CONFIG_XIP_PHYS_ADDR);
89 _xiprom = .; /* XIP ROM area to be mapped */
96 .text : { /* Real text segment */
97 _stext = .; /* Text and read-only data */
99 __entry_text_start = .;
101 __entry_text_end = .;
112 *(.got) /* Global offset table */
113 ARM_CPU_KEEP(PROC_INFO)
119 __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
120 __start___ex_table = .;
124 __stop___ex_table = .;
127 #ifdef CONFIG_ARM_UNWIND
129 * Stack unwinding tables
133 __start_unwind_idx = .;
135 __stop_unwind_idx = .;
138 __start_unwind_tab = .;
140 __stop_unwind_tab = .;
146 _etext = .; /* End of text and rodata section */
149 * The vectors and stubs are relocatable code, and the
150 * only thing that matters is their relative offsets
153 .vectors 0xffff0000 : AT(__vectors_start) {
156 . = __vectors_start + SIZEOF(.vectors);
160 .stubs ADDR(.vectors) + 0x1000 : AT(__stubs_start) {
163 . = __stubs_start + SIZEOF(.stubs);
166 PROVIDE(vector_fiq_offset = vector_fiq - ADDR(.vectors));
170 ARM_EXIT_KEEP(EXIT_TEXT)
173 ARM_CPU_DISCARD(PROC_INFO)
176 __arch_info_begin = .;
181 __tagtable_begin = .;
193 #ifdef CONFIG_ARM_MPU
196 _exiprom = .; /* End of XIP ROM area */
199 * From this point, stuff is considered writable and will be copied to RAM
201 __data_loc = ALIGN(4); /* location in file */
202 . = PAGE_OFFSET + TEXT_OFFSET; /* location in memory */
204 #define LOAD_OFFSET (PAGE_OFFSET + TEXT_OFFSET - __data_loc)
206 . = ALIGN(THREAD_SIZE);
208 RW_DATA_SECTION(L1_CACHE_BYTES, PAGE_SIZE, THREAD_SIZE)
209 .data.ro_after_init : AT(ADDR(.data.ro_after_init) - LOAD_OFFSET) {
210 *(.data..ro_after_init)
214 . = ALIGN(PAGE_SIZE);
216 .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
219 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
220 ARM_EXIT_KEEP(EXIT_DATA)
223 PERCPU_SECTION(L1_CACHE_BYTES)
227 * End of copied data. We need a dummy section to get its LMA.
228 * Also located before final ALIGN() as trailing padding is not stored
229 * in the resulting binary file and useless to copy.
231 .data.endmark : AT(ADDR(.data.endmark) - LOAD_OFFSET) { }
232 _edata_loc = LOADADDR(.data.endmark);
234 . = ALIGN(PAGE_SIZE);
237 #ifdef CONFIG_HAVE_TCM
239 * We align everything to a page boundary so we can
240 * free it after init has commenced and TCM contents have
241 * been copied to its destination.
244 . = ALIGN(PAGE_SIZE);
250 * Link these to the ITCM RAM
251 * Put VMA to the TCM address and LMA to the common RAM
252 * and we'll upload the contents from RAM to TCM and free
253 * the used RAM after that.
255 .text_itcm ITCM_OFFSET : AT(__itcm_start)
265 * Reset the dot pointer, this is needed to create the
266 * relative __dtcm_start below (to be used as extern in code).
268 . = ADDR(.tcm_start) + SIZEOF(.tcm_start) + SIZEOF(.text_itcm);
274 /* TODO: add remainder of ITCM as well, that can be used for data! */
275 .data_dtcm DTCM_OFFSET : AT(__dtcm_start)
284 /* Reset the dot pointer or the linker gets confused */
285 . = ADDR(.dtcm_start) + SIZEOF(.data_dtcm);
287 /* End marker for freeing TCM copy in linked object */
288 .tcm_end : AT(ADDR(.dtcm_start) + SIZEOF(.data_dtcm)){
289 . = ALIGN(PAGE_SIZE);
301 * These must never be empty
302 * If you have to comment these two assert statements out, your
303 * binutils is too old (for other reasons as well)
305 ASSERT((__proc_info_end - __proc_info_begin), "missing CPU support")
306 ASSERT((__arch_info_end - __arch_info_begin), "no machine record defined")
309 * The HYP init code can't be more than a page long,
310 * and should not cross a page boundary.
311 * The above comment applies as well.
313 ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & PAGE_MASK) <= PAGE_SIZE,
314 "HYP init code too big or misaligned")
316 #ifdef CONFIG_XIP_DEFLATED_DATA
318 * The .bss is used as a stack area for __inflate_kernel_data() whose stack
319 * frame is 9568 bytes. Make sure it has extra room left.
321 ASSERT((_end - __bss_start) >= 12288, ".bss too small for CONFIG_XIP_DEFLATED_DATA")
324 #ifdef CONFIG_ARM_MPU
326 * Due to PMSAv7 restriction on base address and size we have to
327 * enforce minimal alignment restrictions. It was seen that weaker
328 * alignment restriction on _xiprom will likely force XIP address
329 * space spawns multiple MPU regions thus it is likely we run in
330 * situation when we are reprogramming MPU region we run on with
331 * something which doesn't cover reprogramming code itself, so as soon
332 * as we update MPU settings we'd immediately try to execute straight
333 * from background region which is XN.
334 * It seem that alignment in 1M should suit most users.
335 * _exiprom is aligned as 1/8 of 1M so can be covered by subregion
338 ASSERT(!(_xiprom & (SZ_1M - 1)), "XIP start address may cause MPU programming issues")
339 ASSERT(!(_exiprom & (SZ_128K - 1)), "XIP end address may cause MPU programming issues")