xref: /openbmc/linux/arch/arm64/kernel/vmlinux.lds.S (revision b03afaa8)
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
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>
6 */
7
8#define RO_EXCEPTION_TABLE_ALIGN	8
9
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>
15#include <asm/page.h>
16
17#include "image.h"
18
19OUTPUT_ARCH(aarch64)
20ENTRY(_text)
21
22jiffies = jiffies_64;
23
24#define HYPERVISOR_TEXT					\
25	/*						\
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)		\
32	 */						\
33	. = ALIGN(SZ_4K);				\
34	__hyp_idmap_text_start = .;			\
35	*(.hyp.idmap.text)				\
36	__hyp_idmap_text_end = .;			\
37	__hyp_text_start = .;				\
38	*(.hyp.text)					\
39	__hyp_text_end = .;
40
41#define IDMAP_TEXT					\
42	. = ALIGN(SZ_4K);				\
43	__idmap_text_start = .;				\
44	*(.idmap.text)					\
45	__idmap_text_end = .;
46
47#ifdef CONFIG_HIBERNATION
48#define HIBERNATE_TEXT					\
49	. = ALIGN(SZ_4K);				\
50	__hibernate_exit_text_start = .;		\
51	*(.hibernate_exit.text)				\
52	__hibernate_exit_text_end = .;
53#else
54#define HIBERNATE_TEXT
55#endif
56
57#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
58#define TRAMP_TEXT					\
59	. = ALIGN(PAGE_SIZE);				\
60	__entry_tramp_text_start = .;			\
61	*(.entry.tramp.text)				\
62	. = ALIGN(PAGE_SIZE);				\
63	__entry_tramp_text_end = .;
64#else
65#define TRAMP_TEXT
66#endif
67
68/*
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.
74 */
75PECOFF_FILE_ALIGNMENT = 0x200;
76
77#ifdef CONFIG_EFI
78#define PECOFF_EDATA_PADDING	\
79	.pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
80#else
81#define PECOFF_EDATA_PADDING
82#endif
83
84SECTIONS
85{
86	/*
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
90	 * order of matching.
91	 */
92	/DISCARD/ : {
93		EXIT_CALL
94		*(.discard)
95		*(.discard.*)
96		*(.interp .dynamic)
97		*(.dynsym .dynstr .hash .gnu.hash)
98		*(.eh_frame)
99	}
100
101	. = KIMAGE_VADDR + TEXT_OFFSET;
102
103	.head.text : {
104		_text = .;
105		HEAD_TEXT
106	}
107	.text : {			/* Real text segment		*/
108		_stext = .;		/* Text and read-only data	*/
109			IRQENTRY_TEXT
110			SOFTIRQENTRY_TEXT
111			ENTRY_TEXT
112			TEXT_TEXT
113			SCHED_TEXT
114			CPUIDLE_TEXT
115			LOCK_TEXT
116			KPROBES_TEXT
117			HYPERVISOR_TEXT
118			IDMAP_TEXT
119			HIBERNATE_TEXT
120			TRAMP_TEXT
121			*(.fixup)
122			*(.gnu.warning)
123		. = ALIGN(16);
124		*(.got)			/* Global offset table		*/
125	}
126
127	. = ALIGN(SEGMENT_ALIGN);
128	_etext = .;			/* End of text section */
129
130	/* everything from this point to __init_begin will be marked RO NX */
131	RO_DATA(PAGE_SIZE)
132
133	idmap_pg_dir = .;
134	. += IDMAP_DIR_SIZE;
135	idmap_pg_end = .;
136
137#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
138	tramp_pg_dir = .;
139	. += PAGE_SIZE;
140#endif
141
142#ifdef CONFIG_ARM64_SW_TTBR0_PAN
143	reserved_ttbr0 = .;
144	. += RESERVED_TTBR0_SIZE;
145#endif
146	swapper_pg_dir = .;
147	. += PAGE_SIZE;
148	swapper_pg_end = .;
149
150	. = ALIGN(SEGMENT_ALIGN);
151	__init_begin = .;
152	__inittext_begin = .;
153
154	INIT_TEXT_SECTION(8)
155
156	__exittext_begin = .;
157	.exit.text : {
158		EXIT_TEXT
159	}
160	__exittext_end = .;
161
162	. = ALIGN(4);
163	.altinstructions : {
164		__alt_instructions = .;
165		*(.altinstructions)
166		__alt_instructions_end = .;
167	}
168
169	. = ALIGN(SEGMENT_ALIGN);
170	__inittext_end = .;
171	__initdata_begin = .;
172
173	.init.data : {
174		INIT_DATA
175		INIT_SETUP(16)
176		INIT_CALLS
177		CON_INITCALL
178		INIT_RAM_FS
179		*(.init.rodata.* .init.bss)	/* from the EFI stub */
180	}
181	.exit.data : {
182		EXIT_DATA
183	}
184
185	PERCPU_SECTION(L1_CACHE_BYTES)
186
187	.rela.dyn : ALIGN(8) {
188		*(.rela .rela*)
189	}
190
191	__rela_offset	= ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR);
192	__rela_size	= SIZEOF(.rela.dyn);
193
194#ifdef CONFIG_RELR
195	.relr.dyn : ALIGN(8) {
196		*(.relr.dyn)
197	}
198
199	__relr_offset	= ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR);
200	__relr_size	= SIZEOF(.relr.dyn);
201#endif
202
203	. = ALIGN(SEGMENT_ALIGN);
204	__initdata_end = .;
205	__init_end = .;
206
207	_data = .;
208	_sdata = .;
209	RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
210
211	/*
212	 * Data written with the MMU off but read with the MMU on requires
213	 * cache lines to be invalidated, discarding up to a Cache Writeback
214	 * Granule (CWG) of data from the cache. Keep the section that
215	 * requires this type of maintenance to be in its own Cache Writeback
216	 * Granule (CWG) area so the cache maintenance operations don't
217	 * interfere with adjacent data.
218	 */
219	.mmuoff.data.write : ALIGN(SZ_2K) {
220		__mmuoff_data_start = .;
221		*(.mmuoff.data.write)
222	}
223	. = ALIGN(SZ_2K);
224	.mmuoff.data.read : {
225		*(.mmuoff.data.read)
226		__mmuoff_data_end = .;
227	}
228
229	PECOFF_EDATA_PADDING
230	__pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
231	_edata = .;
232
233	BSS_SECTION(0, 0, 0)
234
235	. = ALIGN(PAGE_SIZE);
236	init_pg_dir = .;
237	. += INIT_DIR_SIZE;
238	init_pg_end = .;
239
240	. = ALIGN(SEGMENT_ALIGN);
241	__pecoff_data_size = ABSOLUTE(. - __initdata_begin);
242	_end = .;
243
244	STABS_DEBUG
245
246	HEAD_SYMBOLS
247}
248
249#include "image-vars.h"
250
251/*
252 * The HYP init code and ID map text can't be longer than a page each,
253 * and should not cross a page boundary.
254 */
255ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
256	"HYP init code too big or misaligned")
257ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
258	"ID map text too big or misaligned")
259#ifdef CONFIG_HIBERNATION
260ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
261	<= SZ_4K, "Hibernate exit text too big or misaligned")
262#endif
263#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
264ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE,
265	"Entry trampoline text too big")
266#endif
267/*
268 * If padding is applied before .head.text, virt<->phys conversions will fail.
269 */
270ASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned")
271