xref: /openbmc/linux/arch/arm64/kernel/vmlinux.lds.S (revision 2883352bf801d093a04f269800b48bb8aa2515fb)
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
9*2883352bSKees Cook#define RUNTIME_DISCARD_EXIT
1019f6bc32SKees Cook
118c2c3df3SCatalin Marinas#include <asm-generic/vmlinux.lds.h>
1298fb7548SArd Biesheuvel#include <asm/cache.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
242240bbb6SMarc Zyngier#define HYPERVISOR_TEXT					\
252240bbb6SMarc Zyngier	/*						\
2606f75a1fSArd Biesheuvel	 * Align to 4 KB so that			\
2706f75a1fSArd Biesheuvel	 * a) the HYP vector table is at its minimum	\
2806f75a1fSArd Biesheuvel	 *    alignment of 2048 bytes			\
2906f75a1fSArd Biesheuvel	 * b) the HYP init code will not cross a page	\
3006f75a1fSArd Biesheuvel	 *    boundary if its size does not exceed	\
3106f75a1fSArd Biesheuvel	 *    4 KB (see related ASSERT() below)		\
322240bbb6SMarc Zyngier	 */						\
3306f75a1fSArd Biesheuvel	. = ALIGN(SZ_4K);				\
345c636aa0SMasahiro Yamada	__hyp_idmap_text_start = .;			\
352240bbb6SMarc Zyngier	*(.hyp.idmap.text)				\
365c636aa0SMasahiro Yamada	__hyp_idmap_text_end = .;			\
375c636aa0SMasahiro Yamada	__hyp_text_start = .;				\
382240bbb6SMarc Zyngier	*(.hyp.text)					\
395c636aa0SMasahiro Yamada	__hyp_text_end = .;
402240bbb6SMarc Zyngier
415dfe9d7dSArd Biesheuvel#define IDMAP_TEXT					\
425dfe9d7dSArd Biesheuvel	. = ALIGN(SZ_4K);				\
435c636aa0SMasahiro Yamada	__idmap_text_start = .;				\
445dfe9d7dSArd Biesheuvel	*(.idmap.text)					\
455c636aa0SMasahiro Yamada	__idmap_text_end = .;
465dfe9d7dSArd Biesheuvel
4782869ac5SJames Morse#ifdef CONFIG_HIBERNATION
4882869ac5SJames Morse#define HIBERNATE_TEXT					\
4982869ac5SJames Morse	. = ALIGN(SZ_4K);				\
505c636aa0SMasahiro Yamada	__hibernate_exit_text_start = .;		\
5182869ac5SJames Morse	*(.hibernate_exit.text)				\
525c636aa0SMasahiro Yamada	__hibernate_exit_text_end = .;
5382869ac5SJames Morse#else
5482869ac5SJames Morse#define HIBERNATE_TEXT
5582869ac5SJames Morse#endif
5682869ac5SJames Morse
57c7b9adafSWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
58c7b9adafSWill Deacon#define TRAMP_TEXT					\
59c7b9adafSWill Deacon	. = ALIGN(PAGE_SIZE);				\
605c636aa0SMasahiro Yamada	__entry_tramp_text_start = .;			\
61c7b9adafSWill Deacon	*(.entry.tramp.text)				\
62c7b9adafSWill Deacon	. = ALIGN(PAGE_SIZE);				\
635c636aa0SMasahiro Yamada	__entry_tramp_text_end = .;
64c7b9adafSWill Deacon#else
65c7b9adafSWill Deacon#define TRAMP_TEXT
66c7b9adafSWill Deacon#endif
67c7b9adafSWill Deacon
68a352ea3eSArd Biesheuvel/*
69a352ea3eSArd Biesheuvel * The size of the PE/COFF section that covers the kernel image, which
70348a625dSArd Biesheuvel * runs from _stext to _edata, must be a round multiple of the PE/COFF
71348a625dSArd Biesheuvel * FileAlignment, which we set to its minimum value of 0x200. '_stext'
72a352ea3eSArd Biesheuvel * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
73a352ea3eSArd Biesheuvel * boundary should be sufficient.
74a352ea3eSArd Biesheuvel */
75a352ea3eSArd BiesheuvelPECOFF_FILE_ALIGNMENT = 0x200;
76a352ea3eSArd Biesheuvel
77a352ea3eSArd Biesheuvel#ifdef CONFIG_EFI
78a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING	\
79a352ea3eSArd Biesheuvel	.pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
80a352ea3eSArd Biesheuvel#else
81a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING
82a352ea3eSArd Biesheuvel#endif
83a352ea3eSArd Biesheuvel
848c2c3df3SCatalin MarinasSECTIONS
858c2c3df3SCatalin Marinas{
868c2c3df3SCatalin Marinas	/*
878c2c3df3SCatalin Marinas	 * XXX: The linker does not define how output sections are
888c2c3df3SCatalin Marinas	 * assigned to input sections when there are multiple statements
898c2c3df3SCatalin Marinas	 * matching the same input section name.  There is no documented
908c2c3df3SCatalin Marinas	 * order of matching.
918c2c3df3SCatalin Marinas	 */
92*2883352bSKees Cook	DISCARDS
938c2c3df3SCatalin Marinas	/DISCARD/ : {
941e48ef7fSArd Biesheuvel		*(.interp .dynamic)
953bbd3db8SArd Biesheuvel		*(.dynsym .dynstr .hash .gnu.hash)
968c2c3df3SCatalin Marinas	}
978c2c3df3SCatalin Marinas
98ab893fb9SArd Biesheuvel	. = KIMAGE_VADDR + TEXT_OFFSET;
998c2c3df3SCatalin Marinas
1008c2c3df3SCatalin Marinas	.head.text : {
1018c2c3df3SCatalin Marinas		_text = .;
1028c2c3df3SCatalin Marinas		HEAD_TEXT
1038c2c3df3SCatalin Marinas	}
1048c2c3df3SCatalin Marinas	.text : {			/* Real text segment		*/
1058c2c3df3SCatalin Marinas		_stext = .;		/* Text and read-only data	*/
1068c2c3df3SCatalin Marinas			IRQENTRY_TEXT
107be7635e7SAlexander Potapenko			SOFTIRQENTRY_TEXT
108888b3c87SPratyush Anand			ENTRY_TEXT
1098c2c3df3SCatalin Marinas			TEXT_TEXT
1108c2c3df3SCatalin Marinas			SCHED_TEXT
1116727ad9eSChris Metcalf			CPUIDLE_TEXT
1128c2c3df3SCatalin Marinas			LOCK_TEXT
1132dd0e8d2SSandeepa Prabhu			KPROBES_TEXT
1142240bbb6SMarc Zyngier			HYPERVISOR_TEXT
1155dfe9d7dSArd Biesheuvel			IDMAP_TEXT
11682869ac5SJames Morse			HIBERNATE_TEXT
117c7b9adafSWill Deacon			TRAMP_TEXT
1188c2c3df3SCatalin Marinas			*(.fixup)
1198c2c3df3SCatalin Marinas			*(.gnu.warning)
1208c2c3df3SCatalin Marinas		. = ALIGN(16);
1218c2c3df3SCatalin Marinas		*(.got)			/* Global offset table		*/
1228c2c3df3SCatalin Marinas	}
1238c2c3df3SCatalin Marinas
12497740051SArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
1259fdc14c5SArd Biesheuvel	_etext = .;			/* End of text section */
1269fdc14c5SArd Biesheuvel
12719f6bc32SKees Cook	/* everything from this point to __init_begin will be marked RO NX */
12819f6bc32SKees Cook	RO_DATA(PAGE_SIZE)
1298c2c3df3SCatalin Marinas
1308eb7e28dSJun Yao	idmap_pg_dir = .;
1318eb7e28dSJun Yao	. += IDMAP_DIR_SIZE;
1329d2d75edSGavin Shan	idmap_pg_end = .;
1338eb7e28dSJun Yao
1348eb7e28dSJun Yao#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
1358eb7e28dSJun Yao	tramp_pg_dir = .;
1368eb7e28dSJun Yao	. += PAGE_SIZE;
1378eb7e28dSJun Yao#endif
1388eb7e28dSJun Yao
1398eb7e28dSJun Yao#ifdef CONFIG_ARM64_SW_TTBR0_PAN
1408eb7e28dSJun Yao	reserved_ttbr0 = .;
1418eb7e28dSJun Yao	. += RESERVED_TTBR0_SIZE;
1428eb7e28dSJun Yao#endif
1438eb7e28dSJun Yao	swapper_pg_dir = .;
1448eb7e28dSJun Yao	. += PAGE_SIZE;
1458eb7e28dSJun Yao	swapper_pg_end = .;
1468eb7e28dSJun Yao
14797740051SArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
1488c2c3df3SCatalin Marinas	__init_begin = .;
1492ebe088bSArd Biesheuvel	__inittext_begin = .;
1508c2c3df3SCatalin Marinas
1518c2c3df3SCatalin Marinas	INIT_TEXT_SECTION(8)
152ca2ef4ffSMark Rutland
153ca2ef4ffSMark Rutland	__exittext_begin = .;
1548c2c3df3SCatalin Marinas	.exit.text : {
1551eae811dSArd Biesheuvel		EXIT_TEXT
1568c2c3df3SCatalin Marinas	}
157ca2ef4ffSMark Rutland	__exittext_end = .;
158da141706SLaura Abbott
1592ebe088bSArd Biesheuvel	. = ALIGN(4);
1602ebe088bSArd Biesheuvel	.altinstructions : {
1612ebe088bSArd Biesheuvel		__alt_instructions = .;
1622ebe088bSArd Biesheuvel		*(.altinstructions)
1632ebe088bSArd Biesheuvel		__alt_instructions_end = .;
1642ebe088bSArd Biesheuvel	}
1652ebe088bSArd Biesheuvel
16676085affSArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
1672ebe088bSArd Biesheuvel	__inittext_end = .;
1682ebe088bSArd Biesheuvel	__initdata_begin = .;
1692ebe088bSArd Biesheuvel
1708c2c3df3SCatalin Marinas	.init.data : {
1718c2c3df3SCatalin Marinas		INIT_DATA
1728c2c3df3SCatalin Marinas		INIT_SETUP(16)
1738c2c3df3SCatalin Marinas		INIT_CALLS
1748c2c3df3SCatalin Marinas		CON_INITCALL
1758c2c3df3SCatalin Marinas		INIT_RAM_FS
1761ce99bf4SArd Biesheuvel		*(.init.rodata.* .init.bss)	/* from the EFI stub */
1778c2c3df3SCatalin Marinas	}
1788c2c3df3SCatalin Marinas	.exit.data : {
1791eae811dSArd Biesheuvel		EXIT_DATA
1808c2c3df3SCatalin Marinas	}
1818c2c3df3SCatalin Marinas
18298fb7548SArd Biesheuvel	PERCPU_SECTION(L1_CACHE_BYTES)
1838c2c3df3SCatalin Marinas
1843bbd3db8SArd Biesheuvel	.rela.dyn : ALIGN(8) {
1851e48ef7fSArd Biesheuvel		*(.rela .rela*)
1861e48ef7fSArd Biesheuvel	}
187e039ee4eSAndre Przywara
1883bbd3db8SArd Biesheuvel	__rela_offset	= ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR);
1893bbd3db8SArd Biesheuvel	__rela_size	= SIZEOF(.rela.dyn);
1900cd3defeSArd Biesheuvel
1915cf896fbSPeter Collingbourne#ifdef CONFIG_RELR
1925cf896fbSPeter Collingbourne	.relr.dyn : ALIGN(8) {
1935cf896fbSPeter Collingbourne		*(.relr.dyn)
1945cf896fbSPeter Collingbourne	}
1955cf896fbSPeter Collingbourne
1965cf896fbSPeter Collingbourne	__relr_offset	= ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR);
1975cf896fbSPeter Collingbourne	__relr_size	= SIZEOF(.relr.dyn);
1985cf896fbSPeter Collingbourne#endif
1995cf896fbSPeter Collingbourne
20097740051SArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
2012ebe088bSArd Biesheuvel	__initdata_end = .;
2029aa4ec15SMark Rutland	__init_end = .;
2039aa4ec15SMark Rutland
2043c620626SMark Salter	_data = .;
2058c2c3df3SCatalin Marinas	_sdata = .;
206c9174047SKees Cook	RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
207b6113038SJames Morse
208b6113038SJames Morse	/*
209b6113038SJames Morse	 * Data written with the MMU off but read with the MMU on requires
210b6113038SJames Morse	 * cache lines to be invalidated, discarding up to a Cache Writeback
211b6113038SJames Morse	 * Granule (CWG) of data from the cache. Keep the section that
212b6113038SJames Morse	 * requires this type of maintenance to be in its own Cache Writeback
213b6113038SJames Morse	 * Granule (CWG) area so the cache maintenance operations don't
214b6113038SJames Morse	 * interfere with adjacent data.
215b6113038SJames Morse	 */
216b6113038SJames Morse	.mmuoff.data.write : ALIGN(SZ_2K) {
217b6113038SJames Morse		__mmuoff_data_start = .;
218b6113038SJames Morse		*(.mmuoff.data.write)
219b6113038SJames Morse	}
220b6113038SJames Morse	. = ALIGN(SZ_2K);
221b6113038SJames Morse	.mmuoff.data.read : {
222b6113038SJames Morse		*(.mmuoff.data.read)
223b6113038SJames Morse		__mmuoff_data_end = .;
224b6113038SJames Morse	}
225b6113038SJames Morse
226a352ea3eSArd Biesheuvel	PECOFF_EDATA_PADDING
227cad27ef2SArd Biesheuvel	__pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
2288c2c3df3SCatalin Marinas	_edata = .;
2298c2c3df3SCatalin Marinas
2308c2c3df3SCatalin Marinas	BSS_SECTION(0, 0, 0)
231bd00cd5fSMark Rutland
232bd00cd5fSMark Rutland	. = ALIGN(PAGE_SIZE);
2332b5548b6SJun Yao	init_pg_dir = .;
2342b5548b6SJun Yao	. += INIT_DIR_SIZE;
2352b5548b6SJun Yao	init_pg_end = .;
2362b5548b6SJun Yao
23776085affSArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
238cad27ef2SArd Biesheuvel	__pecoff_data_size = ABSOLUTE(. - __initdata_begin);
2398c2c3df3SCatalin Marinas	_end = .;
2408c2c3df3SCatalin Marinas
2418c2c3df3SCatalin Marinas	STABS_DEBUG
242c604abc3SKees Cook	ELF_DETAILS
243a2c1d73bSMark Rutland
244a2c1d73bSMark Rutland	HEAD_SYMBOLS
2458c2c3df3SCatalin Marinas}
2462240bbb6SMarc Zyngier
24790776dd1SKees Cook#include "image-vars.h"
24890776dd1SKees Cook
2492240bbb6SMarc Zyngier/*
2505dfe9d7dSArd Biesheuvel * The HYP init code and ID map text can't be longer than a page each,
25106f75a1fSArd Biesheuvel * and should not cross a page boundary.
2522240bbb6SMarc Zyngier */
25306f75a1fSArd BiesheuvelASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
25406f75a1fSArd Biesheuvel	"HYP init code too big or misaligned")
2555dfe9d7dSArd BiesheuvelASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
2565dfe9d7dSArd Biesheuvel	"ID map text too big or misaligned")
25782869ac5SJames Morse#ifdef CONFIG_HIBERNATION
25882869ac5SJames MorseASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
25982869ac5SJames Morse	<= SZ_4K, "Hibernate exit text too big or misaligned")
26082869ac5SJames Morse#endif
2616c27c408SWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
2626c27c408SWill DeaconASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE,
2636c27c408SWill Deacon	"Entry trampoline text too big")
2646c27c408SWill Deacon#endif
265da57a369SMark Rutland/*
266da57a369SMark Rutland * If padding is applied before .head.text, virt<->phys conversions will fail.
267da57a369SMark Rutland */
268ab893fb9SArd BiesheuvelASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned")
269