• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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#include <asm/hyp_image.h>
9#ifdef CONFIG_KVM
10#define HYPERVISOR_EXTABLE					\
11	. = ALIGN(SZ_8);					\
12	__start___kvm_ex_table = .;				\
13	*(__kvm_ex_table)					\
14	__stop___kvm_ex_table = .;
15
16#define HYPERVISOR_RODATA_SECTIONS				\
17	HYP_SECTION_NAME(.rodata) : {				\
18		. = ALIGN(PAGE_SIZE);				\
19		__hyp_rodata_start = .;				\
20		*(HYP_SECTION_NAME(.data..ro_after_init))	\
21		*(HYP_SECTION_NAME(.rodata))			\
22		. = ALIGN(PAGE_SIZE);				\
23		__hyp_rodata_end = .;				\
24	}
25
26#define HYPERVISOR_DATA_SECTION					\
27	HYP_SECTION_NAME(.data) : {				\
28		. = ALIGN(PAGE_SIZE);				\
29		__hyp_data_start = .;				\
30		*(HYP_SECTION_NAME(.data))			\
31		. = ALIGN(PAGE_SIZE);				\
32		__hyp_data_end = .;				\
33	}
34
35#define HYPERVISOR_PERCPU_SECTION				\
36	. = ALIGN(PAGE_SIZE);					\
37	HYP_SECTION_NAME(.data..percpu) : {			\
38		*(HYP_SECTION_NAME(.data..percpu))		\
39	}
40
41#define HYPERVISOR_RELOC_SECTION				\
42	.hyp.reloc : ALIGN(4) {					\
43		__hyp_reloc_begin = .;				\
44		*(.hyp.reloc)					\
45		__hyp_reloc_end = .;				\
46	}
47
48#define BSS_FIRST_SECTIONS					\
49	__hyp_bss_start = .;					\
50	*(HYP_SECTION_NAME(.bss))				\
51	. = ALIGN(PAGE_SIZE);					\
52	__hyp_bss_end = .;
53
54/*
55 * We require that __hyp_bss_start and __bss_start are aligned, and enforce it
56 * with an assertion. But the BSS_SECTION macro places an empty .sbss section
57 * between them, which can in some cases cause the linker to misalign them. To
58 * work around the issue, force a page alignment for __bss_start.
59 */
60#define SBSS_ALIGN			PAGE_SIZE
61#else /* CONFIG_KVM */
62#define HYPERVISOR_EXTABLE
63#define HYPERVISOR_RODATA_SECTIONS
64#define HYPERVISOR_DATA_SECTION
65#define HYPERVISOR_PERCPU_SECTION
66#define HYPERVISOR_RELOC_SECTION
67#define SBSS_ALIGN			0
68#endif
69
70#define RO_EXCEPTION_TABLE_ALIGN	8
71#define RUNTIME_DISCARD_EXIT
72
73#include <asm-generic/vmlinux.lds.h>
74#include <asm/cache.h>
75#include <asm/kernel-pgtable.h>
76#include <asm/memory.h>
77#include <asm/page.h>
78
79#include "image.h"
80
81OUTPUT_ARCH(aarch64)
82ENTRY(_text)
83
84jiffies = jiffies_64;
85
86#define HYPERVISOR_TEXT					\
87	. = ALIGN(PAGE_SIZE);				\
88	__hyp_idmap_text_start = .;			\
89	*(.hyp.idmap.text)				\
90	__hyp_idmap_text_end = .;			\
91	__hyp_text_start = .;				\
92	*(.hyp.text)					\
93	HYPERVISOR_EXTABLE				\
94	. = ALIGN(PAGE_SIZE);				\
95	__hyp_text_end = .;
96
97#define IDMAP_TEXT					\
98	. = ALIGN(SZ_4K);				\
99	__idmap_text_start = .;				\
100	*(.idmap.text)					\
101	__idmap_text_end = .;
102
103#ifdef CONFIG_HIBERNATION
104#define HIBERNATE_TEXT					\
105	. = ALIGN(SZ_4K);				\
106	__hibernate_exit_text_start = .;		\
107	*(.hibernate_exit.text)				\
108	__hibernate_exit_text_end = .;
109#else
110#define HIBERNATE_TEXT
111#endif
112
113#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
114#define TRAMP_TEXT					\
115	. = ALIGN(PAGE_SIZE);				\
116	__entry_tramp_text_start = .;			\
117	*(.entry.tramp.text)				\
118	. = ALIGN(PAGE_SIZE);				\
119	__entry_tramp_text_end = .;
120#else
121#define TRAMP_TEXT
122#endif
123
124/*
125 * The size of the PE/COFF section that covers the kernel image, which
126 * runs from _stext to _edata, must be a round multiple of the PE/COFF
127 * FileAlignment, which we set to its minimum value of 0x200. '_stext'
128 * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
129 * boundary should be sufficient.
130 */
131PECOFF_FILE_ALIGNMENT = 0x200;
132
133#ifdef CONFIG_EFI
134#define PECOFF_EDATA_PADDING	\
135	.pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
136#else
137#define PECOFF_EDATA_PADDING
138#endif
139
140SECTIONS
141{
142	/*
143	 * XXX: The linker does not define how output sections are
144	 * assigned to input sections when there are multiple statements
145	 * matching the same input section name.  There is no documented
146	 * order of matching.
147	 */
148	DISCARDS
149	/DISCARD/ : {
150		*(.interp .dynamic)
151		*(.dynsym .dynstr .hash .gnu.hash)
152	}
153
154	. = KIMAGE_VADDR;
155
156	.head.text : {
157		_text = .;
158		HEAD_TEXT
159	}
160	.text : {			/* Real text segment		*/
161		_stext = .;		/* Text and read-only data	*/
162			IRQENTRY_TEXT
163			SOFTIRQENTRY_TEXT
164			ENTRY_TEXT
165			TEXT_TEXT
166			SCHED_TEXT
167			CPUIDLE_TEXT
168			LOCK_TEXT
169			KPROBES_TEXT
170			HYPERVISOR_TEXT
171			IDMAP_TEXT
172			HIBERNATE_TEXT
173			TRAMP_TEXT
174			*(.fixup)
175			*(.gnu.warning)
176		. = ALIGN(16);
177		*(.got)			/* Global offset table		*/
178	}
179
180	/*
181	 * Make sure that the .got.plt is either completely empty or it
182	 * contains only the lazy dispatch entries.
183	 */
184	.got.plt : { *(.got.plt) }
185	ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18,
186	       "Unexpected GOT/PLT entries detected!")
187
188	. = ALIGN(SEGMENT_ALIGN);
189	_etext = .;			/* End of text section */
190
191	/* everything from this point to __init_begin will be marked RO NX */
192	RO_DATA(PAGE_SIZE)
193
194	HYPERVISOR_RODATA_SECTIONS
195
196	idmap_pg_dir = .;
197	. += IDMAP_DIR_SIZE;
198	idmap_pg_end = .;
199
200#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
201	tramp_pg_dir = .;
202	. += PAGE_SIZE;
203#endif
204
205	reserved_pg_dir = .;
206	. += PAGE_SIZE;
207
208	swapper_pg_dir = .;
209	. += PAGE_SIZE;
210
211	. = ALIGN(SEGMENT_ALIGN);
212	__init_begin = .;
213	__inittext_begin = .;
214
215	INIT_TEXT_SECTION(8)
216
217	__exittext_begin = .;
218	.exit.text : {
219		EXIT_TEXT
220	}
221	__exittext_end = .;
222
223	. = ALIGN(4);
224	.altinstructions : {
225		__alt_instructions = .;
226		*(.altinstructions)
227		__alt_instructions_end = .;
228	}
229
230	. = ALIGN(SEGMENT_ALIGN);
231	__inittext_end = .;
232	__initdata_begin = .;
233
234	.init.data : {
235		INIT_DATA
236		INIT_SETUP(16)
237		INIT_CALLS
238		CON_INITCALL
239		INIT_RAM_FS
240		*(.init.altinstructions .init.rodata.* .init.bss)	/* from the EFI stub */
241	}
242	.exit.data : {
243		EXIT_DATA
244	}
245
246	PERCPU_SECTION(L1_CACHE_BYTES)
247	HYPERVISOR_PERCPU_SECTION
248
249	HYPERVISOR_RELOC_SECTION
250
251	.rela.dyn : ALIGN(8) {
252		*(.rela .rela*)
253	}
254
255	__rela_offset	= ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR);
256	__rela_size	= SIZEOF(.rela.dyn);
257
258#ifdef CONFIG_RELR
259	.relr.dyn : ALIGN(8) {
260		*(.relr.dyn)
261	}
262
263	__relr_offset	= ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR);
264	__relr_size	= SIZEOF(.relr.dyn);
265#endif
266
267	. = ALIGN(SEGMENT_ALIGN);
268	__initdata_end = .;
269	__init_end = .;
270
271	_data = .;
272	_sdata = .;
273	RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
274
275	HYPERVISOR_DATA_SECTION
276
277	/*
278	 * Data written with the MMU off but read with the MMU on requires
279	 * cache lines to be invalidated, discarding up to a Cache Writeback
280	 * Granule (CWG) of data from the cache. Keep the section that
281	 * requires this type of maintenance to be in its own Cache Writeback
282	 * Granule (CWG) area so the cache maintenance operations don't
283	 * interfere with adjacent data.
284	 */
285	.mmuoff.data.write : ALIGN(SZ_2K) {
286		__mmuoff_data_start = .;
287		*(.mmuoff.data.write)
288	}
289	. = ALIGN(SZ_2K);
290	.mmuoff.data.read : {
291		*(.mmuoff.data.read)
292		__mmuoff_data_end = .;
293	}
294
295	PECOFF_EDATA_PADDING
296	__pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
297	_edata = .;
298
299	BSS_SECTION(SBSS_ALIGN, 0, 0)
300
301	. = ALIGN(PAGE_SIZE);
302	init_pg_dir = .;
303	. += INIT_DIR_SIZE;
304	init_pg_end = .;
305
306	. = ALIGN(SEGMENT_ALIGN);
307	__pecoff_data_size = ABSOLUTE(. - __initdata_begin);
308	_end = .;
309
310	STABS_DEBUG
311	DWARF_DEBUG
312	ELF_DETAILS
313
314	HEAD_SYMBOLS
315
316	/*
317	 * Sections that should stay zero sized, which is safer to
318	 * explicitly check instead of blindly discarding.
319	 */
320	.plt : {
321		*(.plt) *(.plt.*) *(.iplt) *(.igot .igot.plt)
322	}
323	ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!")
324
325	.data.rel.ro : { *(.data.rel.ro) }
326	ASSERT(SIZEOF(.data.rel.ro) == 0, "Unexpected RELRO detected!")
327}
328
329#include "image-vars.h"
330
331/*
332 * The HYP init code and ID map text can't be longer than a page each. The
333 * former is page-aligned, but the latter may not be with 16K or 64K pages, so
334 * it should also not cross a page boundary.
335 */
336ASSERT(__hyp_idmap_text_end - __hyp_idmap_text_start <= PAGE_SIZE,
337	"HYP init code too big")
338ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
339	"ID map text too big or misaligned")
340#ifdef CONFIG_HIBERNATION
341ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
342	<= SZ_4K, "Hibernate exit text too big or misaligned")
343#endif
344#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
345ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) <= 3*PAGE_SIZE,
346	"Entry trampoline text too big")
347#endif
348#ifdef CONFIG_KVM
349ASSERT(__hyp_bss_start == __bss_start, "HYP and Host BSS are misaligned")
350#endif
351/*
352 * If padding is applied before .head.text, virt<->phys conversions will fail.
353 */
354ASSERT(_text == KIMAGE_VADDR, "HEAD is misaligned")
355