xref: /openbmc/linux/arch/arm64/kernel/vmlinux.lds.S (revision e3067861ba6650a566a6273738c23c956ad55c02)
18c2c3df3SCatalin Marinas/*
28c2c3df3SCatalin Marinas * ld script to make ARM Linux kernel
38c2c3df3SCatalin Marinas * taken from the i386 version by Russell King
48c2c3df3SCatalin Marinas * Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>
58c2c3df3SCatalin Marinas */
68c2c3df3SCatalin Marinas
78c2c3df3SCatalin Marinas#include <asm-generic/vmlinux.lds.h>
898fb7548SArd Biesheuvel#include <asm/cache.h>
987d1587bSSuzuki K. Poulose#include <asm/kernel-pgtable.h>
108c2c3df3SCatalin Marinas#include <asm/thread_info.h>
118c2c3df3SCatalin Marinas#include <asm/memory.h>
128c2c3df3SCatalin Marinas#include <asm/page.h>
13da141706SLaura Abbott#include <asm/pgtable.h>
148c2c3df3SCatalin Marinas
15a2c1d73bSMark Rutland#include "image.h"
16a2c1d73bSMark Rutland
1707c802bdSWill Deacon/* .exit.text needed in case of alternative patching */
1807c802bdSWill Deacon#define ARM_EXIT_KEEP(x)	x
1907c802bdSWill Deacon#define ARM_EXIT_DISCARD(x)
208c2c3df3SCatalin Marinas
218c2c3df3SCatalin MarinasOUTPUT_ARCH(aarch64)
22af885f40SGeoff LevandENTRY(_text)
238c2c3df3SCatalin Marinas
248c2c3df3SCatalin Marinasjiffies = jiffies_64;
258c2c3df3SCatalin Marinas
262240bbb6SMarc Zyngier#define HYPERVISOR_TEXT					\
272240bbb6SMarc Zyngier	/*						\
2806f75a1fSArd Biesheuvel	 * Align to 4 KB so that			\
2906f75a1fSArd Biesheuvel	 * a) the HYP vector table is at its minimum	\
3006f75a1fSArd Biesheuvel	 *    alignment of 2048 bytes			\
3106f75a1fSArd Biesheuvel	 * b) the HYP init code will not cross a page	\
3206f75a1fSArd Biesheuvel	 *    boundary if its size does not exceed	\
3306f75a1fSArd Biesheuvel	 *    4 KB (see related ASSERT() below)		\
342240bbb6SMarc Zyngier	 */						\
3506f75a1fSArd Biesheuvel	. = ALIGN(SZ_4K);				\
362240bbb6SMarc Zyngier	VMLINUX_SYMBOL(__hyp_idmap_text_start) = .;	\
372240bbb6SMarc Zyngier	*(.hyp.idmap.text)				\
382240bbb6SMarc Zyngier	VMLINUX_SYMBOL(__hyp_idmap_text_end) = .;	\
392240bbb6SMarc Zyngier	VMLINUX_SYMBOL(__hyp_text_start) = .;		\
402240bbb6SMarc Zyngier	*(.hyp.text)					\
412240bbb6SMarc Zyngier	VMLINUX_SYMBOL(__hyp_text_end) = .;
422240bbb6SMarc Zyngier
435dfe9d7dSArd Biesheuvel#define IDMAP_TEXT					\
445dfe9d7dSArd Biesheuvel	. = ALIGN(SZ_4K);				\
455dfe9d7dSArd Biesheuvel	VMLINUX_SYMBOL(__idmap_text_start) = .;		\
465dfe9d7dSArd Biesheuvel	*(.idmap.text)					\
475dfe9d7dSArd Biesheuvel	VMLINUX_SYMBOL(__idmap_text_end) = .;
485dfe9d7dSArd Biesheuvel
4982869ac5SJames Morse#ifdef CONFIG_HIBERNATION
5082869ac5SJames Morse#define HIBERNATE_TEXT					\
5182869ac5SJames Morse	. = ALIGN(SZ_4K);				\
5282869ac5SJames Morse	VMLINUX_SYMBOL(__hibernate_exit_text_start) = .;\
5382869ac5SJames Morse	*(.hibernate_exit.text)				\
5482869ac5SJames Morse	VMLINUX_SYMBOL(__hibernate_exit_text_end) = .;
5582869ac5SJames Morse#else
5682869ac5SJames Morse#define HIBERNATE_TEXT
5782869ac5SJames Morse#endif
5882869ac5SJames Morse
59a352ea3eSArd Biesheuvel/*
60a352ea3eSArd Biesheuvel * The size of the PE/COFF section that covers the kernel image, which
61a352ea3eSArd Biesheuvel * runs from stext to _edata, must be a round multiple of the PE/COFF
62a352ea3eSArd Biesheuvel * FileAlignment, which we set to its minimum value of 0x200. 'stext'
63a352ea3eSArd Biesheuvel * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
64a352ea3eSArd Biesheuvel * boundary should be sufficient.
65a352ea3eSArd Biesheuvel */
66a352ea3eSArd BiesheuvelPECOFF_FILE_ALIGNMENT = 0x200;
67a352ea3eSArd Biesheuvel
68a352ea3eSArd Biesheuvel#ifdef CONFIG_EFI
69a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING	\
70a352ea3eSArd Biesheuvel	.pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
71a352ea3eSArd Biesheuvel#else
72a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING
73a352ea3eSArd Biesheuvel#endif
74a352ea3eSArd Biesheuvel
758c2c3df3SCatalin MarinasSECTIONS
768c2c3df3SCatalin Marinas{
778c2c3df3SCatalin Marinas	/*
788c2c3df3SCatalin Marinas	 * XXX: The linker does not define how output sections are
798c2c3df3SCatalin Marinas	 * assigned to input sections when there are multiple statements
808c2c3df3SCatalin Marinas	 * matching the same input section name.  There is no documented
818c2c3df3SCatalin Marinas	 * order of matching.
828c2c3df3SCatalin Marinas	 */
838c2c3df3SCatalin Marinas	/DISCARD/ : {
848c2c3df3SCatalin Marinas		ARM_EXIT_DISCARD(EXIT_TEXT)
858c2c3df3SCatalin Marinas		ARM_EXIT_DISCARD(EXIT_DATA)
868c2c3df3SCatalin Marinas		EXIT_CALL
878c2c3df3SCatalin Marinas		*(.discard)
888c2c3df3SCatalin Marinas		*(.discard.*)
891e48ef7fSArd Biesheuvel		*(.interp .dynamic)
9008cc55b2SArd Biesheuvel		*(.dynsym .dynstr .hash)
918c2c3df3SCatalin Marinas	}
928c2c3df3SCatalin Marinas
93ab893fb9SArd Biesheuvel	. = KIMAGE_VADDR + TEXT_OFFSET;
948c2c3df3SCatalin Marinas
958c2c3df3SCatalin Marinas	.head.text : {
968c2c3df3SCatalin Marinas		_text = .;
978c2c3df3SCatalin Marinas		HEAD_TEXT
988c2c3df3SCatalin Marinas	}
998c2c3df3SCatalin Marinas	.text : {			/* Real text segment		*/
1008c2c3df3SCatalin Marinas		_stext = .;		/* Text and read-only data	*/
1018c2c3df3SCatalin Marinas			__exception_text_start = .;
1028c2c3df3SCatalin Marinas			*(.exception.text)
1038c2c3df3SCatalin Marinas			__exception_text_end = .;
1048c2c3df3SCatalin Marinas			IRQENTRY_TEXT
105be7635e7SAlexander Potapenko			SOFTIRQENTRY_TEXT
106888b3c87SPratyush Anand			ENTRY_TEXT
1078c2c3df3SCatalin Marinas			TEXT_TEXT
1088c2c3df3SCatalin Marinas			SCHED_TEXT
1096727ad9eSChris Metcalf			CPUIDLE_TEXT
1108c2c3df3SCatalin Marinas			LOCK_TEXT
1112dd0e8d2SSandeepa Prabhu			KPROBES_TEXT
1122240bbb6SMarc Zyngier			HYPERVISOR_TEXT
1135dfe9d7dSArd Biesheuvel			IDMAP_TEXT
11482869ac5SJames Morse			HIBERNATE_TEXT
1158c2c3df3SCatalin Marinas			*(.fixup)
1168c2c3df3SCatalin Marinas			*(.gnu.warning)
1178c2c3df3SCatalin Marinas		. = ALIGN(16);
1188c2c3df3SCatalin Marinas		*(.got)			/* Global offset table		*/
1198c2c3df3SCatalin Marinas	}
1208c2c3df3SCatalin Marinas
12197740051SArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
1229fdc14c5SArd Biesheuvel	_etext = .;			/* End of text section */
1239fdc14c5SArd Biesheuvel
1242f39b5f9SJeremy Linton	RO_DATA(PAGE_SIZE)		/* everything from this point to     */
1259fdc14c5SArd Biesheuvel	EXCEPTION_TABLE(8)		/* __init_begin will be marked RO NX */
126c80b7ee8SMark Salter	NOTES
1278c2c3df3SCatalin Marinas
12897740051SArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
1298c2c3df3SCatalin Marinas	__init_begin = .;
1302ebe088bSArd Biesheuvel	__inittext_begin = .;
1318c2c3df3SCatalin Marinas
1328c2c3df3SCatalin Marinas	INIT_TEXT_SECTION(8)
1338c2c3df3SCatalin Marinas	.exit.text : {
1348c2c3df3SCatalin Marinas		ARM_EXIT_KEEP(EXIT_TEXT)
1358c2c3df3SCatalin Marinas	}
136da141706SLaura Abbott
1372ebe088bSArd Biesheuvel	. = ALIGN(4);
1382ebe088bSArd Biesheuvel	.altinstructions : {
1392ebe088bSArd Biesheuvel		__alt_instructions = .;
1402ebe088bSArd Biesheuvel		*(.altinstructions)
1412ebe088bSArd Biesheuvel		__alt_instructions_end = .;
1422ebe088bSArd Biesheuvel	}
1432ebe088bSArd Biesheuvel	.altinstr_replacement : {
1442ebe088bSArd Biesheuvel		*(.altinstr_replacement)
1452ebe088bSArd Biesheuvel	}
1462ebe088bSArd Biesheuvel
1472ebe088bSArd Biesheuvel	. = ALIGN(PAGE_SIZE);
1482ebe088bSArd Biesheuvel	__inittext_end = .;
1492ebe088bSArd Biesheuvel	__initdata_begin = .;
1502ebe088bSArd Biesheuvel
1518c2c3df3SCatalin Marinas	.init.data : {
1528c2c3df3SCatalin Marinas		INIT_DATA
1538c2c3df3SCatalin Marinas		INIT_SETUP(16)
1548c2c3df3SCatalin Marinas		INIT_CALLS
1558c2c3df3SCatalin Marinas		CON_INITCALL
1568c2c3df3SCatalin Marinas		SECURITY_INITCALL
1578c2c3df3SCatalin Marinas		INIT_RAM_FS
1581ce99bf4SArd Biesheuvel		*(.init.rodata.* .init.bss)	/* from the EFI stub */
1598c2c3df3SCatalin Marinas	}
1608c2c3df3SCatalin Marinas	.exit.data : {
1618c2c3df3SCatalin Marinas		ARM_EXIT_KEEP(EXIT_DATA)
1628c2c3df3SCatalin Marinas	}
1638c2c3df3SCatalin Marinas
16498fb7548SArd Biesheuvel	PERCPU_SECTION(L1_CACHE_BYTES)
1658c2c3df3SCatalin Marinas
1661e48ef7fSArd Biesheuvel	.rela : ALIGN(8) {
1671e48ef7fSArd Biesheuvel		*(.rela .rela*)
1681e48ef7fSArd Biesheuvel	}
169e039ee4eSAndre Przywara
170d6732fc4SArd Biesheuvel	__rela_offset	= ABSOLUTE(ADDR(.rela) - KIMAGE_VADDR);
1710cd3defeSArd Biesheuvel	__rela_size	= SIZEOF(.rela);
1720cd3defeSArd Biesheuvel
17397740051SArd Biesheuvel	. = ALIGN(SEGMENT_ALIGN);
1742ebe088bSArd Biesheuvel	__initdata_end = .;
1759aa4ec15SMark Rutland	__init_end = .;
1769aa4ec15SMark Rutland
1773c620626SMark Salter	_data = .;
1788c2c3df3SCatalin Marinas	_sdata = .;
179*e3067861SMark Rutland	RW_DATA_SECTION(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
180b6113038SJames Morse
181b6113038SJames Morse	/*
182b6113038SJames Morse	 * Data written with the MMU off but read with the MMU on requires
183b6113038SJames Morse	 * cache lines to be invalidated, discarding up to a Cache Writeback
184b6113038SJames Morse	 * Granule (CWG) of data from the cache. Keep the section that
185b6113038SJames Morse	 * requires this type of maintenance to be in its own Cache Writeback
186b6113038SJames Morse	 * Granule (CWG) area so the cache maintenance operations don't
187b6113038SJames Morse	 * interfere with adjacent data.
188b6113038SJames Morse	 */
189b6113038SJames Morse	.mmuoff.data.write : ALIGN(SZ_2K) {
190b6113038SJames Morse		__mmuoff_data_start = .;
191b6113038SJames Morse		*(.mmuoff.data.write)
192b6113038SJames Morse	}
193b6113038SJames Morse	. = ALIGN(SZ_2K);
194b6113038SJames Morse	.mmuoff.data.read : {
195b6113038SJames Morse		*(.mmuoff.data.read)
196b6113038SJames Morse		__mmuoff_data_end = .;
197b6113038SJames Morse	}
198b6113038SJames Morse
199a352ea3eSArd Biesheuvel	PECOFF_EDATA_PADDING
200cad27ef2SArd Biesheuvel	__pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
2018c2c3df3SCatalin Marinas	_edata = .;
2028c2c3df3SCatalin Marinas
2038c2c3df3SCatalin Marinas	BSS_SECTION(0, 0, 0)
204bd00cd5fSMark Rutland
205bd00cd5fSMark Rutland	. = ALIGN(PAGE_SIZE);
206bd00cd5fSMark Rutland	idmap_pg_dir = .;
207bd00cd5fSMark Rutland	. += IDMAP_DIR_SIZE;
208bd00cd5fSMark Rutland	swapper_pg_dir = .;
209bd00cd5fSMark Rutland	. += SWAPPER_DIR_SIZE;
210bd00cd5fSMark Rutland
2114b65a5dbSCatalin Marinas#ifdef CONFIG_ARM64_SW_TTBR0_PAN
2124b65a5dbSCatalin Marinas	reserved_ttbr0 = .;
2134b65a5dbSCatalin Marinas	. += RESERVED_TTBR0_SIZE;
2144b65a5dbSCatalin Marinas#endif
2154b65a5dbSCatalin Marinas
216cad27ef2SArd Biesheuvel	__pecoff_data_size = ABSOLUTE(. - __initdata_begin);
2178c2c3df3SCatalin Marinas	_end = .;
2188c2c3df3SCatalin Marinas
2198c2c3df3SCatalin Marinas	STABS_DEBUG
220a2c1d73bSMark Rutland
221a2c1d73bSMark Rutland	HEAD_SYMBOLS
2228c2c3df3SCatalin Marinas}
2232240bbb6SMarc Zyngier
2242240bbb6SMarc Zyngier/*
2255dfe9d7dSArd Biesheuvel * The HYP init code and ID map text can't be longer than a page each,
22606f75a1fSArd Biesheuvel * and should not cross a page boundary.
2272240bbb6SMarc Zyngier */
22806f75a1fSArd BiesheuvelASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
22906f75a1fSArd Biesheuvel	"HYP init code too big or misaligned")
2305dfe9d7dSArd BiesheuvelASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
2315dfe9d7dSArd Biesheuvel	"ID map text too big or misaligned")
23282869ac5SJames Morse#ifdef CONFIG_HIBERNATION
23382869ac5SJames MorseASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
23482869ac5SJames Morse	<= SZ_4K, "Hibernate exit text too big or misaligned")
23582869ac5SJames Morse#endif
236da57a369SMark Rutland
237da57a369SMark Rutland/*
238da57a369SMark Rutland * If padding is applied before .head.text, virt<->phys conversions will fail.
239da57a369SMark Rutland */
240ab893fb9SArd BiesheuvelASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned")
241