xref: /openbmc/linux/arch/arm64/kernel/vmlinux.lds.S (revision 1e48ef7fcc374051730381a2a05da77eb4eafdb0)
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
49a352ea3eSArd Biesheuvel/*
50a352ea3eSArd Biesheuvel * The size of the PE/COFF section that covers the kernel image, which
51a352ea3eSArd Biesheuvel * runs from stext to _edata, must be a round multiple of the PE/COFF
52a352ea3eSArd Biesheuvel * FileAlignment, which we set to its minimum value of 0x200. 'stext'
53a352ea3eSArd Biesheuvel * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
54a352ea3eSArd Biesheuvel * boundary should be sufficient.
55a352ea3eSArd Biesheuvel */
56a352ea3eSArd BiesheuvelPECOFF_FILE_ALIGNMENT = 0x200;
57a352ea3eSArd Biesheuvel
58a352ea3eSArd Biesheuvel#ifdef CONFIG_EFI
59a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING	\
60a352ea3eSArd Biesheuvel	.pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
61a352ea3eSArd Biesheuvel#else
62a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING
63a352ea3eSArd Biesheuvel#endif
64a352ea3eSArd Biesheuvel
65cb083816SMark Rutland#if defined(CONFIG_DEBUG_ALIGN_RODATA)
66da141706SLaura Abbott#define ALIGN_DEBUG_RO			. = ALIGN(1<<SECTION_SHIFT);
67da141706SLaura Abbott#define ALIGN_DEBUG_RO_MIN(min)		ALIGN_DEBUG_RO
68cb083816SMark Rutland#elif defined(CONFIG_DEBUG_RODATA)
69cb083816SMark Rutland#define ALIGN_DEBUG_RO			. = ALIGN(1<<PAGE_SHIFT);
70cb083816SMark Rutland#define ALIGN_DEBUG_RO_MIN(min)		ALIGN_DEBUG_RO
71da141706SLaura Abbott#else
72da141706SLaura Abbott#define ALIGN_DEBUG_RO
73da141706SLaura Abbott#define ALIGN_DEBUG_RO_MIN(min)		. = ALIGN(min);
74da141706SLaura Abbott#endif
75da141706SLaura Abbott
768c2c3df3SCatalin MarinasSECTIONS
778c2c3df3SCatalin Marinas{
788c2c3df3SCatalin Marinas	/*
798c2c3df3SCatalin Marinas	 * XXX: The linker does not define how output sections are
808c2c3df3SCatalin Marinas	 * assigned to input sections when there are multiple statements
818c2c3df3SCatalin Marinas	 * matching the same input section name.  There is no documented
828c2c3df3SCatalin Marinas	 * order of matching.
838c2c3df3SCatalin Marinas	 */
848c2c3df3SCatalin Marinas	/DISCARD/ : {
858c2c3df3SCatalin Marinas		ARM_EXIT_DISCARD(EXIT_TEXT)
868c2c3df3SCatalin Marinas		ARM_EXIT_DISCARD(EXIT_DATA)
878c2c3df3SCatalin Marinas		EXIT_CALL
888c2c3df3SCatalin Marinas		*(.discard)
898c2c3df3SCatalin Marinas		*(.discard.*)
90*1e48ef7fSArd Biesheuvel		*(.interp .dynamic)
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	}
99fca082bfSMark Rutland	ALIGN_DEBUG_RO_MIN(PAGE_SIZE)
1008c2c3df3SCatalin Marinas	.text : {			/* Real text segment		*/
1018c2c3df3SCatalin Marinas		_stext = .;		/* Text and read-only data	*/
1028c2c3df3SCatalin Marinas			__exception_text_start = .;
1038c2c3df3SCatalin Marinas			*(.exception.text)
1048c2c3df3SCatalin Marinas			__exception_text_end = .;
1058c2c3df3SCatalin Marinas			IRQENTRY_TEXT
1068c2c3df3SCatalin Marinas			TEXT_TEXT
1078c2c3df3SCatalin Marinas			SCHED_TEXT
1088c2c3df3SCatalin Marinas			LOCK_TEXT
1092240bbb6SMarc Zyngier			HYPERVISOR_TEXT
1105dfe9d7dSArd Biesheuvel			IDMAP_TEXT
1118c2c3df3SCatalin Marinas			*(.fixup)
1128c2c3df3SCatalin Marinas			*(.gnu.warning)
1138c2c3df3SCatalin Marinas		. = ALIGN(16);
1148c2c3df3SCatalin Marinas		*(.got)			/* Global offset table		*/
1158c2c3df3SCatalin Marinas	}
1168c2c3df3SCatalin Marinas
1178c2c3df3SCatalin Marinas	RO_DATA(PAGE_SIZE)
118adace895SWill Deacon	EXCEPTION_TABLE(8)
119c80b7ee8SMark Salter	NOTES
1208c2c3df3SCatalin Marinas
121da141706SLaura Abbott	ALIGN_DEBUG_RO_MIN(PAGE_SIZE)
122fca082bfSMark Rutland	_etext = .;			/* End of text and rodata section */
1238c2c3df3SCatalin Marinas	__init_begin = .;
1248c2c3df3SCatalin Marinas
1258c2c3df3SCatalin Marinas	INIT_TEXT_SECTION(8)
1268c2c3df3SCatalin Marinas	.exit.text : {
1278c2c3df3SCatalin Marinas		ARM_EXIT_KEEP(EXIT_TEXT)
1288c2c3df3SCatalin Marinas	}
129da141706SLaura Abbott
1308c2c3df3SCatalin Marinas	.init.data : {
1318c2c3df3SCatalin Marinas		INIT_DATA
1328c2c3df3SCatalin Marinas		INIT_SETUP(16)
1338c2c3df3SCatalin Marinas		INIT_CALLS
1348c2c3df3SCatalin Marinas		CON_INITCALL
1358c2c3df3SCatalin Marinas		SECURITY_INITCALL
1368c2c3df3SCatalin Marinas		INIT_RAM_FS
1378c2c3df3SCatalin Marinas	}
1388c2c3df3SCatalin Marinas	.exit.data : {
1398c2c3df3SCatalin Marinas		ARM_EXIT_KEEP(EXIT_DATA)
1408c2c3df3SCatalin Marinas	}
1418c2c3df3SCatalin Marinas
14298fb7548SArd Biesheuvel	PERCPU_SECTION(L1_CACHE_BYTES)
1438c2c3df3SCatalin Marinas
144e039ee4eSAndre Przywara	. = ALIGN(4);
145e039ee4eSAndre Przywara	.altinstructions : {
146e039ee4eSAndre Przywara		__alt_instructions = .;
147e039ee4eSAndre Przywara		*(.altinstructions)
148e039ee4eSAndre Przywara		__alt_instructions_end = .;
149e039ee4eSAndre Przywara	}
150e039ee4eSAndre Przywara	.altinstr_replacement : {
151e039ee4eSAndre Przywara		*(.altinstr_replacement)
152e039ee4eSAndre Przywara	}
153*1e48ef7fSArd Biesheuvel	.rela : ALIGN(8) {
154*1e48ef7fSArd Biesheuvel		__reloc_start = .;
155*1e48ef7fSArd Biesheuvel		*(.rela .rela*)
156*1e48ef7fSArd Biesheuvel		__reloc_end = .;
157*1e48ef7fSArd Biesheuvel	}
158*1e48ef7fSArd Biesheuvel	.dynsym : ALIGN(8) {
159*1e48ef7fSArd Biesheuvel		__dynsym_start = .;
160*1e48ef7fSArd Biesheuvel		*(.dynsym)
161*1e48ef7fSArd Biesheuvel	}
162*1e48ef7fSArd Biesheuvel	.dynstr : {
163*1e48ef7fSArd Biesheuvel		*(.dynstr)
164*1e48ef7fSArd Biesheuvel	}
165*1e48ef7fSArd Biesheuvel	.hash : {
166*1e48ef7fSArd Biesheuvel		*(.hash)
167*1e48ef7fSArd Biesheuvel	}
168e039ee4eSAndre Przywara
169e039ee4eSAndre Przywara	. = ALIGN(PAGE_SIZE);
1709aa4ec15SMark Rutland	__init_end = .;
1719aa4ec15SMark Rutland
1723c620626SMark Salter	_data = .;
1738c2c3df3SCatalin Marinas	_sdata = .;
17498fb7548SArd Biesheuvel	RW_DATA_SECTION(L1_CACHE_BYTES, PAGE_SIZE, THREAD_SIZE)
175a352ea3eSArd Biesheuvel	PECOFF_EDATA_PADDING
1768c2c3df3SCatalin Marinas	_edata = .;
1778c2c3df3SCatalin Marinas
1788c2c3df3SCatalin Marinas	BSS_SECTION(0, 0, 0)
179bd00cd5fSMark Rutland
180bd00cd5fSMark Rutland	. = ALIGN(PAGE_SIZE);
181bd00cd5fSMark Rutland	idmap_pg_dir = .;
182bd00cd5fSMark Rutland	. += IDMAP_DIR_SIZE;
183bd00cd5fSMark Rutland	swapper_pg_dir = .;
184bd00cd5fSMark Rutland	. += SWAPPER_DIR_SIZE;
185bd00cd5fSMark Rutland
1868c2c3df3SCatalin Marinas	_end = .;
1878c2c3df3SCatalin Marinas
1888c2c3df3SCatalin Marinas	STABS_DEBUG
189a2c1d73bSMark Rutland
190a2c1d73bSMark Rutland	HEAD_SYMBOLS
1918c2c3df3SCatalin Marinas}
1922240bbb6SMarc Zyngier
1932240bbb6SMarc Zyngier/*
1945dfe9d7dSArd Biesheuvel * The HYP init code and ID map text can't be longer than a page each,
19506f75a1fSArd Biesheuvel * and should not cross a page boundary.
1962240bbb6SMarc Zyngier */
19706f75a1fSArd BiesheuvelASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
19806f75a1fSArd Biesheuvel	"HYP init code too big or misaligned")
1995dfe9d7dSArd BiesheuvelASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
2005dfe9d7dSArd Biesheuvel	"ID map text too big or misaligned")
201da57a369SMark Rutland
202da57a369SMark Rutland/*
203da57a369SMark Rutland * If padding is applied before .head.text, virt<->phys conversions will fail.
204da57a369SMark Rutland */
205ab893fb9SArd BiesheuvelASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned")
206