xref: /openbmc/linux/arch/arm64/kernel/vmlinux.lds.S (revision e2a073dde9218cdef3c5431bddabf4549dd65fea)
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 = .;
32e9ee186bSJames Morse
3330c95391SDavid Brazdil#define HYPERVISOR_PERCPU_SECTION				\
3430c95391SDavid Brazdil	. = ALIGN(PAGE_SIZE);					\
3530c95391SDavid Brazdil	HYP_SECTION_NAME(.data..percpu) : {			\
3630c95391SDavid Brazdil		*(HYP_SECTION_NAME(.data..percpu))		\
3730c95391SDavid Brazdil	}
383471ee06SDavid Brazdil#else /* CONFIG_KVM */
393471ee06SDavid Brazdil#define HYPERVISOR_EXTABLE
4030c95391SDavid Brazdil#define HYPERVISOR_PERCPU_SECTION
413471ee06SDavid Brazdil#endif
428c2c3df3SCatalin Marinas
432240bbb6SMarc Zyngier#define HYPERVISOR_TEXT					\
442240bbb6SMarc Zyngier	/*						\
4506f75a1fSArd Biesheuvel	 * Align to 4 KB so that			\
4606f75a1fSArd Biesheuvel	 * a) the HYP vector table is at its minimum	\
4706f75a1fSArd Biesheuvel	 *    alignment of 2048 bytes			\
4806f75a1fSArd Biesheuvel	 * b) the HYP init code will not cross a page	\
4906f75a1fSArd Biesheuvel	 *    boundary if its size does not exceed	\
5006f75a1fSArd Biesheuvel	 *    4 KB (see related ASSERT() below)		\
512240bbb6SMarc Zyngier	 */						\
5206f75a1fSArd Biesheuvel	. = ALIGN(SZ_4K);				\
535c636aa0SMasahiro Yamada	__hyp_idmap_text_start = .;			\
542240bbb6SMarc Zyngier	*(.hyp.idmap.text)				\
555c636aa0SMasahiro Yamada	__hyp_idmap_text_end = .;			\
565c636aa0SMasahiro Yamada	__hyp_text_start = .;				\
572240bbb6SMarc Zyngier	*(.hyp.text)					\
58e9ee186bSJames Morse	HYPERVISOR_EXTABLE				\
595c636aa0SMasahiro Yamada	__hyp_text_end = .;
602240bbb6SMarc Zyngier
615dfe9d7dSArd Biesheuvel#define IDMAP_TEXT					\
625dfe9d7dSArd Biesheuvel	. = ALIGN(SZ_4K);				\
635c636aa0SMasahiro Yamada	__idmap_text_start = .;				\
645dfe9d7dSArd Biesheuvel	*(.idmap.text)					\
655c636aa0SMasahiro Yamada	__idmap_text_end = .;
665dfe9d7dSArd Biesheuvel
6782869ac5SJames Morse#ifdef CONFIG_HIBERNATION
6882869ac5SJames Morse#define HIBERNATE_TEXT					\
6982869ac5SJames Morse	. = ALIGN(SZ_4K);				\
705c636aa0SMasahiro Yamada	__hibernate_exit_text_start = .;		\
7182869ac5SJames Morse	*(.hibernate_exit.text)				\
725c636aa0SMasahiro Yamada	__hibernate_exit_text_end = .;
7382869ac5SJames Morse#else
7482869ac5SJames Morse#define HIBERNATE_TEXT
7582869ac5SJames Morse#endif
7682869ac5SJames Morse
77c7b9adafSWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
78c7b9adafSWill Deacon#define TRAMP_TEXT					\
79c7b9adafSWill Deacon	. = ALIGN(PAGE_SIZE);				\
805c636aa0SMasahiro Yamada	__entry_tramp_text_start = .;			\
81c7b9adafSWill Deacon	*(.entry.tramp.text)				\
82c7b9adafSWill Deacon	. = ALIGN(PAGE_SIZE);				\
835c636aa0SMasahiro Yamada	__entry_tramp_text_end = .;
84c7b9adafSWill Deacon#else
85c7b9adafSWill Deacon#define TRAMP_TEXT
86c7b9adafSWill Deacon#endif
87c7b9adafSWill Deacon
88a352ea3eSArd Biesheuvel/*
89a352ea3eSArd Biesheuvel * The size of the PE/COFF section that covers the kernel image, which
90348a625dSArd Biesheuvel * runs from _stext to _edata, must be a round multiple of the PE/COFF
91348a625dSArd Biesheuvel * FileAlignment, which we set to its minimum value of 0x200. '_stext'
92a352ea3eSArd Biesheuvel * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
93a352ea3eSArd Biesheuvel * boundary should be sufficient.
94a352ea3eSArd Biesheuvel */
95a352ea3eSArd BiesheuvelPECOFF_FILE_ALIGNMENT = 0x200;
96a352ea3eSArd Biesheuvel
97a352ea3eSArd Biesheuvel#ifdef CONFIG_EFI
98a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING	\
99a352ea3eSArd Biesheuvel	.pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
100a352ea3eSArd Biesheuvel#else
101a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING
102a352ea3eSArd Biesheuvel#endif
103a352ea3eSArd Biesheuvel
1048c2c3df3SCatalin MarinasSECTIONS
1058c2c3df3SCatalin Marinas{
1068c2c3df3SCatalin Marinas	/*
1078c2c3df3SCatalin Marinas	 * XXX: The linker does not define how output sections are
1088c2c3df3SCatalin Marinas	 * assigned to input sections when there are multiple statements
1098c2c3df3SCatalin Marinas	 * matching the same input section name.  There is no documented
1108c2c3df3SCatalin Marinas	 * order of matching.
1118c2c3df3SCatalin Marinas	 */
1122883352bSKees Cook	DISCARDS
1138c2c3df3SCatalin Marinas	/DISCARD/ : {
1141e48ef7fSArd Biesheuvel		*(.interp .dynamic)
1153bbd3db8SArd Biesheuvel		*(.dynsym .dynstr .hash .gnu.hash)
1168c2c3df3SCatalin Marinas	}
1178c2c3df3SCatalin Marinas
118120dc60dSArd Biesheuvel	. = KIMAGE_VADDR;
1198c2c3df3SCatalin Marinas
1208c2c3df3SCatalin Marinas	.head.text : {
1218c2c3df3SCatalin Marinas		_text = .;
1228c2c3df3SCatalin Marinas		HEAD_TEXT
1238c2c3df3SCatalin Marinas	}
124*e2a073ddSArd Biesheuvel	.text : ALIGN(SEGMENT_ALIGN) {	/* Real text segment		*/
1258c2c3df3SCatalin Marinas		_stext = .;		/* Text and read-only data	*/
1268c2c3df3SCatalin Marinas			IRQENTRY_TEXT
127be7635e7SAlexander Potapenko			SOFTIRQENTRY_TEXT
128888b3c87SPratyush Anand			ENTRY_TEXT
1298c2c3df3SCatalin Marinas			TEXT_TEXT
1308c2c3df3SCatalin Marinas			SCHED_TEXT
1316727ad9eSChris Metcalf			CPUIDLE_TEXT
1328c2c3df3SCatalin Marinas			LOCK_TEXT
1332dd0e8d2SSandeepa Prabhu			KPROBES_TEXT
1342240bbb6SMarc Zyngier			HYPERVISOR_TEXT
1355dfe9d7dSArd Biesheuvel			IDMAP_TEXT
13682869ac5SJames Morse			HIBERNATE_TEXT
137c7b9adafSWill Deacon			TRAMP_TEXT
1388c2c3df3SCatalin Marinas			*(.fixup)
1398c2c3df3SCatalin Marinas			*(.gnu.warning)
1408c2c3df3SCatalin Marinas		. = ALIGN(16);
1418c2c3df3SCatalin Marinas		*(.got)			/* Global offset table		*/
1428c2c3df3SCatalin Marinas	}
1438c2c3df3SCatalin Marinas
144be288182SKees Cook	/*
145be288182SKees Cook	 * Make sure that the .got.plt is either completely empty or it
146be288182SKees Cook	 * contains only the lazy dispatch entries.
147be288182SKees Cook	 */
148be288182SKees Cook	.got.plt : { *(.got.plt) }
149be288182SKees Cook	ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18,
150be288182SKees Cook	       "Unexpected GOT/PLT entries detected!")
151be288182SKees Cook
15297740051SArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
1539fdc14c5SArd Biesheuvel	_etext = .;			/* End of text section */
1549fdc14c5SArd Biesheuvel
15519f6bc32SKees Cook	/* everything from this point to __init_begin will be marked RO NX */
15619f6bc32SKees Cook	RO_DATA(PAGE_SIZE)
1578c2c3df3SCatalin Marinas
1588eb7e28dSJun Yao	idmap_pg_dir = .;
1598eb7e28dSJun Yao	. += IDMAP_DIR_SIZE;
1609d2d75edSGavin Shan	idmap_pg_end = .;
1618eb7e28dSJun Yao
1628eb7e28dSJun Yao#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
1638eb7e28dSJun Yao	tramp_pg_dir = .;
1648eb7e28dSJun Yao	. += PAGE_SIZE;
1658eb7e28dSJun Yao#endif
1668eb7e28dSJun Yao
1678eb7e28dSJun Yao#ifdef CONFIG_ARM64_SW_TTBR0_PAN
1688eb7e28dSJun Yao	reserved_ttbr0 = .;
1698eb7e28dSJun Yao	. += RESERVED_TTBR0_SIZE;
1708eb7e28dSJun Yao#endif
1718eb7e28dSJun Yao	swapper_pg_dir = .;
1728eb7e28dSJun Yao	. += PAGE_SIZE;
1738eb7e28dSJun Yao	swapper_pg_end = .;
1748eb7e28dSJun Yao
17597740051SArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
1768c2c3df3SCatalin Marinas	__init_begin = .;
1772ebe088bSArd Biesheuvel	__inittext_begin = .;
1788c2c3df3SCatalin Marinas
1798c2c3df3SCatalin Marinas	INIT_TEXT_SECTION(8)
180ca2ef4ffSMark Rutland
181ca2ef4ffSMark Rutland	__exittext_begin = .;
1828c2c3df3SCatalin Marinas	.exit.text : {
1831eae811dSArd Biesheuvel		EXIT_TEXT
1848c2c3df3SCatalin Marinas	}
185ca2ef4ffSMark Rutland	__exittext_end = .;
186da141706SLaura Abbott
1872ebe088bSArd Biesheuvel	. = ALIGN(4);
1882ebe088bSArd Biesheuvel	.altinstructions : {
1892ebe088bSArd Biesheuvel		__alt_instructions = .;
1902ebe088bSArd Biesheuvel		*(.altinstructions)
1912ebe088bSArd Biesheuvel		__alt_instructions_end = .;
1922ebe088bSArd Biesheuvel	}
1932ebe088bSArd Biesheuvel
19476085affSArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
1952ebe088bSArd Biesheuvel	__inittext_end = .;
1962ebe088bSArd Biesheuvel	__initdata_begin = .;
1972ebe088bSArd Biesheuvel
1988c2c3df3SCatalin Marinas	.init.data : {
1998c2c3df3SCatalin Marinas		INIT_DATA
2008c2c3df3SCatalin Marinas		INIT_SETUP(16)
2018c2c3df3SCatalin Marinas		INIT_CALLS
2028c2c3df3SCatalin Marinas		CON_INITCALL
2038c2c3df3SCatalin Marinas		INIT_RAM_FS
2041ce99bf4SArd Biesheuvel		*(.init.rodata.* .init.bss)	/* from the EFI stub */
2058c2c3df3SCatalin Marinas	}
2068c2c3df3SCatalin Marinas	.exit.data : {
2071eae811dSArd Biesheuvel		EXIT_DATA
2088c2c3df3SCatalin Marinas	}
2098c2c3df3SCatalin Marinas
21098fb7548SArd Biesheuvel	PERCPU_SECTION(L1_CACHE_BYTES)
21130c95391SDavid Brazdil	HYPERVISOR_PERCPU_SECTION
2128c2c3df3SCatalin Marinas
2133bbd3db8SArd Biesheuvel	.rela.dyn : ALIGN(8) {
2141e48ef7fSArd Biesheuvel		*(.rela .rela*)
2151e48ef7fSArd Biesheuvel	}
216e039ee4eSAndre Przywara
2173bbd3db8SArd Biesheuvel	__rela_offset	= ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR);
2183bbd3db8SArd Biesheuvel	__rela_size	= SIZEOF(.rela.dyn);
2190cd3defeSArd Biesheuvel
2205cf896fbSPeter Collingbourne#ifdef CONFIG_RELR
2215cf896fbSPeter Collingbourne	.relr.dyn : ALIGN(8) {
2225cf896fbSPeter Collingbourne		*(.relr.dyn)
2235cf896fbSPeter Collingbourne	}
2245cf896fbSPeter Collingbourne
2255cf896fbSPeter Collingbourne	__relr_offset	= ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR);
2265cf896fbSPeter Collingbourne	__relr_size	= SIZEOF(.relr.dyn);
2275cf896fbSPeter Collingbourne#endif
2285cf896fbSPeter Collingbourne
22997740051SArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
2302ebe088bSArd Biesheuvel	__initdata_end = .;
2319aa4ec15SMark Rutland	__init_end = .;
2329aa4ec15SMark Rutland
2333c620626SMark Salter	_data = .;
2348c2c3df3SCatalin Marinas	_sdata = .;
235c9174047SKees Cook	RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
236b6113038SJames Morse
237b6113038SJames Morse	/*
238b6113038SJames Morse	 * Data written with the MMU off but read with the MMU on requires
239b6113038SJames Morse	 * cache lines to be invalidated, discarding up to a Cache Writeback
240b6113038SJames Morse	 * Granule (CWG) of data from the cache. Keep the section that
241b6113038SJames Morse	 * requires this type of maintenance to be in its own Cache Writeback
242b6113038SJames Morse	 * Granule (CWG) area so the cache maintenance operations don't
243b6113038SJames Morse	 * interfere with adjacent data.
244b6113038SJames Morse	 */
245b6113038SJames Morse	.mmuoff.data.write : ALIGN(SZ_2K) {
246b6113038SJames Morse		__mmuoff_data_start = .;
247b6113038SJames Morse		*(.mmuoff.data.write)
248b6113038SJames Morse	}
249b6113038SJames Morse	. = ALIGN(SZ_2K);
250b6113038SJames Morse	.mmuoff.data.read : {
251b6113038SJames Morse		*(.mmuoff.data.read)
252b6113038SJames Morse		__mmuoff_data_end = .;
253b6113038SJames Morse	}
254b6113038SJames Morse
255a352ea3eSArd Biesheuvel	PECOFF_EDATA_PADDING
256cad27ef2SArd Biesheuvel	__pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
2578c2c3df3SCatalin Marinas	_edata = .;
2588c2c3df3SCatalin Marinas
2598c2c3df3SCatalin Marinas	BSS_SECTION(0, 0, 0)
260bd00cd5fSMark Rutland
261bd00cd5fSMark Rutland	. = ALIGN(PAGE_SIZE);
2622b5548b6SJun Yao	init_pg_dir = .;
2632b5548b6SJun Yao	. += INIT_DIR_SIZE;
2642b5548b6SJun Yao	init_pg_end = .;
2652b5548b6SJun Yao
26676085affSArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
267cad27ef2SArd Biesheuvel	__pecoff_data_size = ABSOLUTE(. - __initdata_begin);
2688c2c3df3SCatalin Marinas	_end = .;
2698c2c3df3SCatalin Marinas
2708c2c3df3SCatalin Marinas	STABS_DEBUG
271578d7f0fSKees Cook	DWARF_DEBUG
272c604abc3SKees Cook	ELF_DETAILS
273a2c1d73bSMark Rutland
274a2c1d73bSMark Rutland	HEAD_SYMBOLS
275be288182SKees Cook
276be288182SKees Cook	/*
277be288182SKees Cook	 * Sections that should stay zero sized, which is safer to
278be288182SKees Cook	 * explicitly check instead of blindly discarding.
279be288182SKees Cook	 */
280be288182SKees Cook	.plt : {
2815f692a81SArd Biesheuvel		*(.plt) *(.plt.*) *(.iplt) *(.igot .igot.plt)
282be288182SKees Cook	}
283be288182SKees Cook	ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!")
284be288182SKees Cook
285be288182SKees Cook	.data.rel.ro : { *(.data.rel.ro) }
286be288182SKees Cook	ASSERT(SIZEOF(.data.rel.ro) == 0, "Unexpected RELRO detected!")
2878c2c3df3SCatalin Marinas}
2882240bbb6SMarc Zyngier
28990776dd1SKees Cook#include "image-vars.h"
29090776dd1SKees Cook
2912240bbb6SMarc Zyngier/*
2925dfe9d7dSArd Biesheuvel * The HYP init code and ID map text can't be longer than a page each,
29306f75a1fSArd Biesheuvel * and should not cross a page boundary.
2942240bbb6SMarc Zyngier */
29506f75a1fSArd BiesheuvelASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
29606f75a1fSArd Biesheuvel	"HYP init code too big or misaligned")
2975dfe9d7dSArd BiesheuvelASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
2985dfe9d7dSArd Biesheuvel	"ID map text too big or misaligned")
29982869ac5SJames Morse#ifdef CONFIG_HIBERNATION
30082869ac5SJames MorseASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
30182869ac5SJames Morse	<= SZ_4K, "Hibernate exit text too big or misaligned")
30282869ac5SJames Morse#endif
3036c27c408SWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
3046c27c408SWill DeaconASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE,
3056c27c408SWill Deacon	"Entry trampoline text too big")
3066c27c408SWill Deacon#endif
307da57a369SMark Rutland/*
308da57a369SMark Rutland * If padding is applied before .head.text, virt<->phys conversions will fail.
309da57a369SMark Rutland */
310120dc60dSArd BiesheuvelASSERT(_text == KIMAGE_VADDR, "HEAD is misaligned")
311