xref: /openbmc/linux/arch/arm64/kernel/vmlinux.lds.S (revision 9aa4ec1571da62366cfddc20f3b923609604fe63)
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>
887d1587bSSuzuki K. Poulose#include <asm/kernel-pgtable.h>
98c2c3df3SCatalin Marinas#include <asm/thread_info.h>
108c2c3df3SCatalin Marinas#include <asm/memory.h>
118c2c3df3SCatalin Marinas#include <asm/page.h>
12da141706SLaura Abbott#include <asm/pgtable.h>
138c2c3df3SCatalin Marinas
14a2c1d73bSMark Rutland#include "image.h"
15a2c1d73bSMark Rutland
1607c802bdSWill Deacon/* .exit.text needed in case of alternative patching */
1707c802bdSWill Deacon#define ARM_EXIT_KEEP(x)	x
1807c802bdSWill Deacon#define ARM_EXIT_DISCARD(x)
198c2c3df3SCatalin Marinas
208c2c3df3SCatalin MarinasOUTPUT_ARCH(aarch64)
21af885f40SGeoff LevandENTRY(_text)
228c2c3df3SCatalin Marinas
238c2c3df3SCatalin Marinasjiffies = jiffies_64;
248c2c3df3SCatalin Marinas
252240bbb6SMarc Zyngier#define HYPERVISOR_TEXT					\
262240bbb6SMarc Zyngier	/*						\
2706f75a1fSArd Biesheuvel	 * Align to 4 KB so that			\
2806f75a1fSArd Biesheuvel	 * a) the HYP vector table is at its minimum	\
2906f75a1fSArd Biesheuvel	 *    alignment of 2048 bytes			\
3006f75a1fSArd Biesheuvel	 * b) the HYP init code will not cross a page	\
3106f75a1fSArd Biesheuvel	 *    boundary if its size does not exceed	\
3206f75a1fSArd Biesheuvel	 *    4 KB (see related ASSERT() below)		\
332240bbb6SMarc Zyngier	 */						\
3406f75a1fSArd Biesheuvel	. = ALIGN(SZ_4K);				\
352240bbb6SMarc Zyngier	VMLINUX_SYMBOL(__hyp_idmap_text_start) = .;	\
362240bbb6SMarc Zyngier	*(.hyp.idmap.text)				\
372240bbb6SMarc Zyngier	VMLINUX_SYMBOL(__hyp_idmap_text_end) = .;	\
382240bbb6SMarc Zyngier	VMLINUX_SYMBOL(__hyp_text_start) = .;		\
392240bbb6SMarc Zyngier	*(.hyp.text)					\
402240bbb6SMarc Zyngier	VMLINUX_SYMBOL(__hyp_text_end) = .;
412240bbb6SMarc Zyngier
425dfe9d7dSArd Biesheuvel#define IDMAP_TEXT					\
435dfe9d7dSArd Biesheuvel	. = ALIGN(SZ_4K);				\
445dfe9d7dSArd Biesheuvel	VMLINUX_SYMBOL(__idmap_text_start) = .;		\
455dfe9d7dSArd Biesheuvel	*(.idmap.text)					\
465dfe9d7dSArd Biesheuvel	VMLINUX_SYMBOL(__idmap_text_end) = .;
475dfe9d7dSArd Biesheuvel
48a352ea3eSArd Biesheuvel/*
49a352ea3eSArd Biesheuvel * The size of the PE/COFF section that covers the kernel image, which
50a352ea3eSArd Biesheuvel * runs from stext to _edata, must be a round multiple of the PE/COFF
51a352ea3eSArd Biesheuvel * FileAlignment, which we set to its minimum value of 0x200. 'stext'
52a352ea3eSArd Biesheuvel * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
53a352ea3eSArd Biesheuvel * boundary should be sufficient.
54a352ea3eSArd Biesheuvel */
55a352ea3eSArd BiesheuvelPECOFF_FILE_ALIGNMENT = 0x200;
56a352ea3eSArd Biesheuvel
57a352ea3eSArd Biesheuvel#ifdef CONFIG_EFI
58a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING	\
59a352ea3eSArd Biesheuvel	.pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
60a352ea3eSArd Biesheuvel#else
61a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING
62a352ea3eSArd Biesheuvel#endif
63a352ea3eSArd Biesheuvel
64cb083816SMark Rutland#if defined(CONFIG_DEBUG_ALIGN_RODATA)
65da141706SLaura Abbott#define ALIGN_DEBUG_RO			. = ALIGN(1<<SECTION_SHIFT);
66da141706SLaura Abbott#define ALIGN_DEBUG_RO_MIN(min)		ALIGN_DEBUG_RO
67cb083816SMark Rutland#elif defined(CONFIG_DEBUG_RODATA)
68cb083816SMark Rutland#define ALIGN_DEBUG_RO			. = ALIGN(1<<PAGE_SHIFT);
69cb083816SMark Rutland#define ALIGN_DEBUG_RO_MIN(min)		ALIGN_DEBUG_RO
70da141706SLaura Abbott#else
71da141706SLaura Abbott#define ALIGN_DEBUG_RO
72da141706SLaura Abbott#define ALIGN_DEBUG_RO_MIN(min)		. = ALIGN(min);
73da141706SLaura Abbott#endif
74da141706SLaura Abbott
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.*)
898c2c3df3SCatalin Marinas	}
908c2c3df3SCatalin Marinas
918c2c3df3SCatalin Marinas	. = PAGE_OFFSET + TEXT_OFFSET;
928c2c3df3SCatalin Marinas
938c2c3df3SCatalin Marinas	.head.text : {
948c2c3df3SCatalin Marinas		_text = .;
958c2c3df3SCatalin Marinas		HEAD_TEXT
968c2c3df3SCatalin Marinas	}
97da141706SLaura Abbott	ALIGN_DEBUG_RO
988c2c3df3SCatalin Marinas	.text : {			/* Real text segment		*/
998c2c3df3SCatalin Marinas		_stext = .;		/* Text and read-only data	*/
1008c2c3df3SCatalin Marinas			__exception_text_start = .;
1018c2c3df3SCatalin Marinas			*(.exception.text)
1028c2c3df3SCatalin Marinas			__exception_text_end = .;
1038c2c3df3SCatalin Marinas			IRQENTRY_TEXT
1048c2c3df3SCatalin Marinas			TEXT_TEXT
1058c2c3df3SCatalin Marinas			SCHED_TEXT
1068c2c3df3SCatalin Marinas			LOCK_TEXT
1072240bbb6SMarc Zyngier			HYPERVISOR_TEXT
1085dfe9d7dSArd Biesheuvel			IDMAP_TEXT
1098c2c3df3SCatalin Marinas			*(.fixup)
1108c2c3df3SCatalin Marinas			*(.gnu.warning)
1118c2c3df3SCatalin Marinas		. = ALIGN(16);
1128c2c3df3SCatalin Marinas		*(.got)			/* Global offset table		*/
1138c2c3df3SCatalin Marinas	}
1148c2c3df3SCatalin Marinas
1158c2c3df3SCatalin Marinas	RO_DATA(PAGE_SIZE)
116adace895SWill Deacon	EXCEPTION_TABLE(8)
117c80b7ee8SMark Salter	NOTES
118da141706SLaura Abbott	ALIGN_DEBUG_RO
1198c2c3df3SCatalin Marinas	_etext = .;			/* End of text and rodata section */
1208c2c3df3SCatalin Marinas
121da141706SLaura Abbott	ALIGN_DEBUG_RO_MIN(PAGE_SIZE)
1228c2c3df3SCatalin Marinas	__init_begin = .;
1238c2c3df3SCatalin Marinas
1248c2c3df3SCatalin Marinas	INIT_TEXT_SECTION(8)
1258c2c3df3SCatalin Marinas	.exit.text : {
1268c2c3df3SCatalin Marinas		ARM_EXIT_KEEP(EXIT_TEXT)
1278c2c3df3SCatalin Marinas	}
128da141706SLaura Abbott
1298c2c3df3SCatalin Marinas	.init.data : {
1308c2c3df3SCatalin Marinas		INIT_DATA
1318c2c3df3SCatalin Marinas		INIT_SETUP(16)
1328c2c3df3SCatalin Marinas		INIT_CALLS
1338c2c3df3SCatalin Marinas		CON_INITCALL
1348c2c3df3SCatalin Marinas		SECURITY_INITCALL
1358c2c3df3SCatalin Marinas		INIT_RAM_FS
1368c2c3df3SCatalin Marinas	}
1378c2c3df3SCatalin Marinas	.exit.data : {
1388c2c3df3SCatalin Marinas		ARM_EXIT_KEEP(EXIT_DATA)
1398c2c3df3SCatalin Marinas	}
1408c2c3df3SCatalin Marinas
1418c2c3df3SCatalin Marinas	PERCPU_SECTION(64)
1428c2c3df3SCatalin Marinas
143e039ee4eSAndre Przywara	. = ALIGN(4);
144e039ee4eSAndre Przywara	.altinstructions : {
145e039ee4eSAndre Przywara		__alt_instructions = .;
146e039ee4eSAndre Przywara		*(.altinstructions)
147e039ee4eSAndre Przywara		__alt_instructions_end = .;
148e039ee4eSAndre Przywara	}
149e039ee4eSAndre Przywara	.altinstr_replacement : {
150e039ee4eSAndre Przywara		*(.altinstr_replacement)
151e039ee4eSAndre Przywara	}
152e039ee4eSAndre Przywara
153e039ee4eSAndre Przywara	. = ALIGN(PAGE_SIZE);
154*9aa4ec15SMark Rutland	__init_end = .;
155*9aa4ec15SMark Rutland
1563c620626SMark Salter	_data = .;
1578c2c3df3SCatalin Marinas	_sdata = .;
1583c620626SMark Salter	RW_DATA_SECTION(64, PAGE_SIZE, THREAD_SIZE)
159a352ea3eSArd Biesheuvel	PECOFF_EDATA_PADDING
1608c2c3df3SCatalin Marinas	_edata = .;
1618c2c3df3SCatalin Marinas
1628c2c3df3SCatalin Marinas	BSS_SECTION(0, 0, 0)
163bd00cd5fSMark Rutland
164bd00cd5fSMark Rutland	. = ALIGN(PAGE_SIZE);
165bd00cd5fSMark Rutland	idmap_pg_dir = .;
166bd00cd5fSMark Rutland	. += IDMAP_DIR_SIZE;
167bd00cd5fSMark Rutland	swapper_pg_dir = .;
168bd00cd5fSMark Rutland	. += SWAPPER_DIR_SIZE;
169bd00cd5fSMark Rutland
1708c2c3df3SCatalin Marinas	_end = .;
1718c2c3df3SCatalin Marinas
1728c2c3df3SCatalin Marinas	STABS_DEBUG
173a2c1d73bSMark Rutland
174a2c1d73bSMark Rutland	HEAD_SYMBOLS
1758c2c3df3SCatalin Marinas}
1762240bbb6SMarc Zyngier
1772240bbb6SMarc Zyngier/*
1785dfe9d7dSArd Biesheuvel * The HYP init code and ID map text can't be longer than a page each,
17906f75a1fSArd Biesheuvel * and should not cross a page boundary.
1802240bbb6SMarc Zyngier */
18106f75a1fSArd BiesheuvelASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
18206f75a1fSArd Biesheuvel	"HYP init code too big or misaligned")
1835dfe9d7dSArd BiesheuvelASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
1845dfe9d7dSArd Biesheuvel	"ID map text too big or misaligned")
185da57a369SMark Rutland
186da57a369SMark Rutland/*
187da57a369SMark Rutland * If padding is applied before .head.text, virt<->phys conversions will fail.
188da57a369SMark Rutland */
189da57a369SMark RutlandASSERT(_text == (PAGE_OFFSET + TEXT_OFFSET), "HEAD is misaligned")
190