xref: /openbmc/linux/arch/arm64/kernel/vmlinux.lds.S (revision 00ef543419366e8b742435992d08e0d5a87fd561)
1b2441318SGreg Kroah-Hartman/* SPDX-License-Identifier: GPL-2.0 */
28c2c3df3SCatalin Marinas/*
38c2c3df3SCatalin Marinas * ld script to make ARM Linux kernel
48c2c3df3SCatalin Marinas * taken from the i386 version by Russell King
58c2c3df3SCatalin Marinas * Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>
68c2c3df3SCatalin Marinas */
78c2c3df3SCatalin Marinas
819f6bc32SKees Cook#define RO_EXCEPTION_TABLE_ALIGN	8
92883352bSKees Cook#define RUNTIME_DISCARD_EXIT
1019f6bc32SKees Cook
118c2c3df3SCatalin Marinas#include <asm-generic/vmlinux.lds.h>
1298fb7548SArd Biesheuvel#include <asm/cache.h>
13ce492a16SDavid Brazdil#include <asm/hyp_image.h>
1487d1587bSSuzuki K. Poulose#include <asm/kernel-pgtable.h>
158c2c3df3SCatalin Marinas#include <asm/memory.h>
168c2c3df3SCatalin Marinas#include <asm/page.h>
178c2c3df3SCatalin Marinas
18a2c1d73bSMark Rutland#include "image.h"
19a2c1d73bSMark Rutland
208c2c3df3SCatalin MarinasOUTPUT_ARCH(aarch64)
21af885f40SGeoff LevandENTRY(_text)
228c2c3df3SCatalin Marinas
238c2c3df3SCatalin Marinasjiffies = jiffies_64;
248c2c3df3SCatalin Marinas
25e9ee186bSJames Morse
263471ee06SDavid Brazdil#ifdef CONFIG_KVM
27e9ee186bSJames Morse#define HYPERVISOR_EXTABLE					\
28e9ee186bSJames Morse	. = ALIGN(SZ_8);					\
29e9ee186bSJames Morse	__start___kvm_ex_table = .;				\
30e9ee186bSJames Morse	*(__kvm_ex_table)					\
31e9ee186bSJames Morse	__stop___kvm_ex_table = .;
3230c95391SDavid Brazdil
332d7bf218SDavid Brazdil#define HYPERVISOR_DATA_SECTIONS				\
342d7bf218SDavid Brazdil	HYP_SECTION_NAME(.data..ro_after_init) : {		\
352d7bf218SDavid Brazdil		__hyp_data_ro_after_init_start = .;		\
362d7bf218SDavid Brazdil		*(HYP_SECTION_NAME(.data..ro_after_init))	\
372d7bf218SDavid Brazdil		__hyp_data_ro_after_init_end = .;		\
382d7bf218SDavid Brazdil	}
392d7bf218SDavid Brazdil
4030c95391SDavid Brazdil#define HYPERVISOR_PERCPU_SECTION				\
4130c95391SDavid Brazdil	. = ALIGN(PAGE_SIZE);					\
4230c95391SDavid Brazdil	HYP_SECTION_NAME(.data..percpu) : {			\
4330c95391SDavid Brazdil		*(HYP_SECTION_NAME(.data..percpu))		\
4430c95391SDavid Brazdil	}
453471ee06SDavid Brazdil#else /* CONFIG_KVM */
463471ee06SDavid Brazdil#define HYPERVISOR_EXTABLE
472d7bf218SDavid Brazdil#define HYPERVISOR_DATA_SECTIONS
4830c95391SDavid Brazdil#define HYPERVISOR_PERCPU_SECTION
493471ee06SDavid Brazdil#endif
50e9ee186bSJames Morse
512240bbb6SMarc Zyngier#define HYPERVISOR_TEXT					\
522240bbb6SMarc Zyngier	/*						\
5306f75a1fSArd Biesheuvel	 * Align to 4 KB so that			\
5406f75a1fSArd Biesheuvel	 * a) the HYP vector table is at its minimum	\
5506f75a1fSArd Biesheuvel	 *    alignment of 2048 bytes			\
5606f75a1fSArd Biesheuvel	 * b) the HYP init code will not cross a page	\
5706f75a1fSArd Biesheuvel	 *    boundary if its size does not exceed	\
5806f75a1fSArd Biesheuvel	 *    4 KB (see related ASSERT() below)		\
592240bbb6SMarc Zyngier	 */						\
6006f75a1fSArd Biesheuvel	. = ALIGN(SZ_4K);				\
615c636aa0SMasahiro Yamada	__hyp_idmap_text_start = .;			\
622240bbb6SMarc Zyngier	*(.hyp.idmap.text)				\
635c636aa0SMasahiro Yamada	__hyp_idmap_text_end = .;			\
645c636aa0SMasahiro Yamada	__hyp_text_start = .;				\
652240bbb6SMarc Zyngier	*(.hyp.text)					\
66e9ee186bSJames Morse	HYPERVISOR_EXTABLE				\
675c636aa0SMasahiro Yamada	__hyp_text_end = .;
682240bbb6SMarc Zyngier
695dfe9d7dSArd Biesheuvel#define IDMAP_TEXT					\
705dfe9d7dSArd Biesheuvel	. = ALIGN(SZ_4K);				\
715c636aa0SMasahiro Yamada	__idmap_text_start = .;				\
725dfe9d7dSArd Biesheuvel	*(.idmap.text)					\
735c636aa0SMasahiro Yamada	__idmap_text_end = .;
745dfe9d7dSArd Biesheuvel
7582869ac5SJames Morse#ifdef CONFIG_HIBERNATION
7682869ac5SJames Morse#define HIBERNATE_TEXT					\
7782869ac5SJames Morse	. = ALIGN(SZ_4K);				\
785c636aa0SMasahiro Yamada	__hibernate_exit_text_start = .;		\
7982869ac5SJames Morse	*(.hibernate_exit.text)				\
805c636aa0SMasahiro Yamada	__hibernate_exit_text_end = .;
8182869ac5SJames Morse#else
8282869ac5SJames Morse#define HIBERNATE_TEXT
8382869ac5SJames Morse#endif
8482869ac5SJames Morse
85c7b9adafSWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
86c7b9adafSWill Deacon#define TRAMP_TEXT					\
87c7b9adafSWill Deacon	. = ALIGN(PAGE_SIZE);				\
885c636aa0SMasahiro Yamada	__entry_tramp_text_start = .;			\
89c7b9adafSWill Deacon	*(.entry.tramp.text)				\
90c7b9adafSWill Deacon	. = ALIGN(PAGE_SIZE);				\
915c636aa0SMasahiro Yamada	__entry_tramp_text_end = .;
92c7b9adafSWill Deacon#else
93c7b9adafSWill Deacon#define TRAMP_TEXT
94c7b9adafSWill Deacon#endif
95c7b9adafSWill Deacon
96a352ea3eSArd Biesheuvel/*
97a352ea3eSArd Biesheuvel * The size of the PE/COFF section that covers the kernel image, which
98348a625dSArd Biesheuvel * runs from _stext to _edata, must be a round multiple of the PE/COFF
99348a625dSArd Biesheuvel * FileAlignment, which we set to its minimum value of 0x200. '_stext'
100a352ea3eSArd Biesheuvel * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
101a352ea3eSArd Biesheuvel * boundary should be sufficient.
102a352ea3eSArd Biesheuvel */
103a352ea3eSArd BiesheuvelPECOFF_FILE_ALIGNMENT = 0x200;
104a352ea3eSArd Biesheuvel
105a352ea3eSArd Biesheuvel#ifdef CONFIG_EFI
106a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING	\
107a352ea3eSArd Biesheuvel	.pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
108a352ea3eSArd Biesheuvel#else
109a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING
110a352ea3eSArd Biesheuvel#endif
111a352ea3eSArd Biesheuvel
1128c2c3df3SCatalin MarinasSECTIONS
1138c2c3df3SCatalin Marinas{
1148c2c3df3SCatalin Marinas	/*
1158c2c3df3SCatalin Marinas	 * XXX: The linker does not define how output sections are
1168c2c3df3SCatalin Marinas	 * assigned to input sections when there are multiple statements
1178c2c3df3SCatalin Marinas	 * matching the same input section name.  There is no documented
1188c2c3df3SCatalin Marinas	 * order of matching.
1198c2c3df3SCatalin Marinas	 */
1202883352bSKees Cook	DISCARDS
1218c2c3df3SCatalin Marinas	/DISCARD/ : {
1221e48ef7fSArd Biesheuvel		*(.interp .dynamic)
1233bbd3db8SArd Biesheuvel		*(.dynsym .dynstr .hash .gnu.hash)
1248c2c3df3SCatalin Marinas	}
1258c2c3df3SCatalin Marinas
126120dc60dSArd Biesheuvel	. = KIMAGE_VADDR;
1278c2c3df3SCatalin Marinas
1288c2c3df3SCatalin Marinas	.head.text : {
1298c2c3df3SCatalin Marinas		_text = .;
1308c2c3df3SCatalin Marinas		HEAD_TEXT
1318c2c3df3SCatalin Marinas	}
132e2a073ddSArd Biesheuvel	.text : ALIGN(SEGMENT_ALIGN) {	/* Real text segment		*/
1338c2c3df3SCatalin Marinas		_stext = .;		/* Text and read-only data	*/
1348c2c3df3SCatalin Marinas			IRQENTRY_TEXT
135be7635e7SAlexander Potapenko			SOFTIRQENTRY_TEXT
136888b3c87SPratyush Anand			ENTRY_TEXT
1378c2c3df3SCatalin Marinas			TEXT_TEXT
1388c2c3df3SCatalin Marinas			SCHED_TEXT
1396727ad9eSChris Metcalf			CPUIDLE_TEXT
1408c2c3df3SCatalin Marinas			LOCK_TEXT
1412dd0e8d2SSandeepa Prabhu			KPROBES_TEXT
1422240bbb6SMarc Zyngier			HYPERVISOR_TEXT
1435dfe9d7dSArd Biesheuvel			IDMAP_TEXT
14482869ac5SJames Morse			HIBERNATE_TEXT
145c7b9adafSWill Deacon			TRAMP_TEXT
1468c2c3df3SCatalin Marinas			*(.fixup)
1478c2c3df3SCatalin Marinas			*(.gnu.warning)
1488c2c3df3SCatalin Marinas		. = ALIGN(16);
1498c2c3df3SCatalin Marinas		*(.got)			/* Global offset table		*/
1508c2c3df3SCatalin Marinas	}
1518c2c3df3SCatalin Marinas
152be288182SKees Cook	/*
153be288182SKees Cook	 * Make sure that the .got.plt is either completely empty or it
154be288182SKees Cook	 * contains only the lazy dispatch entries.
155be288182SKees Cook	 */
156be288182SKees Cook	.got.plt : { *(.got.plt) }
157be288182SKees Cook	ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18,
158be288182SKees Cook	       "Unexpected GOT/PLT entries detected!")
159be288182SKees Cook
16097740051SArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
1619fdc14c5SArd Biesheuvel	_etext = .;			/* End of text section */
1629fdc14c5SArd Biesheuvel
16319f6bc32SKees Cook	/* everything from this point to __init_begin will be marked RO NX */
16419f6bc32SKees Cook	RO_DATA(PAGE_SIZE)
1658c2c3df3SCatalin Marinas
1668eb7e28dSJun Yao	idmap_pg_dir = .;
1678eb7e28dSJun Yao	. += IDMAP_DIR_SIZE;
1689d2d75edSGavin Shan	idmap_pg_end = .;
1698eb7e28dSJun Yao
1708eb7e28dSJun Yao#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
1718eb7e28dSJun Yao	tramp_pg_dir = .;
1728eb7e28dSJun Yao	. += PAGE_SIZE;
1738eb7e28dSJun Yao#endif
1748eb7e28dSJun Yao
175833be850SMark Rutland	reserved_pg_dir = .;
176833be850SMark Rutland	. += PAGE_SIZE;
177833be850SMark Rutland
1788eb7e28dSJun Yao	swapper_pg_dir = .;
1798eb7e28dSJun Yao	. += PAGE_SIZE;
1808eb7e28dSJun Yao
18197740051SArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
1828c2c3df3SCatalin Marinas	__init_begin = .;
1832ebe088bSArd Biesheuvel	__inittext_begin = .;
1848c2c3df3SCatalin Marinas
1858c2c3df3SCatalin Marinas	INIT_TEXT_SECTION(8)
186ca2ef4ffSMark Rutland
187ca2ef4ffSMark Rutland	__exittext_begin = .;
1888c2c3df3SCatalin Marinas	.exit.text : {
1891eae811dSArd Biesheuvel		EXIT_TEXT
1908c2c3df3SCatalin Marinas	}
191ca2ef4ffSMark Rutland	__exittext_end = .;
192da141706SLaura Abbott
1932ebe088bSArd Biesheuvel	. = ALIGN(4);
1942ebe088bSArd Biesheuvel	.altinstructions : {
1952ebe088bSArd Biesheuvel		__alt_instructions = .;
1962ebe088bSArd Biesheuvel		*(.altinstructions)
1972ebe088bSArd Biesheuvel		__alt_instructions_end = .;
1982ebe088bSArd Biesheuvel	}
1992ebe088bSArd Biesheuvel
20076085affSArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
2012ebe088bSArd Biesheuvel	__inittext_end = .;
2022ebe088bSArd Biesheuvel	__initdata_begin = .;
2032ebe088bSArd Biesheuvel
2048c2c3df3SCatalin Marinas	.init.data : {
2058c2c3df3SCatalin Marinas		INIT_DATA
2068c2c3df3SCatalin Marinas		INIT_SETUP(16)
2078c2c3df3SCatalin Marinas		INIT_CALLS
2088c2c3df3SCatalin Marinas		CON_INITCALL
2098c2c3df3SCatalin Marinas		INIT_RAM_FS
210ba4259a6SCatalin Marinas		*(.init.altinstructions .init.bss)	/* from the EFI stub */
2118c2c3df3SCatalin Marinas	}
2128c2c3df3SCatalin Marinas	.exit.data : {
2131eae811dSArd Biesheuvel		EXIT_DATA
2148c2c3df3SCatalin Marinas	}
2158c2c3df3SCatalin Marinas
21698fb7548SArd Biesheuvel	PERCPU_SECTION(L1_CACHE_BYTES)
21730c95391SDavid Brazdil	HYPERVISOR_PERCPU_SECTION
2188c2c3df3SCatalin Marinas
2193bbd3db8SArd Biesheuvel	.rela.dyn : ALIGN(8) {
2201e48ef7fSArd Biesheuvel		*(.rela .rela*)
2211e48ef7fSArd Biesheuvel	}
222e039ee4eSAndre Przywara
2233bbd3db8SArd Biesheuvel	__rela_offset	= ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR);
2243bbd3db8SArd Biesheuvel	__rela_size	= SIZEOF(.rela.dyn);
2250cd3defeSArd Biesheuvel
2265cf896fbSPeter Collingbourne#ifdef CONFIG_RELR
2275cf896fbSPeter Collingbourne	.relr.dyn : ALIGN(8) {
2285cf896fbSPeter Collingbourne		*(.relr.dyn)
2295cf896fbSPeter Collingbourne	}
2305cf896fbSPeter Collingbourne
2315cf896fbSPeter Collingbourne	__relr_offset	= ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR);
2325cf896fbSPeter Collingbourne	__relr_size	= SIZEOF(.relr.dyn);
2335cf896fbSPeter Collingbourne#endif
2345cf896fbSPeter Collingbourne
23597740051SArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
2362ebe088bSArd Biesheuvel	__initdata_end = .;
2379aa4ec15SMark Rutland	__init_end = .;
2389aa4ec15SMark Rutland
2393c620626SMark Salter	_data = .;
2408c2c3df3SCatalin Marinas	_sdata = .;
241c9174047SKees Cook	RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
242b6113038SJames Morse
2432d7bf218SDavid Brazdil	HYPERVISOR_DATA_SECTIONS
2442d7bf218SDavid Brazdil
245b6113038SJames Morse	/*
246b6113038SJames Morse	 * Data written with the MMU off but read with the MMU on requires
247b6113038SJames Morse	 * cache lines to be invalidated, discarding up to a Cache Writeback
248b6113038SJames Morse	 * Granule (CWG) of data from the cache. Keep the section that
249b6113038SJames Morse	 * requires this type of maintenance to be in its own Cache Writeback
250b6113038SJames Morse	 * Granule (CWG) area so the cache maintenance operations don't
251b6113038SJames Morse	 * interfere with adjacent data.
252b6113038SJames Morse	 */
253b6113038SJames Morse	.mmuoff.data.write : ALIGN(SZ_2K) {
254b6113038SJames Morse		__mmuoff_data_start = .;
255b6113038SJames Morse		*(.mmuoff.data.write)
256b6113038SJames Morse	}
257b6113038SJames Morse	. = ALIGN(SZ_2K);
258b6113038SJames Morse	.mmuoff.data.read : {
259b6113038SJames Morse		*(.mmuoff.data.read)
260b6113038SJames Morse		__mmuoff_data_end = .;
261b6113038SJames Morse	}
262b6113038SJames Morse
263a352ea3eSArd Biesheuvel	PECOFF_EDATA_PADDING
264cad27ef2SArd Biesheuvel	__pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
2658c2c3df3SCatalin Marinas	_edata = .;
2668c2c3df3SCatalin Marinas
2678c2c3df3SCatalin Marinas	BSS_SECTION(0, 0, 0)
268bd00cd5fSMark Rutland
269bd00cd5fSMark Rutland	. = ALIGN(PAGE_SIZE);
2702b5548b6SJun Yao	init_pg_dir = .;
2712b5548b6SJun Yao	. += INIT_DIR_SIZE;
2722b5548b6SJun Yao	init_pg_end = .;
2732b5548b6SJun Yao
27476085affSArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
275cad27ef2SArd Biesheuvel	__pecoff_data_size = ABSOLUTE(. - __initdata_begin);
2768c2c3df3SCatalin Marinas	_end = .;
2778c2c3df3SCatalin Marinas
2788c2c3df3SCatalin Marinas	STABS_DEBUG
279578d7f0fSKees Cook	DWARF_DEBUG
280c604abc3SKees Cook	ELF_DETAILS
281a2c1d73bSMark Rutland
282a2c1d73bSMark Rutland	HEAD_SYMBOLS
283be288182SKees Cook
284be288182SKees Cook	/*
285be288182SKees Cook	 * Sections that should stay zero sized, which is safer to
286be288182SKees Cook	 * explicitly check instead of blindly discarding.
287be288182SKees Cook	 */
288be288182SKees Cook	.plt : {
2895f692a81SArd Biesheuvel		*(.plt) *(.plt.*) *(.iplt) *(.igot .igot.plt)
290be288182SKees Cook	}
291be288182SKees Cook	ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!")
292be288182SKees Cook
293be288182SKees Cook	.data.rel.ro : { *(.data.rel.ro) }
294be288182SKees Cook	ASSERT(SIZEOF(.data.rel.ro) == 0, "Unexpected RELRO detected!")
2958c2c3df3SCatalin Marinas}
2962240bbb6SMarc Zyngier
29790776dd1SKees Cook#include "image-vars.h"
29890776dd1SKees Cook
2992240bbb6SMarc Zyngier/*
3005dfe9d7dSArd Biesheuvel * The HYP init code and ID map text can't be longer than a page each,
30106f75a1fSArd Biesheuvel * and should not cross a page boundary.
3022240bbb6SMarc Zyngier */
30306f75a1fSArd BiesheuvelASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
30406f75a1fSArd Biesheuvel	"HYP init code too big or misaligned")
3055dfe9d7dSArd BiesheuvelASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
3065dfe9d7dSArd Biesheuvel	"ID map text too big or misaligned")
30782869ac5SJames Morse#ifdef CONFIG_HIBERNATION
30882869ac5SJames MorseASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
30982869ac5SJames Morse	<= SZ_4K, "Hibernate exit text too big or misaligned")
31082869ac5SJames Morse#endif
3116c27c408SWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
3126c27c408SWill DeaconASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE,
3136c27c408SWill Deacon	"Entry trampoline text too big")
3146c27c408SWill Deacon#endif
315da57a369SMark Rutland/*
316da57a369SMark Rutland * If padding is applied before .head.text, virt<->phys conversions will fail.
317da57a369SMark Rutland */
318120dc60dSArd BiesheuvelASSERT(_text == KIMAGE_VADDR, "HEAD is misaligned")
319*00ef5434SJoey Gouly
320*00ef5434SJoey GoulyASSERT(swapper_pg_dir - reserved_pg_dir == RESERVED_SWAPPER_OFFSET,
321*00ef5434SJoey Gouly       "RESERVED_SWAPPER_OFFSET is wrong!")
322