xref: /openbmc/linux/arch/arm64/kernel/vmlinux.lds.S (revision 90776dd1c427cbb4d381aa4b13338f1fb1d20f5e)
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
88c2c3df3SCatalin Marinas#include <asm-generic/vmlinux.lds.h>
998fb7548SArd Biesheuvel#include <asm/cache.h>
1087d1587bSSuzuki K. Poulose#include <asm/kernel-pgtable.h>
118c2c3df3SCatalin Marinas#include <asm/thread_info.h>
128c2c3df3SCatalin Marinas#include <asm/memory.h>
138c2c3df3SCatalin Marinas#include <asm/page.h>
14da141706SLaura Abbott#include <asm/pgtable.h>
158c2c3df3SCatalin Marinas
16a2c1d73bSMark Rutland#include "image.h"
17a2c1d73bSMark Rutland
1807c802bdSWill Deacon/* .exit.text needed in case of alternative patching */
1907c802bdSWill Deacon#define ARM_EXIT_KEEP(x)	x
2007c802bdSWill Deacon#define ARM_EXIT_DISCARD(x)
218c2c3df3SCatalin Marinas
228c2c3df3SCatalin MarinasOUTPUT_ARCH(aarch64)
23af885f40SGeoff LevandENTRY(_text)
248c2c3df3SCatalin Marinas
258c2c3df3SCatalin Marinasjiffies = jiffies_64;
268c2c3df3SCatalin Marinas
272240bbb6SMarc Zyngier#define HYPERVISOR_TEXT					\
282240bbb6SMarc Zyngier	/*						\
2906f75a1fSArd Biesheuvel	 * Align to 4 KB so that			\
3006f75a1fSArd Biesheuvel	 * a) the HYP vector table is at its minimum	\
3106f75a1fSArd Biesheuvel	 *    alignment of 2048 bytes			\
3206f75a1fSArd Biesheuvel	 * b) the HYP init code will not cross a page	\
3306f75a1fSArd Biesheuvel	 *    boundary if its size does not exceed	\
3406f75a1fSArd Biesheuvel	 *    4 KB (see related ASSERT() below)		\
352240bbb6SMarc Zyngier	 */						\
3606f75a1fSArd Biesheuvel	. = ALIGN(SZ_4K);				\
375c636aa0SMasahiro Yamada	__hyp_idmap_text_start = .;			\
382240bbb6SMarc Zyngier	*(.hyp.idmap.text)				\
395c636aa0SMasahiro Yamada	__hyp_idmap_text_end = .;			\
405c636aa0SMasahiro Yamada	__hyp_text_start = .;				\
412240bbb6SMarc Zyngier	*(.hyp.text)					\
425c636aa0SMasahiro Yamada	__hyp_text_end = .;
432240bbb6SMarc Zyngier
445dfe9d7dSArd Biesheuvel#define IDMAP_TEXT					\
455dfe9d7dSArd Biesheuvel	. = ALIGN(SZ_4K);				\
465c636aa0SMasahiro Yamada	__idmap_text_start = .;				\
475dfe9d7dSArd Biesheuvel	*(.idmap.text)					\
485c636aa0SMasahiro Yamada	__idmap_text_end = .;
495dfe9d7dSArd Biesheuvel
5082869ac5SJames Morse#ifdef CONFIG_HIBERNATION
5182869ac5SJames Morse#define HIBERNATE_TEXT					\
5282869ac5SJames Morse	. = ALIGN(SZ_4K);				\
535c636aa0SMasahiro Yamada	__hibernate_exit_text_start = .;		\
5482869ac5SJames Morse	*(.hibernate_exit.text)				\
555c636aa0SMasahiro Yamada	__hibernate_exit_text_end = .;
5682869ac5SJames Morse#else
5782869ac5SJames Morse#define HIBERNATE_TEXT
5882869ac5SJames Morse#endif
5982869ac5SJames Morse
60c7b9adafSWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
61c7b9adafSWill Deacon#define TRAMP_TEXT					\
62c7b9adafSWill Deacon	. = ALIGN(PAGE_SIZE);				\
635c636aa0SMasahiro Yamada	__entry_tramp_text_start = .;			\
64c7b9adafSWill Deacon	*(.entry.tramp.text)				\
65c7b9adafSWill Deacon	. = ALIGN(PAGE_SIZE);				\
665c636aa0SMasahiro Yamada	__entry_tramp_text_end = .;
67c7b9adafSWill Deacon#else
68c7b9adafSWill Deacon#define TRAMP_TEXT
69c7b9adafSWill Deacon#endif
70c7b9adafSWill Deacon
71a352ea3eSArd Biesheuvel/*
72a352ea3eSArd Biesheuvel * The size of the PE/COFF section that covers the kernel image, which
73a352ea3eSArd Biesheuvel * runs from stext to _edata, must be a round multiple of the PE/COFF
74a352ea3eSArd Biesheuvel * FileAlignment, which we set to its minimum value of 0x200. 'stext'
75a352ea3eSArd Biesheuvel * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
76a352ea3eSArd Biesheuvel * boundary should be sufficient.
77a352ea3eSArd Biesheuvel */
78a352ea3eSArd BiesheuvelPECOFF_FILE_ALIGNMENT = 0x200;
79a352ea3eSArd Biesheuvel
80a352ea3eSArd Biesheuvel#ifdef CONFIG_EFI
81a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING	\
82a352ea3eSArd Biesheuvel	.pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
83a352ea3eSArd Biesheuvel#else
84a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING
85a352ea3eSArd Biesheuvel#endif
86a352ea3eSArd Biesheuvel
878c2c3df3SCatalin MarinasSECTIONS
888c2c3df3SCatalin Marinas{
898c2c3df3SCatalin Marinas	/*
908c2c3df3SCatalin Marinas	 * XXX: The linker does not define how output sections are
918c2c3df3SCatalin Marinas	 * assigned to input sections when there are multiple statements
928c2c3df3SCatalin Marinas	 * matching the same input section name.  There is no documented
938c2c3df3SCatalin Marinas	 * order of matching.
948c2c3df3SCatalin Marinas	 */
958c2c3df3SCatalin Marinas	/DISCARD/ : {
968c2c3df3SCatalin Marinas		ARM_EXIT_DISCARD(EXIT_TEXT)
978c2c3df3SCatalin Marinas		ARM_EXIT_DISCARD(EXIT_DATA)
988c2c3df3SCatalin Marinas		EXIT_CALL
998c2c3df3SCatalin Marinas		*(.discard)
1008c2c3df3SCatalin Marinas		*(.discard.*)
1011e48ef7fSArd Biesheuvel		*(.interp .dynamic)
1023bbd3db8SArd Biesheuvel		*(.dynsym .dynstr .hash .gnu.hash)
1033bbd3db8SArd Biesheuvel		*(.eh_frame)
1048c2c3df3SCatalin Marinas	}
1058c2c3df3SCatalin Marinas
106ab893fb9SArd Biesheuvel	. = KIMAGE_VADDR + TEXT_OFFSET;
1078c2c3df3SCatalin Marinas
1088c2c3df3SCatalin Marinas	.head.text : {
1098c2c3df3SCatalin Marinas		_text = .;
1108c2c3df3SCatalin Marinas		HEAD_TEXT
1118c2c3df3SCatalin Marinas	}
1128c2c3df3SCatalin Marinas	.text : {			/* Real text segment		*/
1138c2c3df3SCatalin Marinas		_stext = .;		/* Text and read-only data	*/
1148c2c3df3SCatalin Marinas			__exception_text_start = .;
1158c2c3df3SCatalin Marinas			*(.exception.text)
1168c2c3df3SCatalin Marinas			__exception_text_end = .;
1178c2c3df3SCatalin Marinas			IRQENTRY_TEXT
118be7635e7SAlexander Potapenko			SOFTIRQENTRY_TEXT
119888b3c87SPratyush Anand			ENTRY_TEXT
1208c2c3df3SCatalin Marinas			TEXT_TEXT
1218c2c3df3SCatalin Marinas			SCHED_TEXT
1226727ad9eSChris Metcalf			CPUIDLE_TEXT
1238c2c3df3SCatalin Marinas			LOCK_TEXT
1242dd0e8d2SSandeepa Prabhu			KPROBES_TEXT
1252240bbb6SMarc Zyngier			HYPERVISOR_TEXT
1265dfe9d7dSArd Biesheuvel			IDMAP_TEXT
12782869ac5SJames Morse			HIBERNATE_TEXT
128c7b9adafSWill Deacon			TRAMP_TEXT
1298c2c3df3SCatalin Marinas			*(.fixup)
1308c2c3df3SCatalin Marinas			*(.gnu.warning)
1318c2c3df3SCatalin Marinas		. = ALIGN(16);
1328c2c3df3SCatalin Marinas		*(.got)			/* Global offset table		*/
1338c2c3df3SCatalin Marinas	}
1348c2c3df3SCatalin Marinas
13597740051SArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
1369fdc14c5SArd Biesheuvel	_etext = .;			/* End of text section */
1379fdc14c5SArd Biesheuvel
1382f39b5f9SJeremy Linton	RO_DATA(PAGE_SIZE)		/* everything from this point to     */
1399fdc14c5SArd Biesheuvel	EXCEPTION_TABLE(8)		/* __init_begin will be marked RO NX */
140c80b7ee8SMark Salter	NOTES
1418c2c3df3SCatalin Marinas
1428eb7e28dSJun Yao	. = ALIGN(PAGE_SIZE);
1438eb7e28dSJun Yao	idmap_pg_dir = .;
1448eb7e28dSJun Yao	. += IDMAP_DIR_SIZE;
1458eb7e28dSJun Yao
1468eb7e28dSJun Yao#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
1478eb7e28dSJun Yao	tramp_pg_dir = .;
1488eb7e28dSJun Yao	. += PAGE_SIZE;
1498eb7e28dSJun Yao#endif
1508eb7e28dSJun Yao
1518eb7e28dSJun Yao#ifdef CONFIG_ARM64_SW_TTBR0_PAN
1528eb7e28dSJun Yao	reserved_ttbr0 = .;
1538eb7e28dSJun Yao	. += RESERVED_TTBR0_SIZE;
1548eb7e28dSJun Yao#endif
1558eb7e28dSJun Yao	swapper_pg_dir = .;
1568eb7e28dSJun Yao	. += PAGE_SIZE;
1578eb7e28dSJun Yao	swapper_pg_end = .;
1588eb7e28dSJun Yao
15997740051SArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
1608c2c3df3SCatalin Marinas	__init_begin = .;
1612ebe088bSArd Biesheuvel	__inittext_begin = .;
1628c2c3df3SCatalin Marinas
1638c2c3df3SCatalin Marinas	INIT_TEXT_SECTION(8)
1648c2c3df3SCatalin Marinas	.exit.text : {
1658c2c3df3SCatalin Marinas		ARM_EXIT_KEEP(EXIT_TEXT)
1668c2c3df3SCatalin Marinas	}
167da141706SLaura Abbott
1682ebe088bSArd Biesheuvel	. = ALIGN(4);
1692ebe088bSArd Biesheuvel	.altinstructions : {
1702ebe088bSArd Biesheuvel		__alt_instructions = .;
1712ebe088bSArd Biesheuvel		*(.altinstructions)
1722ebe088bSArd Biesheuvel		__alt_instructions_end = .;
1732ebe088bSArd Biesheuvel	}
1742ebe088bSArd Biesheuvel	.altinstr_replacement : {
1752ebe088bSArd Biesheuvel		*(.altinstr_replacement)
1762ebe088bSArd Biesheuvel	}
1772ebe088bSArd Biesheuvel
1782ebe088bSArd Biesheuvel	. = ALIGN(PAGE_SIZE);
1792ebe088bSArd Biesheuvel	__inittext_end = .;
1802ebe088bSArd Biesheuvel	__initdata_begin = .;
1812ebe088bSArd Biesheuvel
1828c2c3df3SCatalin Marinas	.init.data : {
1838c2c3df3SCatalin Marinas		INIT_DATA
1848c2c3df3SCatalin Marinas		INIT_SETUP(16)
1858c2c3df3SCatalin Marinas		INIT_CALLS
1868c2c3df3SCatalin Marinas		CON_INITCALL
1878c2c3df3SCatalin Marinas		INIT_RAM_FS
1881ce99bf4SArd Biesheuvel		*(.init.rodata.* .init.bss)	/* from the EFI stub */
1898c2c3df3SCatalin Marinas	}
1908c2c3df3SCatalin Marinas	.exit.data : {
1918c2c3df3SCatalin Marinas		ARM_EXIT_KEEP(EXIT_DATA)
1928c2c3df3SCatalin Marinas	}
1938c2c3df3SCatalin Marinas
19498fb7548SArd Biesheuvel	PERCPU_SECTION(L1_CACHE_BYTES)
1958c2c3df3SCatalin Marinas
1963bbd3db8SArd Biesheuvel	.rela.dyn : ALIGN(8) {
1971e48ef7fSArd Biesheuvel		*(.rela .rela*)
1981e48ef7fSArd Biesheuvel	}
199e039ee4eSAndre Przywara
2003bbd3db8SArd Biesheuvel	__rela_offset	= ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR);
2013bbd3db8SArd Biesheuvel	__rela_size	= SIZEOF(.rela.dyn);
2020cd3defeSArd Biesheuvel
2035cf896fbSPeter Collingbourne#ifdef CONFIG_RELR
2045cf896fbSPeter Collingbourne	.relr.dyn : ALIGN(8) {
2055cf896fbSPeter Collingbourne		*(.relr.dyn)
2065cf896fbSPeter Collingbourne	}
2075cf896fbSPeter Collingbourne
2085cf896fbSPeter Collingbourne	__relr_offset	= ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR);
2095cf896fbSPeter Collingbourne	__relr_size	= SIZEOF(.relr.dyn);
2105cf896fbSPeter Collingbourne#endif
2115cf896fbSPeter Collingbourne
21297740051SArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
2132ebe088bSArd Biesheuvel	__initdata_end = .;
2149aa4ec15SMark Rutland	__init_end = .;
2159aa4ec15SMark Rutland
2163c620626SMark Salter	_data = .;
2178c2c3df3SCatalin Marinas	_sdata = .;
218e3067861SMark Rutland	RW_DATA_SECTION(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
219b6113038SJames Morse
220b6113038SJames Morse	/*
221b6113038SJames Morse	 * Data written with the MMU off but read with the MMU on requires
222b6113038SJames Morse	 * cache lines to be invalidated, discarding up to a Cache Writeback
223b6113038SJames Morse	 * Granule (CWG) of data from the cache. Keep the section that
224b6113038SJames Morse	 * requires this type of maintenance to be in its own Cache Writeback
225b6113038SJames Morse	 * Granule (CWG) area so the cache maintenance operations don't
226b6113038SJames Morse	 * interfere with adjacent data.
227b6113038SJames Morse	 */
228b6113038SJames Morse	.mmuoff.data.write : ALIGN(SZ_2K) {
229b6113038SJames Morse		__mmuoff_data_start = .;
230b6113038SJames Morse		*(.mmuoff.data.write)
231b6113038SJames Morse	}
232b6113038SJames Morse	. = ALIGN(SZ_2K);
233b6113038SJames Morse	.mmuoff.data.read : {
234b6113038SJames Morse		*(.mmuoff.data.read)
235b6113038SJames Morse		__mmuoff_data_end = .;
236b6113038SJames Morse	}
237b6113038SJames Morse
238a352ea3eSArd Biesheuvel	PECOFF_EDATA_PADDING
239cad27ef2SArd Biesheuvel	__pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
2408c2c3df3SCatalin Marinas	_edata = .;
2418c2c3df3SCatalin Marinas
2428c2c3df3SCatalin Marinas	BSS_SECTION(0, 0, 0)
243bd00cd5fSMark Rutland
244bd00cd5fSMark Rutland	. = ALIGN(PAGE_SIZE);
2452b5548b6SJun Yao	init_pg_dir = .;
2462b5548b6SJun Yao	. += INIT_DIR_SIZE;
2472b5548b6SJun Yao	init_pg_end = .;
2482b5548b6SJun Yao
249cad27ef2SArd Biesheuvel	__pecoff_data_size = ABSOLUTE(. - __initdata_begin);
2508c2c3df3SCatalin Marinas	_end = .;
2518c2c3df3SCatalin Marinas
2528c2c3df3SCatalin Marinas	STABS_DEBUG
253a2c1d73bSMark Rutland
254a2c1d73bSMark Rutland	HEAD_SYMBOLS
2558c2c3df3SCatalin Marinas}
2562240bbb6SMarc Zyngier
257*90776dd1SKees Cook#include "image-vars.h"
258*90776dd1SKees Cook
2592240bbb6SMarc Zyngier/*
2605dfe9d7dSArd Biesheuvel * The HYP init code and ID map text can't be longer than a page each,
26106f75a1fSArd Biesheuvel * and should not cross a page boundary.
2622240bbb6SMarc Zyngier */
26306f75a1fSArd BiesheuvelASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
26406f75a1fSArd Biesheuvel	"HYP init code too big or misaligned")
2655dfe9d7dSArd BiesheuvelASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
2665dfe9d7dSArd Biesheuvel	"ID map text too big or misaligned")
26782869ac5SJames Morse#ifdef CONFIG_HIBERNATION
26882869ac5SJames MorseASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
26982869ac5SJames Morse	<= SZ_4K, "Hibernate exit text too big or misaligned")
27082869ac5SJames Morse#endif
2716c27c408SWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
2726c27c408SWill DeaconASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE,
2736c27c408SWill Deacon	"Entry trampoline text too big")
2746c27c408SWill Deacon#endif
275da57a369SMark Rutland/*
276da57a369SMark Rutland * If padding is applied before .head.text, virt<->phys conversions will fail.
277da57a369SMark Rutland */
278ab893fb9SArd BiesheuvelASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned")
279