xref: /linux/arch/arm64/kernel/vmlinux.lds.S (revision ca55b2fef3a9373fcfc30f82fd26bc7fccbda732)
1/*
2 * ld script to make ARM Linux kernel
3 * taken from the i386 version by Russell King
4 * Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>
5 */
6
7#include <asm-generic/vmlinux.lds.h>
8#include <asm/thread_info.h>
9#include <asm/memory.h>
10#include <asm/page.h>
11#include <asm/pgtable.h>
12
13#include "image.h"
14
15/* .exit.text needed in case of alternative patching */
16#define ARM_EXIT_KEEP(x)	x
17#define ARM_EXIT_DISCARD(x)
18
19OUTPUT_ARCH(aarch64)
20ENTRY(_text)
21
22jiffies = jiffies_64;
23
24#define HYPERVISOR_TEXT					\
25	/*						\
26	 * Align to 4 KB so that			\
27	 * a) the HYP vector table is at its minimum	\
28	 *    alignment of 2048 bytes			\
29	 * b) the HYP init code will not cross a page	\
30	 *    boundary if its size does not exceed	\
31	 *    4 KB (see related ASSERT() below)		\
32	 */						\
33	. = ALIGN(SZ_4K);				\
34	VMLINUX_SYMBOL(__hyp_idmap_text_start) = .;	\
35	*(.hyp.idmap.text)				\
36	VMLINUX_SYMBOL(__hyp_idmap_text_end) = .;	\
37	VMLINUX_SYMBOL(__hyp_text_start) = .;		\
38	*(.hyp.text)					\
39	VMLINUX_SYMBOL(__hyp_text_end) = .;
40
41#define IDMAP_TEXT					\
42	. = ALIGN(SZ_4K);				\
43	VMLINUX_SYMBOL(__idmap_text_start) = .;		\
44	*(.idmap.text)					\
45	VMLINUX_SYMBOL(__idmap_text_end) = .;
46
47/*
48 * The size of the PE/COFF section that covers the kernel image, which
49 * runs from stext to _edata, must be a round multiple of the PE/COFF
50 * FileAlignment, which we set to its minimum value of 0x200. 'stext'
51 * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
52 * boundary should be sufficient.
53 */
54PECOFF_FILE_ALIGNMENT = 0x200;
55
56#ifdef CONFIG_EFI
57#define PECOFF_EDATA_PADDING	\
58	.pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
59#else
60#define PECOFF_EDATA_PADDING
61#endif
62
63#ifdef CONFIG_DEBUG_ALIGN_RODATA
64#define ALIGN_DEBUG_RO			. = ALIGN(1<<SECTION_SHIFT);
65#define ALIGN_DEBUG_RO_MIN(min)		ALIGN_DEBUG_RO
66#else
67#define ALIGN_DEBUG_RO
68#define ALIGN_DEBUG_RO_MIN(min)		. = ALIGN(min);
69#endif
70
71SECTIONS
72{
73	/*
74	 * XXX: The linker does not define how output sections are
75	 * assigned to input sections when there are multiple statements
76	 * matching the same input section name.  There is no documented
77	 * order of matching.
78	 */
79	/DISCARD/ : {
80		ARM_EXIT_DISCARD(EXIT_TEXT)
81		ARM_EXIT_DISCARD(EXIT_DATA)
82		EXIT_CALL
83		*(.discard)
84		*(.discard.*)
85	}
86
87	. = PAGE_OFFSET + TEXT_OFFSET;
88
89	.head.text : {
90		_text = .;
91		HEAD_TEXT
92	}
93	ALIGN_DEBUG_RO
94	.text : {			/* Real text segment		*/
95		_stext = .;		/* Text and read-only data	*/
96			__exception_text_start = .;
97			*(.exception.text)
98			__exception_text_end = .;
99			IRQENTRY_TEXT
100			TEXT_TEXT
101			SCHED_TEXT
102			LOCK_TEXT
103			HYPERVISOR_TEXT
104			IDMAP_TEXT
105			*(.fixup)
106			*(.gnu.warning)
107		. = ALIGN(16);
108		*(.got)			/* Global offset table		*/
109	}
110
111	ALIGN_DEBUG_RO
112	RO_DATA(PAGE_SIZE)
113	EXCEPTION_TABLE(8)
114	NOTES
115	ALIGN_DEBUG_RO
116	_etext = .;			/* End of text and rodata section */
117
118	ALIGN_DEBUG_RO_MIN(PAGE_SIZE)
119	__init_begin = .;
120
121	INIT_TEXT_SECTION(8)
122	.exit.text : {
123		ARM_EXIT_KEEP(EXIT_TEXT)
124	}
125
126	ALIGN_DEBUG_RO_MIN(16)
127	.init.data : {
128		INIT_DATA
129		INIT_SETUP(16)
130		INIT_CALLS
131		CON_INITCALL
132		SECURITY_INITCALL
133		INIT_RAM_FS
134	}
135	.exit.data : {
136		ARM_EXIT_KEEP(EXIT_DATA)
137	}
138
139	PERCPU_SECTION(64)
140
141	. = ALIGN(PAGE_SIZE);
142	__init_end = .;
143
144	. = ALIGN(4);
145	.altinstructions : {
146		__alt_instructions = .;
147		*(.altinstructions)
148		__alt_instructions_end = .;
149	}
150	.altinstr_replacement : {
151		*(.altinstr_replacement)
152	}
153
154	. = ALIGN(PAGE_SIZE);
155	_data = .;
156	_sdata = .;
157	RW_DATA_SECTION(64, PAGE_SIZE, THREAD_SIZE)
158	PECOFF_EDATA_PADDING
159	_edata = .;
160
161	BSS_SECTION(0, 0, 0)
162
163	. = ALIGN(PAGE_SIZE);
164	idmap_pg_dir = .;
165	. += IDMAP_DIR_SIZE;
166	swapper_pg_dir = .;
167	. += SWAPPER_DIR_SIZE;
168
169	_end = .;
170
171	STABS_DEBUG
172
173	HEAD_SYMBOLS
174}
175
176/*
177 * The HYP init code and ID map text can't be longer than a page each,
178 * and should not cross a page boundary.
179 */
180ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
181	"HYP init code too big or misaligned")
182ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
183	"ID map text too big or misaligned")
184
185/*
186 * If padding is applied before .head.text, virt<->phys conversions will fail.
187 */
188ASSERT(_text == (PAGE_OFFSET + TEXT_OFFSET), "HEAD is misaligned")
189