xref: /openbmc/linux/arch/arm64/kernel/vmlinux.lds.S (revision e9ee186bb735bfc17fa81dbc9aebf268aee5b41e)
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>
1287d1587bSSuzuki K. Poulose#include <asm/kernel-pgtable.h>
138c2c3df3SCatalin Marinas#include <asm/memory.h>
148c2c3df3SCatalin Marinas#include <asm/page.h>
158c2c3df3SCatalin Marinas
16a2c1d73bSMark Rutland#include "image.h"
17a2c1d73bSMark Rutland
188c2c3df3SCatalin MarinasOUTPUT_ARCH(aarch64)
19af885f40SGeoff LevandENTRY(_text)
208c2c3df3SCatalin Marinas
218c2c3df3SCatalin Marinasjiffies = jiffies_64;
228c2c3df3SCatalin Marinas
23*e9ee186bSJames Morse
24*e9ee186bSJames Morse#define HYPERVISOR_EXTABLE					\
25*e9ee186bSJames Morse	. = ALIGN(SZ_8);					\
26*e9ee186bSJames Morse	__start___kvm_ex_table = .;				\
27*e9ee186bSJames Morse	*(__kvm_ex_table)					\
28*e9ee186bSJames Morse	__stop___kvm_ex_table = .;
29*e9ee186bSJames Morse
302240bbb6SMarc Zyngier#define HYPERVISOR_TEXT					\
312240bbb6SMarc Zyngier	/*						\
3206f75a1fSArd Biesheuvel	 * Align to 4 KB so that			\
3306f75a1fSArd Biesheuvel	 * a) the HYP vector table is at its minimum	\
3406f75a1fSArd Biesheuvel	 *    alignment of 2048 bytes			\
3506f75a1fSArd Biesheuvel	 * b) the HYP init code will not cross a page	\
3606f75a1fSArd Biesheuvel	 *    boundary if its size does not exceed	\
3706f75a1fSArd Biesheuvel	 *    4 KB (see related ASSERT() below)		\
382240bbb6SMarc Zyngier	 */						\
3906f75a1fSArd Biesheuvel	. = ALIGN(SZ_4K);				\
405c636aa0SMasahiro Yamada	__hyp_idmap_text_start = .;			\
412240bbb6SMarc Zyngier	*(.hyp.idmap.text)				\
425c636aa0SMasahiro Yamada	__hyp_idmap_text_end = .;			\
435c636aa0SMasahiro Yamada	__hyp_text_start = .;				\
442240bbb6SMarc Zyngier	*(.hyp.text)					\
45*e9ee186bSJames Morse	HYPERVISOR_EXTABLE				\
465c636aa0SMasahiro Yamada	__hyp_text_end = .;
472240bbb6SMarc Zyngier
485dfe9d7dSArd Biesheuvel#define IDMAP_TEXT					\
495dfe9d7dSArd Biesheuvel	. = ALIGN(SZ_4K);				\
505c636aa0SMasahiro Yamada	__idmap_text_start = .;				\
515dfe9d7dSArd Biesheuvel	*(.idmap.text)					\
525c636aa0SMasahiro Yamada	__idmap_text_end = .;
535dfe9d7dSArd Biesheuvel
5482869ac5SJames Morse#ifdef CONFIG_HIBERNATION
5582869ac5SJames Morse#define HIBERNATE_TEXT					\
5682869ac5SJames Morse	. = ALIGN(SZ_4K);				\
575c636aa0SMasahiro Yamada	__hibernate_exit_text_start = .;		\
5882869ac5SJames Morse	*(.hibernate_exit.text)				\
595c636aa0SMasahiro Yamada	__hibernate_exit_text_end = .;
6082869ac5SJames Morse#else
6182869ac5SJames Morse#define HIBERNATE_TEXT
6282869ac5SJames Morse#endif
6382869ac5SJames Morse
64c7b9adafSWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
65c7b9adafSWill Deacon#define TRAMP_TEXT					\
66c7b9adafSWill Deacon	. = ALIGN(PAGE_SIZE);				\
675c636aa0SMasahiro Yamada	__entry_tramp_text_start = .;			\
68c7b9adafSWill Deacon	*(.entry.tramp.text)				\
69c7b9adafSWill Deacon	. = ALIGN(PAGE_SIZE);				\
705c636aa0SMasahiro Yamada	__entry_tramp_text_end = .;
71c7b9adafSWill Deacon#else
72c7b9adafSWill Deacon#define TRAMP_TEXT
73c7b9adafSWill Deacon#endif
74c7b9adafSWill Deacon
75a352ea3eSArd Biesheuvel/*
76a352ea3eSArd Biesheuvel * The size of the PE/COFF section that covers the kernel image, which
77348a625dSArd Biesheuvel * runs from _stext to _edata, must be a round multiple of the PE/COFF
78348a625dSArd Biesheuvel * FileAlignment, which we set to its minimum value of 0x200. '_stext'
79a352ea3eSArd Biesheuvel * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
80a352ea3eSArd Biesheuvel * boundary should be sufficient.
81a352ea3eSArd Biesheuvel */
82a352ea3eSArd BiesheuvelPECOFF_FILE_ALIGNMENT = 0x200;
83a352ea3eSArd Biesheuvel
84a352ea3eSArd Biesheuvel#ifdef CONFIG_EFI
85a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING	\
86a352ea3eSArd Biesheuvel	.pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
87a352ea3eSArd Biesheuvel#else
88a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING
89a352ea3eSArd Biesheuvel#endif
90a352ea3eSArd Biesheuvel
918c2c3df3SCatalin MarinasSECTIONS
928c2c3df3SCatalin Marinas{
938c2c3df3SCatalin Marinas	/*
948c2c3df3SCatalin Marinas	 * XXX: The linker does not define how output sections are
958c2c3df3SCatalin Marinas	 * assigned to input sections when there are multiple statements
968c2c3df3SCatalin Marinas	 * matching the same input section name.  There is no documented
978c2c3df3SCatalin Marinas	 * order of matching.
988c2c3df3SCatalin Marinas	 */
998c2c3df3SCatalin Marinas	/DISCARD/ : {
1008c2c3df3SCatalin Marinas		EXIT_CALL
1018c2c3df3SCatalin Marinas		*(.discard)
1028c2c3df3SCatalin Marinas		*(.discard.*)
1031e48ef7fSArd Biesheuvel		*(.interp .dynamic)
1043bbd3db8SArd Biesheuvel		*(.dynsym .dynstr .hash .gnu.hash)
1053bbd3db8SArd Biesheuvel		*(.eh_frame)
1068c2c3df3SCatalin Marinas	}
1078c2c3df3SCatalin Marinas
108ab893fb9SArd Biesheuvel	. = KIMAGE_VADDR + TEXT_OFFSET;
1098c2c3df3SCatalin Marinas
1108c2c3df3SCatalin Marinas	.head.text : {
1118c2c3df3SCatalin Marinas		_text = .;
1128c2c3df3SCatalin Marinas		HEAD_TEXT
1138c2c3df3SCatalin Marinas	}
1148c2c3df3SCatalin Marinas	.text : {			/* Real text segment		*/
1158c2c3df3SCatalin Marinas		_stext = .;		/* Text and read-only data	*/
1168c2c3df3SCatalin Marinas			IRQENTRY_TEXT
117be7635e7SAlexander Potapenko			SOFTIRQENTRY_TEXT
118888b3c87SPratyush Anand			ENTRY_TEXT
1198c2c3df3SCatalin Marinas			TEXT_TEXT
1208c2c3df3SCatalin Marinas			SCHED_TEXT
1216727ad9eSChris Metcalf			CPUIDLE_TEXT
1228c2c3df3SCatalin Marinas			LOCK_TEXT
1232dd0e8d2SSandeepa Prabhu			KPROBES_TEXT
1242240bbb6SMarc Zyngier			HYPERVISOR_TEXT
1255dfe9d7dSArd Biesheuvel			IDMAP_TEXT
12682869ac5SJames Morse			HIBERNATE_TEXT
127c7b9adafSWill Deacon			TRAMP_TEXT
1288c2c3df3SCatalin Marinas			*(.fixup)
1298c2c3df3SCatalin Marinas			*(.gnu.warning)
1308c2c3df3SCatalin Marinas		. = ALIGN(16);
1318c2c3df3SCatalin Marinas		*(.got)			/* Global offset table		*/
1328c2c3df3SCatalin Marinas	}
1338c2c3df3SCatalin Marinas
13497740051SArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
1359fdc14c5SArd Biesheuvel	_etext = .;			/* End of text section */
1369fdc14c5SArd Biesheuvel
13719f6bc32SKees Cook	/* everything from this point to __init_begin will be marked RO NX */
13819f6bc32SKees Cook	RO_DATA(PAGE_SIZE)
1398c2c3df3SCatalin Marinas
1408eb7e28dSJun Yao	idmap_pg_dir = .;
1418eb7e28dSJun Yao	. += IDMAP_DIR_SIZE;
1429d2d75edSGavin Shan	idmap_pg_end = .;
1438eb7e28dSJun Yao
1448eb7e28dSJun Yao#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
1458eb7e28dSJun Yao	tramp_pg_dir = .;
1468eb7e28dSJun Yao	. += PAGE_SIZE;
1478eb7e28dSJun Yao#endif
1488eb7e28dSJun Yao
1498eb7e28dSJun Yao#ifdef CONFIG_ARM64_SW_TTBR0_PAN
1508eb7e28dSJun Yao	reserved_ttbr0 = .;
1518eb7e28dSJun Yao	. += RESERVED_TTBR0_SIZE;
1528eb7e28dSJun Yao#endif
1538eb7e28dSJun Yao	swapper_pg_dir = .;
1548eb7e28dSJun Yao	. += PAGE_SIZE;
1558eb7e28dSJun Yao	swapper_pg_end = .;
1568eb7e28dSJun Yao
15797740051SArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
1588c2c3df3SCatalin Marinas	__init_begin = .;
1592ebe088bSArd Biesheuvel	__inittext_begin = .;
1608c2c3df3SCatalin Marinas
1618c2c3df3SCatalin Marinas	INIT_TEXT_SECTION(8)
162ca2ef4ffSMark Rutland
163ca2ef4ffSMark Rutland	__exittext_begin = .;
1648c2c3df3SCatalin Marinas	.exit.text : {
1651eae811dSArd Biesheuvel		EXIT_TEXT
1668c2c3df3SCatalin Marinas	}
167ca2ef4ffSMark Rutland	__exittext_end = .;
168da141706SLaura Abbott
1692ebe088bSArd Biesheuvel	. = ALIGN(4);
1702ebe088bSArd Biesheuvel	.altinstructions : {
1712ebe088bSArd Biesheuvel		__alt_instructions = .;
1722ebe088bSArd Biesheuvel		*(.altinstructions)
1732ebe088bSArd Biesheuvel		__alt_instructions_end = .;
1742ebe088bSArd Biesheuvel	}
1752ebe088bSArd Biesheuvel
17676085affSArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
1772ebe088bSArd Biesheuvel	__inittext_end = .;
1782ebe088bSArd Biesheuvel	__initdata_begin = .;
1792ebe088bSArd Biesheuvel
1808c2c3df3SCatalin Marinas	.init.data : {
1818c2c3df3SCatalin Marinas		INIT_DATA
1828c2c3df3SCatalin Marinas		INIT_SETUP(16)
1838c2c3df3SCatalin Marinas		INIT_CALLS
1848c2c3df3SCatalin Marinas		CON_INITCALL
1858c2c3df3SCatalin Marinas		INIT_RAM_FS
1861ce99bf4SArd Biesheuvel		*(.init.rodata.* .init.bss)	/* from the EFI stub */
1878c2c3df3SCatalin Marinas	}
1888c2c3df3SCatalin Marinas	.exit.data : {
1891eae811dSArd Biesheuvel		EXIT_DATA
1908c2c3df3SCatalin Marinas	}
1918c2c3df3SCatalin Marinas
19298fb7548SArd Biesheuvel	PERCPU_SECTION(L1_CACHE_BYTES)
1938c2c3df3SCatalin Marinas
1943bbd3db8SArd Biesheuvel	.rela.dyn : ALIGN(8) {
1951e48ef7fSArd Biesheuvel		*(.rela .rela*)
1961e48ef7fSArd Biesheuvel	}
197e039ee4eSAndre Przywara
1983bbd3db8SArd Biesheuvel	__rela_offset	= ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR);
1993bbd3db8SArd Biesheuvel	__rela_size	= SIZEOF(.rela.dyn);
2000cd3defeSArd Biesheuvel
2015cf896fbSPeter Collingbourne#ifdef CONFIG_RELR
2025cf896fbSPeter Collingbourne	.relr.dyn : ALIGN(8) {
2035cf896fbSPeter Collingbourne		*(.relr.dyn)
2045cf896fbSPeter Collingbourne	}
2055cf896fbSPeter Collingbourne
2065cf896fbSPeter Collingbourne	__relr_offset	= ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR);
2075cf896fbSPeter Collingbourne	__relr_size	= SIZEOF(.relr.dyn);
2085cf896fbSPeter Collingbourne#endif
2095cf896fbSPeter Collingbourne
21097740051SArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
2112ebe088bSArd Biesheuvel	__initdata_end = .;
2129aa4ec15SMark Rutland	__init_end = .;
2139aa4ec15SMark Rutland
2143c620626SMark Salter	_data = .;
2158c2c3df3SCatalin Marinas	_sdata = .;
216c9174047SKees Cook	RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
217b6113038SJames Morse
218b6113038SJames Morse	/*
219b6113038SJames Morse	 * Data written with the MMU off but read with the MMU on requires
220b6113038SJames Morse	 * cache lines to be invalidated, discarding up to a Cache Writeback
221b6113038SJames Morse	 * Granule (CWG) of data from the cache. Keep the section that
222b6113038SJames Morse	 * requires this type of maintenance to be in its own Cache Writeback
223b6113038SJames Morse	 * Granule (CWG) area so the cache maintenance operations don't
224b6113038SJames Morse	 * interfere with adjacent data.
225b6113038SJames Morse	 */
226b6113038SJames Morse	.mmuoff.data.write : ALIGN(SZ_2K) {
227b6113038SJames Morse		__mmuoff_data_start = .;
228b6113038SJames Morse		*(.mmuoff.data.write)
229b6113038SJames Morse	}
230b6113038SJames Morse	. = ALIGN(SZ_2K);
231b6113038SJames Morse	.mmuoff.data.read : {
232b6113038SJames Morse		*(.mmuoff.data.read)
233b6113038SJames Morse		__mmuoff_data_end = .;
234b6113038SJames Morse	}
235b6113038SJames Morse
236a352ea3eSArd Biesheuvel	PECOFF_EDATA_PADDING
237cad27ef2SArd Biesheuvel	__pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
2388c2c3df3SCatalin Marinas	_edata = .;
2398c2c3df3SCatalin Marinas
2408c2c3df3SCatalin Marinas	BSS_SECTION(0, 0, 0)
241bd00cd5fSMark Rutland
242bd00cd5fSMark Rutland	. = ALIGN(PAGE_SIZE);
2432b5548b6SJun Yao	init_pg_dir = .;
2442b5548b6SJun Yao	. += INIT_DIR_SIZE;
2452b5548b6SJun Yao	init_pg_end = .;
2462b5548b6SJun Yao
24776085affSArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
248cad27ef2SArd Biesheuvel	__pecoff_data_size = ABSOLUTE(. - __initdata_begin);
2498c2c3df3SCatalin Marinas	_end = .;
2508c2c3df3SCatalin Marinas
2518c2c3df3SCatalin Marinas	STABS_DEBUG
252a2c1d73bSMark Rutland
253a2c1d73bSMark Rutland	HEAD_SYMBOLS
2548c2c3df3SCatalin Marinas}
2552240bbb6SMarc Zyngier
25690776dd1SKees Cook#include "image-vars.h"
25790776dd1SKees Cook
2582240bbb6SMarc Zyngier/*
2595dfe9d7dSArd Biesheuvel * The HYP init code and ID map text can't be longer than a page each,
26006f75a1fSArd Biesheuvel * and should not cross a page boundary.
2612240bbb6SMarc Zyngier */
26206f75a1fSArd BiesheuvelASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
26306f75a1fSArd Biesheuvel	"HYP init code too big or misaligned")
2645dfe9d7dSArd BiesheuvelASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
2655dfe9d7dSArd Biesheuvel	"ID map text too big or misaligned")
26682869ac5SJames Morse#ifdef CONFIG_HIBERNATION
26782869ac5SJames MorseASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
26882869ac5SJames Morse	<= SZ_4K, "Hibernate exit text too big or misaligned")
26982869ac5SJames Morse#endif
2706c27c408SWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
2716c27c408SWill DeaconASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE,
2726c27c408SWill Deacon	"Entry trampoline text too big")
2736c27c408SWill Deacon#endif
274da57a369SMark Rutland/*
275da57a369SMark Rutland * If padding is applied before .head.text, virt<->phys conversions will fail.
276da57a369SMark Rutland */
277ab893fb9SArd BiesheuvelASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned")
278