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