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