xref: /openbmc/linux/arch/arm/kernel/vmlinux.lds.S (revision 550987be)
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>
5 */
6
7#ifdef CONFIG_XIP_KERNEL
8#include "vmlinux-xip.lds.S"
9#else
10
11#include <asm-generic/vmlinux.lds.h>
12#include <asm/cache.h>
13#include <asm/thread_info.h>
14#include <asm/memory.h>
15#include <asm/page.h>
16#include <asm/pgtable.h>
17
18#define PROC_INFO							\
19	. = ALIGN(4);							\
20	VMLINUX_SYMBOL(__proc_info_begin) = .;				\
21	*(.proc.info.init)						\
22	VMLINUX_SYMBOL(__proc_info_end) = .;
23
24#define HYPERVISOR_TEXT							\
25	VMLINUX_SYMBOL(__hyp_text_start) = .;				\
26	*(.hyp.text)							\
27	VMLINUX_SYMBOL(__hyp_text_end) = .;
28
29#define IDMAP_TEXT							\
30	ALIGN_FUNCTION();						\
31	VMLINUX_SYMBOL(__idmap_text_start) = .;				\
32	*(.idmap.text)							\
33	VMLINUX_SYMBOL(__idmap_text_end) = .;				\
34	. = ALIGN(PAGE_SIZE);						\
35	VMLINUX_SYMBOL(__hyp_idmap_text_start) = .;			\
36	*(.hyp.idmap.text)						\
37	VMLINUX_SYMBOL(__hyp_idmap_text_end) = .;
38
39#ifdef CONFIG_HOTPLUG_CPU
40#define ARM_CPU_DISCARD(x)
41#define ARM_CPU_KEEP(x)		x
42#else
43#define ARM_CPU_DISCARD(x)	x
44#define ARM_CPU_KEEP(x)
45#endif
46
47#if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
48	defined(CONFIG_GENERIC_BUG) || defined(CONFIG_JUMP_LABEL)
49#define ARM_EXIT_KEEP(x)	x
50#define ARM_EXIT_DISCARD(x)
51#else
52#define ARM_EXIT_KEEP(x)
53#define ARM_EXIT_DISCARD(x)	x
54#endif
55
56OUTPUT_ARCH(arm)
57ENTRY(stext)
58
59#ifndef __ARMEB__
60jiffies = jiffies_64;
61#else
62jiffies = jiffies_64 + 4;
63#endif
64
65SECTIONS
66{
67	/*
68	 * XXX: The linker does not define how output sections are
69	 * assigned to input sections when there are multiple statements
70	 * matching the same input section name.  There is no documented
71	 * order of matching.
72	 *
73	 * unwind exit sections must be discarded before the rest of the
74	 * unwind sections get included.
75	 */
76	/DISCARD/ : {
77		*(.ARM.exidx.exit.text)
78		*(.ARM.extab.exit.text)
79		ARM_CPU_DISCARD(*(.ARM.exidx.cpuexit.text))
80		ARM_CPU_DISCARD(*(.ARM.extab.cpuexit.text))
81		ARM_EXIT_DISCARD(EXIT_TEXT)
82		ARM_EXIT_DISCARD(EXIT_DATA)
83		EXIT_CALL
84#ifndef CONFIG_MMU
85		*(.text.fixup)
86		*(__ex_table)
87#endif
88#ifndef CONFIG_SMP_ON_UP
89		*(.alt.smp.init)
90#endif
91		*(.discard)
92		*(.discard.*)
93	}
94
95	. = PAGE_OFFSET + TEXT_OFFSET;
96	.head.text : {
97		_text = .;
98		HEAD_TEXT
99	}
100
101#ifdef CONFIG_STRICT_KERNEL_RWX
102	. = ALIGN(1<<SECTION_SHIFT);
103#endif
104
105	.text : {			/* Real text segment		*/
106		_stext = .;		/* Text and read-only data	*/
107			IDMAP_TEXT
108			__entry_text_start = .;
109			*(.entry.text)
110			__entry_text_end = .;
111			IRQENTRY_TEXT
112			SOFTIRQENTRY_TEXT
113			TEXT_TEXT
114			SCHED_TEXT
115			CPUIDLE_TEXT
116			LOCK_TEXT
117			HYPERVISOR_TEXT
118			KPROBES_TEXT
119			*(.gnu.warning)
120			*(.glue_7)
121			*(.glue_7t)
122		. = ALIGN(4);
123		*(.got)			/* Global offset table		*/
124			ARM_CPU_KEEP(PROC_INFO)
125	}
126
127#ifdef CONFIG_DEBUG_ALIGN_RODATA
128	. = ALIGN(1<<SECTION_SHIFT);
129#endif
130	_etext = .;			/* End of text section */
131
132	RO_DATA(PAGE_SIZE)
133
134	. = ALIGN(4);
135	__ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
136		__start___ex_table = .;
137#ifdef CONFIG_MMU
138		*(__ex_table)
139#endif
140		__stop___ex_table = .;
141	}
142
143#ifdef CONFIG_ARM_UNWIND
144	/*
145	 * Stack unwinding tables
146	 */
147	. = ALIGN(8);
148	.ARM.unwind_idx : {
149		__start_unwind_idx = .;
150		*(.ARM.exidx*)
151		__stop_unwind_idx = .;
152	}
153	.ARM.unwind_tab : {
154		__start_unwind_tab = .;
155		*(.ARM.extab*)
156		__stop_unwind_tab = .;
157	}
158#endif
159
160	NOTES
161
162#ifdef CONFIG_STRICT_KERNEL_RWX
163	. = ALIGN(1<<SECTION_SHIFT);
164#else
165	. = ALIGN(PAGE_SIZE);
166#endif
167	__init_begin = .;
168
169	/*
170	 * The vectors and stubs are relocatable code, and the
171	 * only thing that matters is their relative offsets
172	 */
173	__vectors_start = .;
174	.vectors 0xffff0000 : AT(__vectors_start) {
175		*(.vectors)
176	}
177	. = __vectors_start + SIZEOF(.vectors);
178	__vectors_end = .;
179
180	__stubs_start = .;
181	.stubs ADDR(.vectors) + 0x1000 : AT(__stubs_start) {
182		*(.stubs)
183	}
184	. = __stubs_start + SIZEOF(.stubs);
185	__stubs_end = .;
186
187	PROVIDE(vector_fiq_offset = vector_fiq - ADDR(.vectors));
188
189	INIT_TEXT_SECTION(8)
190	.exit.text : {
191		ARM_EXIT_KEEP(EXIT_TEXT)
192	}
193	.init.proc.info : {
194		ARM_CPU_DISCARD(PROC_INFO)
195	}
196	.init.arch.info : {
197		__arch_info_begin = .;
198		*(.arch.info.init)
199		__arch_info_end = .;
200	}
201	.init.tagtable : {
202		__tagtable_begin = .;
203		*(.taglist.init)
204		__tagtable_end = .;
205	}
206#ifdef CONFIG_SMP_ON_UP
207	.init.smpalt : {
208		__smpalt_begin = .;
209		*(.alt.smp.init)
210		__smpalt_end = .;
211	}
212#endif
213	.init.pv_table : {
214		__pv_table_begin = .;
215		*(.pv_table)
216		__pv_table_end = .;
217	}
218
219	INIT_DATA_SECTION(16)
220
221	.exit.data : {
222		ARM_EXIT_KEEP(EXIT_DATA)
223	}
224
225#ifdef CONFIG_SMP
226	PERCPU_SECTION(L1_CACHE_BYTES)
227#endif
228
229#ifdef CONFIG_STRICT_KERNEL_RWX
230	. = ALIGN(1<<SECTION_SHIFT);
231#else
232	. = ALIGN(THREAD_SIZE);
233#endif
234	__init_end = .;
235
236	_sdata = .;
237	RW_DATA_SECTION(L1_CACHE_BYTES, PAGE_SIZE, THREAD_SIZE)
238	_edata = .;
239
240#ifdef CONFIG_HAVE_TCM
241        /*
242	 * We align everything to a page boundary so we can
243	 * free it after init has commenced and TCM contents have
244	 * been copied to its destination.
245	 */
246	.tcm_start : {
247		. = ALIGN(PAGE_SIZE);
248		__tcm_start = .;
249		__itcm_start = .;
250	}
251
252	/*
253	 * Link these to the ITCM RAM
254	 * Put VMA to the TCM address and LMA to the common RAM
255	 * and we'll upload the contents from RAM to TCM and free
256	 * the used RAM after that.
257	 */
258	.text_itcm ITCM_OFFSET : AT(__itcm_start)
259	{
260		__sitcm_text = .;
261		*(.tcm.text)
262		*(.tcm.rodata)
263		. = ALIGN(4);
264		__eitcm_text = .;
265	}
266
267	/*
268	 * Reset the dot pointer, this is needed to create the
269	 * relative __dtcm_start below (to be used as extern in code).
270	 */
271	. = ADDR(.tcm_start) + SIZEOF(.tcm_start) + SIZEOF(.text_itcm);
272
273	.dtcm_start : {
274		__dtcm_start = .;
275	}
276
277	/* TODO: add remainder of ITCM as well, that can be used for data! */
278	.data_dtcm DTCM_OFFSET : AT(__dtcm_start)
279	{
280		. = ALIGN(4);
281		__sdtcm_data = .;
282		*(.tcm.data)
283		. = ALIGN(4);
284		__edtcm_data = .;
285	}
286
287	/* Reset the dot pointer or the linker gets confused */
288	. = ADDR(.dtcm_start) + SIZEOF(.data_dtcm);
289
290	/* End marker for freeing TCM copy in linked object */
291	.tcm_end : AT(ADDR(.dtcm_start) + SIZEOF(.data_dtcm)){
292		. = ALIGN(PAGE_SIZE);
293		__tcm_end = .;
294	}
295#endif
296
297	BSS_SECTION(0, 0, 0)
298	_end = .;
299
300	STABS_DEBUG
301}
302
303#ifdef CONFIG_STRICT_KERNEL_RWX
304/*
305 * Without CONFIG_DEBUG_ALIGN_RODATA, __start_rodata_section_aligned will
306 * be the first section-aligned location after __start_rodata. Otherwise,
307 * it will be equal to __start_rodata.
308 */
309__start_rodata_section_aligned = ALIGN(__start_rodata, 1 << SECTION_SHIFT);
310#endif
311
312/*
313 * These must never be empty
314 * If you have to comment these two assert statements out, your
315 * binutils is too old (for other reasons as well)
316 */
317ASSERT((__proc_info_end - __proc_info_begin), "missing CPU support")
318ASSERT((__arch_info_end - __arch_info_begin), "no machine record defined")
319
320/*
321 * The HYP init code can't be more than a page long,
322 * and should not cross a page boundary.
323 * The above comment applies as well.
324 */
325ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & PAGE_MASK) <= PAGE_SIZE,
326	"HYP init code too big or misaligned")
327
328#endif /* CONFIG_XIP_KERNEL */
329