xref: /openbmc/linux/arch/arm64/kernel/vmlinux.lds.S (revision 30c953911c4370bfb622ee1c2fcc7e78c84df800)
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
919f6bc32SKees Cook
108c2c3df3SCatalin Marinas#include <asm-generic/vmlinux.lds.h>
1198fb7548SArd Biesheuvel#include <asm/cache.h>
12ce492a16SDavid Brazdil#include <asm/hyp_image.h>
1387d1587bSSuzuki K. Poulose#include <asm/kernel-pgtable.h>
148c2c3df3SCatalin Marinas#include <asm/memory.h>
158c2c3df3SCatalin Marinas#include <asm/page.h>
168c2c3df3SCatalin Marinas
17a2c1d73bSMark Rutland#include "image.h"
18a2c1d73bSMark Rutland
198c2c3df3SCatalin MarinasOUTPUT_ARCH(aarch64)
20af885f40SGeoff LevandENTRY(_text)
218c2c3df3SCatalin Marinas
228c2c3df3SCatalin Marinasjiffies = jiffies_64;
238c2c3df3SCatalin Marinas
24e9ee186bSJames Morse
253471ee06SDavid Brazdil#ifdef CONFIG_KVM
26e9ee186bSJames Morse#define HYPERVISOR_EXTABLE					\
27e9ee186bSJames Morse	. = ALIGN(SZ_8);					\
28e9ee186bSJames Morse	__start___kvm_ex_table = .;				\
29e9ee186bSJames Morse	*(__kvm_ex_table)					\
30e9ee186bSJames Morse	__stop___kvm_ex_table = .;
31*30c95391SDavid Brazdil
32*30c95391SDavid Brazdil#define HYPERVISOR_PERCPU_SECTION				\
33*30c95391SDavid Brazdil	. = ALIGN(PAGE_SIZE);					\
34*30c95391SDavid Brazdil	HYP_SECTION_NAME(.data..percpu) : {			\
35*30c95391SDavid Brazdil		*(HYP_SECTION_NAME(.data..percpu))		\
36*30c95391SDavid Brazdil	}
373471ee06SDavid Brazdil#else /* CONFIG_KVM */
383471ee06SDavid Brazdil#define HYPERVISOR_EXTABLE
39*30c95391SDavid Brazdil#define HYPERVISOR_PERCPU_SECTION
403471ee06SDavid Brazdil#endif
41e9ee186bSJames Morse
422240bbb6SMarc Zyngier#define HYPERVISOR_TEXT					\
432240bbb6SMarc Zyngier	/*						\
4406f75a1fSArd Biesheuvel	 * Align to 4 KB so that			\
4506f75a1fSArd Biesheuvel	 * a) the HYP vector table is at its minimum	\
4606f75a1fSArd Biesheuvel	 *    alignment of 2048 bytes			\
4706f75a1fSArd Biesheuvel	 * b) the HYP init code will not cross a page	\
4806f75a1fSArd Biesheuvel	 *    boundary if its size does not exceed	\
4906f75a1fSArd Biesheuvel	 *    4 KB (see related ASSERT() below)		\
502240bbb6SMarc Zyngier	 */						\
5106f75a1fSArd Biesheuvel	. = ALIGN(SZ_4K);				\
525c636aa0SMasahiro Yamada	__hyp_idmap_text_start = .;			\
532240bbb6SMarc Zyngier	*(.hyp.idmap.text)				\
545c636aa0SMasahiro Yamada	__hyp_idmap_text_end = .;			\
555c636aa0SMasahiro Yamada	__hyp_text_start = .;				\
562240bbb6SMarc Zyngier	*(.hyp.text)					\
57e9ee186bSJames Morse	HYPERVISOR_EXTABLE				\
585c636aa0SMasahiro Yamada	__hyp_text_end = .;
592240bbb6SMarc Zyngier
605dfe9d7dSArd Biesheuvel#define IDMAP_TEXT					\
615dfe9d7dSArd Biesheuvel	. = ALIGN(SZ_4K);				\
625c636aa0SMasahiro Yamada	__idmap_text_start = .;				\
635dfe9d7dSArd Biesheuvel	*(.idmap.text)					\
645c636aa0SMasahiro Yamada	__idmap_text_end = .;
655dfe9d7dSArd Biesheuvel
6682869ac5SJames Morse#ifdef CONFIG_HIBERNATION
6782869ac5SJames Morse#define HIBERNATE_TEXT					\
6882869ac5SJames Morse	. = ALIGN(SZ_4K);				\
695c636aa0SMasahiro Yamada	__hibernate_exit_text_start = .;		\
7082869ac5SJames Morse	*(.hibernate_exit.text)				\
715c636aa0SMasahiro Yamada	__hibernate_exit_text_end = .;
7282869ac5SJames Morse#else
7382869ac5SJames Morse#define HIBERNATE_TEXT
7482869ac5SJames Morse#endif
7582869ac5SJames Morse
76c7b9adafSWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
77c7b9adafSWill Deacon#define TRAMP_TEXT					\
78c7b9adafSWill Deacon	. = ALIGN(PAGE_SIZE);				\
795c636aa0SMasahiro Yamada	__entry_tramp_text_start = .;			\
80c7b9adafSWill Deacon	*(.entry.tramp.text)				\
81c7b9adafSWill Deacon	. = ALIGN(PAGE_SIZE);				\
825c636aa0SMasahiro Yamada	__entry_tramp_text_end = .;
83c7b9adafSWill Deacon#else
84c7b9adafSWill Deacon#define TRAMP_TEXT
85c7b9adafSWill Deacon#endif
86c7b9adafSWill Deacon
87a352ea3eSArd Biesheuvel/*
88a352ea3eSArd Biesheuvel * The size of the PE/COFF section that covers the kernel image, which
89348a625dSArd Biesheuvel * runs from _stext to _edata, must be a round multiple of the PE/COFF
90348a625dSArd Biesheuvel * FileAlignment, which we set to its minimum value of 0x200. '_stext'
91a352ea3eSArd Biesheuvel * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
92a352ea3eSArd Biesheuvel * boundary should be sufficient.
93a352ea3eSArd Biesheuvel */
94a352ea3eSArd BiesheuvelPECOFF_FILE_ALIGNMENT = 0x200;
95a352ea3eSArd Biesheuvel
96a352ea3eSArd Biesheuvel#ifdef CONFIG_EFI
97a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING	\
98a352ea3eSArd Biesheuvel	.pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
99a352ea3eSArd Biesheuvel#else
100a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING
101a352ea3eSArd Biesheuvel#endif
102a352ea3eSArd Biesheuvel
1038c2c3df3SCatalin MarinasSECTIONS
1048c2c3df3SCatalin Marinas{
1058c2c3df3SCatalin Marinas	/*
1068c2c3df3SCatalin Marinas	 * XXX: The linker does not define how output sections are
1078c2c3df3SCatalin Marinas	 * assigned to input sections when there are multiple statements
1088c2c3df3SCatalin Marinas	 * matching the same input section name.  There is no documented
1098c2c3df3SCatalin Marinas	 * order of matching.
1108c2c3df3SCatalin Marinas	 */
1118c2c3df3SCatalin Marinas	/DISCARD/ : {
1128c2c3df3SCatalin Marinas		EXIT_CALL
1138c2c3df3SCatalin Marinas		*(.discard)
1148c2c3df3SCatalin Marinas		*(.discard.*)
1151e48ef7fSArd Biesheuvel		*(.interp .dynamic)
1163bbd3db8SArd Biesheuvel		*(.dynsym .dynstr .hash .gnu.hash)
1173bbd3db8SArd Biesheuvel		*(.eh_frame)
1188c2c3df3SCatalin Marinas	}
1198c2c3df3SCatalin Marinas
120ab893fb9SArd Biesheuvel	. = KIMAGE_VADDR + TEXT_OFFSET;
1218c2c3df3SCatalin Marinas
1228c2c3df3SCatalin Marinas	.head.text : {
1238c2c3df3SCatalin Marinas		_text = .;
1248c2c3df3SCatalin Marinas		HEAD_TEXT
1258c2c3df3SCatalin Marinas	}
1268c2c3df3SCatalin Marinas	.text : {			/* Real text segment		*/
1278c2c3df3SCatalin Marinas		_stext = .;		/* Text and read-only data	*/
1288c2c3df3SCatalin Marinas			IRQENTRY_TEXT
129be7635e7SAlexander Potapenko			SOFTIRQENTRY_TEXT
130888b3c87SPratyush Anand			ENTRY_TEXT
1318c2c3df3SCatalin Marinas			TEXT_TEXT
1328c2c3df3SCatalin Marinas			SCHED_TEXT
1336727ad9eSChris Metcalf			CPUIDLE_TEXT
1348c2c3df3SCatalin Marinas			LOCK_TEXT
1352dd0e8d2SSandeepa Prabhu			KPROBES_TEXT
1362240bbb6SMarc Zyngier			HYPERVISOR_TEXT
1375dfe9d7dSArd Biesheuvel			IDMAP_TEXT
13882869ac5SJames Morse			HIBERNATE_TEXT
139c7b9adafSWill Deacon			TRAMP_TEXT
1408c2c3df3SCatalin Marinas			*(.fixup)
1418c2c3df3SCatalin Marinas			*(.gnu.warning)
1428c2c3df3SCatalin Marinas		. = ALIGN(16);
1438c2c3df3SCatalin Marinas		*(.got)			/* Global offset table		*/
1448c2c3df3SCatalin Marinas	}
1458c2c3df3SCatalin Marinas
14697740051SArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
1479fdc14c5SArd Biesheuvel	_etext = .;			/* End of text section */
1489fdc14c5SArd Biesheuvel
14919f6bc32SKees Cook	/* everything from this point to __init_begin will be marked RO NX */
15019f6bc32SKees Cook	RO_DATA(PAGE_SIZE)
1518c2c3df3SCatalin Marinas
1528eb7e28dSJun Yao	idmap_pg_dir = .;
1538eb7e28dSJun Yao	. += IDMAP_DIR_SIZE;
1549d2d75edSGavin Shan	idmap_pg_end = .;
1558eb7e28dSJun Yao
1568eb7e28dSJun Yao#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
1578eb7e28dSJun Yao	tramp_pg_dir = .;
1588eb7e28dSJun Yao	. += PAGE_SIZE;
1598eb7e28dSJun Yao#endif
1608eb7e28dSJun Yao
1618eb7e28dSJun Yao#ifdef CONFIG_ARM64_SW_TTBR0_PAN
1628eb7e28dSJun Yao	reserved_ttbr0 = .;
1638eb7e28dSJun Yao	. += RESERVED_TTBR0_SIZE;
1648eb7e28dSJun Yao#endif
1658eb7e28dSJun Yao	swapper_pg_dir = .;
1668eb7e28dSJun Yao	. += PAGE_SIZE;
1678eb7e28dSJun Yao	swapper_pg_end = .;
1688eb7e28dSJun Yao
16997740051SArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
1708c2c3df3SCatalin Marinas	__init_begin = .;
1712ebe088bSArd Biesheuvel	__inittext_begin = .;
1728c2c3df3SCatalin Marinas
1738c2c3df3SCatalin Marinas	INIT_TEXT_SECTION(8)
174ca2ef4ffSMark Rutland
175ca2ef4ffSMark Rutland	__exittext_begin = .;
1768c2c3df3SCatalin Marinas	.exit.text : {
1771eae811dSArd Biesheuvel		EXIT_TEXT
1788c2c3df3SCatalin Marinas	}
179ca2ef4ffSMark Rutland	__exittext_end = .;
180da141706SLaura Abbott
1812ebe088bSArd Biesheuvel	. = ALIGN(4);
1822ebe088bSArd Biesheuvel	.altinstructions : {
1832ebe088bSArd Biesheuvel		__alt_instructions = .;
1842ebe088bSArd Biesheuvel		*(.altinstructions)
1852ebe088bSArd Biesheuvel		__alt_instructions_end = .;
1862ebe088bSArd Biesheuvel	}
1872ebe088bSArd Biesheuvel
18876085affSArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
1892ebe088bSArd Biesheuvel	__inittext_end = .;
1902ebe088bSArd Biesheuvel	__initdata_begin = .;
1912ebe088bSArd Biesheuvel
1928c2c3df3SCatalin Marinas	.init.data : {
1938c2c3df3SCatalin Marinas		INIT_DATA
1948c2c3df3SCatalin Marinas		INIT_SETUP(16)
1958c2c3df3SCatalin Marinas		INIT_CALLS
1968c2c3df3SCatalin Marinas		CON_INITCALL
1978c2c3df3SCatalin Marinas		INIT_RAM_FS
1981ce99bf4SArd Biesheuvel		*(.init.rodata.* .init.bss)	/* from the EFI stub */
1998c2c3df3SCatalin Marinas	}
2008c2c3df3SCatalin Marinas	.exit.data : {
2011eae811dSArd Biesheuvel		EXIT_DATA
2028c2c3df3SCatalin Marinas	}
2038c2c3df3SCatalin Marinas
20498fb7548SArd Biesheuvel	PERCPU_SECTION(L1_CACHE_BYTES)
205*30c95391SDavid Brazdil	HYPERVISOR_PERCPU_SECTION
2068c2c3df3SCatalin Marinas
2073bbd3db8SArd Biesheuvel	.rela.dyn : ALIGN(8) {
2081e48ef7fSArd Biesheuvel		*(.rela .rela*)
2091e48ef7fSArd Biesheuvel	}
210e039ee4eSAndre Przywara
2113bbd3db8SArd Biesheuvel	__rela_offset	= ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR);
2123bbd3db8SArd Biesheuvel	__rela_size	= SIZEOF(.rela.dyn);
2130cd3defeSArd Biesheuvel
2145cf896fbSPeter Collingbourne#ifdef CONFIG_RELR
2155cf896fbSPeter Collingbourne	.relr.dyn : ALIGN(8) {
2165cf896fbSPeter Collingbourne		*(.relr.dyn)
2175cf896fbSPeter Collingbourne	}
2185cf896fbSPeter Collingbourne
2195cf896fbSPeter Collingbourne	__relr_offset	= ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR);
2205cf896fbSPeter Collingbourne	__relr_size	= SIZEOF(.relr.dyn);
2215cf896fbSPeter Collingbourne#endif
2225cf896fbSPeter Collingbourne
22397740051SArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
2242ebe088bSArd Biesheuvel	__initdata_end = .;
2259aa4ec15SMark Rutland	__init_end = .;
2269aa4ec15SMark Rutland
2273c620626SMark Salter	_data = .;
2288c2c3df3SCatalin Marinas	_sdata = .;
229c9174047SKees Cook	RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
230b6113038SJames Morse
231b6113038SJames Morse	/*
232b6113038SJames Morse	 * Data written with the MMU off but read with the MMU on requires
233b6113038SJames Morse	 * cache lines to be invalidated, discarding up to a Cache Writeback
234b6113038SJames Morse	 * Granule (CWG) of data from the cache. Keep the section that
235b6113038SJames Morse	 * requires this type of maintenance to be in its own Cache Writeback
236b6113038SJames Morse	 * Granule (CWG) area so the cache maintenance operations don't
237b6113038SJames Morse	 * interfere with adjacent data.
238b6113038SJames Morse	 */
239b6113038SJames Morse	.mmuoff.data.write : ALIGN(SZ_2K) {
240b6113038SJames Morse		__mmuoff_data_start = .;
241b6113038SJames Morse		*(.mmuoff.data.write)
242b6113038SJames Morse	}
243b6113038SJames Morse	. = ALIGN(SZ_2K);
244b6113038SJames Morse	.mmuoff.data.read : {
245b6113038SJames Morse		*(.mmuoff.data.read)
246b6113038SJames Morse		__mmuoff_data_end = .;
247b6113038SJames Morse	}
248b6113038SJames Morse
249a352ea3eSArd Biesheuvel	PECOFF_EDATA_PADDING
250cad27ef2SArd Biesheuvel	__pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
2518c2c3df3SCatalin Marinas	_edata = .;
2528c2c3df3SCatalin Marinas
2538c2c3df3SCatalin Marinas	BSS_SECTION(0, 0, 0)
254bd00cd5fSMark Rutland
255bd00cd5fSMark Rutland	. = ALIGN(PAGE_SIZE);
2562b5548b6SJun Yao	init_pg_dir = .;
2572b5548b6SJun Yao	. += INIT_DIR_SIZE;
2582b5548b6SJun Yao	init_pg_end = .;
2592b5548b6SJun Yao
26076085affSArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
261cad27ef2SArd Biesheuvel	__pecoff_data_size = ABSOLUTE(. - __initdata_begin);
2628c2c3df3SCatalin Marinas	_end = .;
2638c2c3df3SCatalin Marinas
2648c2c3df3SCatalin Marinas	STABS_DEBUG
265a2c1d73bSMark Rutland
266a2c1d73bSMark Rutland	HEAD_SYMBOLS
2678c2c3df3SCatalin Marinas}
2682240bbb6SMarc Zyngier
26990776dd1SKees Cook#include "image-vars.h"
27090776dd1SKees Cook
2712240bbb6SMarc Zyngier/*
2725dfe9d7dSArd Biesheuvel * The HYP init code and ID map text can't be longer than a page each,
27306f75a1fSArd Biesheuvel * and should not cross a page boundary.
2742240bbb6SMarc Zyngier */
27506f75a1fSArd BiesheuvelASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
27606f75a1fSArd Biesheuvel	"HYP init code too big or misaligned")
2775dfe9d7dSArd BiesheuvelASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
2785dfe9d7dSArd Biesheuvel	"ID map text too big or misaligned")
27982869ac5SJames Morse#ifdef CONFIG_HIBERNATION
28082869ac5SJames MorseASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
28182869ac5SJames Morse	<= SZ_4K, "Hibernate exit text too big or misaligned")
28282869ac5SJames Morse#endif
2836c27c408SWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
2846c27c408SWill DeaconASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE,
2856c27c408SWill Deacon	"Entry trampoline text too big")
2866c27c408SWill Deacon#endif
287da57a369SMark Rutland/*
288da57a369SMark Rutland * If padding is applied before .head.text, virt<->phys conversions will fail.
289da57a369SMark Rutland */
290ab893fb9SArd BiesheuvelASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned")
291