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/*
42 * The size of the PE/COFF section that covers the kernel image, which
43 * runs from stext to _edata, must be a round multiple of the PE/COFF
44 * FileAlignment, which we set to its minimum value of 0x200. 'stext'
45 * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
46 * boundary should be sufficient.
47 */
48PECOFF_FILE_ALIGNMENT = 0x200;
49
50#ifdef CONFIG_EFI
51#define PECOFF_EDATA_PADDING	\
52	.pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
53#else
54#define PECOFF_EDATA_PADDING
55#endif
56
57#if defined(CONFIG_DEBUG_ALIGN_RODATA)
58#define ALIGN_DEBUG_RO			. = ALIGN(1<<SECTION_SHIFT);
59#define ALIGN_DEBUG_RO_MIN(min)		ALIGN_DEBUG_RO
60#elif defined(CONFIG_DEBUG_RODATA)
61#define ALIGN_DEBUG_RO			. = ALIGN(1<<PAGE_SHIFT);
62#define ALIGN_DEBUG_RO_MIN(min)		ALIGN_DEBUG_RO
63#else
64#define ALIGN_DEBUG_RO
65#define ALIGN_DEBUG_RO_MIN(min)		. = ALIGN(min);
66#endif
67
68SECTIONS
69{
70	/*
71	 * XXX: The linker does not define how output sections are
72	 * assigned to input sections when there are multiple statements
73	 * matching the same input section name.  There is no documented
74	 * order of matching.
75	 */
76	/DISCARD/ : {
77		ARM_EXIT_DISCARD(EXIT_TEXT)
78		ARM_EXIT_DISCARD(EXIT_DATA)
79		EXIT_CALL
80		*(.discard)
81		*(.discard.*)
82	}
83
84	. = PAGE_OFFSET + TEXT_OFFSET;
85
86	.head.text : {
87		_text = .;
88		HEAD_TEXT
89	}
90	ALIGN_DEBUG_RO
91	.text : {			/* Real text segment		*/
92		_stext = .;		/* Text and read-only data	*/
93			__exception_text_start = .;
94			*(.exception.text)
95			__exception_text_end = .;
96			IRQENTRY_TEXT
97			TEXT_TEXT
98			SCHED_TEXT
99			LOCK_TEXT
100			HYPERVISOR_TEXT
101			*(.fixup)
102			*(.gnu.warning)
103		. = ALIGN(16);
104		*(.got)			/* Global offset table		*/
105	}
106
107	ALIGN_DEBUG_RO
108	RO_DATA(PAGE_SIZE)
109	EXCEPTION_TABLE(8)
110	NOTES
111	ALIGN_DEBUG_RO
112	_etext = .;			/* End of text and rodata section */
113
114	ALIGN_DEBUG_RO_MIN(PAGE_SIZE)
115	__init_begin = .;
116
117	INIT_TEXT_SECTION(8)
118	.exit.text : {
119		ARM_EXIT_KEEP(EXIT_TEXT)
120	}
121
122	ALIGN_DEBUG_RO_MIN(16)
123	.init.data : {
124		INIT_DATA
125		INIT_SETUP(16)
126		INIT_CALLS
127		CON_INITCALL
128		SECURITY_INITCALL
129		INIT_RAM_FS
130	}
131	.exit.data : {
132		ARM_EXIT_KEEP(EXIT_DATA)
133	}
134
135	PERCPU_SECTION(64)
136
137	. = ALIGN(PAGE_SIZE);
138	__init_end = .;
139
140	. = ALIGN(4);
141	.altinstructions : {
142		__alt_instructions = .;
143		*(.altinstructions)
144		__alt_instructions_end = .;
145	}
146	.altinstr_replacement : {
147		*(.altinstr_replacement)
148	}
149
150	. = ALIGN(PAGE_SIZE);
151	_data = .;
152	_sdata = .;
153	RW_DATA_SECTION(64, PAGE_SIZE, THREAD_SIZE)
154	PECOFF_EDATA_PADDING
155	_edata = .;
156
157	BSS_SECTION(0, 0, 0)
158
159	. = ALIGN(PAGE_SIZE);
160	idmap_pg_dir = .;
161	. += IDMAP_DIR_SIZE;
162	swapper_pg_dir = .;
163	. += SWAPPER_DIR_SIZE;
164
165	_end = .;
166
167	STABS_DEBUG
168
169	HEAD_SYMBOLS
170}
171
172/*
173 * The HYP init code can't be more than a page long,
174 * and should not cross a page boundary.
175 */
176ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
177	"HYP init code too big or misaligned")
178
179/*
180 * If padding is applied before .head.text, virt<->phys conversions will fail.
181 */
182ASSERT(_text == (PAGE_OFFSET + TEXT_OFFSET), "HEAD is misaligned")
183