Merge branch 'for-5.1' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq
[linux-2.6-block.git] / arch / arm64 / kernel / vmlinux.lds.S
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
8c2c3df3
CM
2/*
3 * ld script to make ARM Linux kernel
4 * taken from the i386 version by Russell King
5 * Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>
6 */
7
8#include <asm-generic/vmlinux.lds.h>
98fb7548 9#include <asm/cache.h>
87d1587b 10#include <asm/kernel-pgtable.h>
8c2c3df3
CM
11#include <asm/thread_info.h>
12#include <asm/memory.h>
13#include <asm/page.h>
da141706 14#include <asm/pgtable.h>
8c2c3df3 15
a2c1d73b
MR
16#include "image.h"
17
07c802bd
WD
18/* .exit.text needed in case of alternative patching */
19#define ARM_EXIT_KEEP(x) x
20#define ARM_EXIT_DISCARD(x)
8c2c3df3
CM
21
22OUTPUT_ARCH(aarch64)
af885f40 23ENTRY(_text)
8c2c3df3
CM
24
25jiffies = jiffies_64;
26
2240bbb6
MZ
27#define HYPERVISOR_TEXT \
28 /* \
06f75a1f
AB
29 * Align to 4 KB so that \
30 * a) the HYP vector table is at its minimum \
31 * alignment of 2048 bytes \
32 * b) the HYP init code will not cross a page \
33 * boundary if its size does not exceed \
34 * 4 KB (see related ASSERT() below) \
2240bbb6 35 */ \
06f75a1f 36 . = ALIGN(SZ_4K); \
5c636aa0 37 __hyp_idmap_text_start = .; \
2240bbb6 38 *(.hyp.idmap.text) \
5c636aa0
MY
39 __hyp_idmap_text_end = .; \
40 __hyp_text_start = .; \
2240bbb6 41 *(.hyp.text) \
5c636aa0 42 __hyp_text_end = .;
2240bbb6 43
5dfe9d7d
AB
44#define IDMAP_TEXT \
45 . = ALIGN(SZ_4K); \
5c636aa0 46 __idmap_text_start = .; \
5dfe9d7d 47 *(.idmap.text) \
5c636aa0 48 __idmap_text_end = .;
5dfe9d7d 49
82869ac5
JM
50#ifdef CONFIG_HIBERNATION
51#define HIBERNATE_TEXT \
52 . = ALIGN(SZ_4K); \
5c636aa0 53 __hibernate_exit_text_start = .; \
82869ac5 54 *(.hibernate_exit.text) \
5c636aa0 55 __hibernate_exit_text_end = .;
82869ac5
JM
56#else
57#define HIBERNATE_TEXT
58#endif
59
c7b9adaf
WD
60#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
61#define TRAMP_TEXT \
62 . = ALIGN(PAGE_SIZE); \
5c636aa0 63 __entry_tramp_text_start = .; \
c7b9adaf
WD
64 *(.entry.tramp.text) \
65 . = ALIGN(PAGE_SIZE); \
5c636aa0 66 __entry_tramp_text_end = .;
c7b9adaf
WD
67#else
68#define TRAMP_TEXT
69#endif
70
a352ea3e
AB
71/*
72 * The size of the PE/COFF section that covers the kernel image, which
73 * runs from stext to _edata, must be a round multiple of the PE/COFF
74 * FileAlignment, which we set to its minimum value of 0x200. 'stext'
75 * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
76 * boundary should be sufficient.
77 */
78PECOFF_FILE_ALIGNMENT = 0x200;
79
80#ifdef CONFIG_EFI
81#define PECOFF_EDATA_PADDING \
82 .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
83#else
84#define PECOFF_EDATA_PADDING
85#endif
86
8c2c3df3
CM
87SECTIONS
88{
89 /*
90 * XXX: The linker does not define how output sections are
91 * assigned to input sections when there are multiple statements
92 * matching the same input section name. There is no documented
93 * order of matching.
94 */
95 /DISCARD/ : {
96 ARM_EXIT_DISCARD(EXIT_TEXT)
97 ARM_EXIT_DISCARD(EXIT_DATA)
98 EXIT_CALL
99 *(.discard)
100 *(.discard.*)
1e48ef7f 101 *(.interp .dynamic)
3bbd3db8
AB
102 *(.dynsym .dynstr .hash .gnu.hash)
103 *(.eh_frame)
8c2c3df3
CM
104 }
105
ab893fb9 106 . = KIMAGE_VADDR + TEXT_OFFSET;
8c2c3df3
CM
107
108 .head.text : {
109 _text = .;
110 HEAD_TEXT
111 }
112 .text : { /* Real text segment */
113 _stext = .; /* Text and read-only data */
8c2c3df3
CM
114 __exception_text_start = .;
115 *(.exception.text)
116 __exception_text_end = .;
117 IRQENTRY_TEXT
be7635e7 118 SOFTIRQENTRY_TEXT
888b3c87 119 ENTRY_TEXT
8c2c3df3
CM
120 TEXT_TEXT
121 SCHED_TEXT
6727ad9e 122 CPUIDLE_TEXT
8c2c3df3 123 LOCK_TEXT
2dd0e8d2 124 KPROBES_TEXT
2240bbb6 125 HYPERVISOR_TEXT
5dfe9d7d 126 IDMAP_TEXT
82869ac5 127 HIBERNATE_TEXT
c7b9adaf 128 TRAMP_TEXT
8c2c3df3
CM
129 *(.fixup)
130 *(.gnu.warning)
131 . = ALIGN(16);
132 *(.got) /* Global offset table */
133 }
134
97740051 135 . = ALIGN(SEGMENT_ALIGN);
9fdc14c5
AB
136 _etext = .; /* End of text section */
137
138 RO_DATA(PAGE_SIZE) /* everything from this point to */
139 EXCEPTION_TABLE(8) /* __init_begin will be marked RO NX */
c80b7ee8 140 NOTES
8c2c3df3 141
8eb7e28d
JY
142 . = ALIGN(PAGE_SIZE);
143 idmap_pg_dir = .;
144 . += IDMAP_DIR_SIZE;
145
146#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
147 tramp_pg_dir = .;
148 . += PAGE_SIZE;
149#endif
150
151#ifdef CONFIG_ARM64_SW_TTBR0_PAN
152 reserved_ttbr0 = .;
153 . += RESERVED_TTBR0_SIZE;
154#endif
155 swapper_pg_dir = .;
156 . += PAGE_SIZE;
157 swapper_pg_end = .;
158
97740051 159 . = ALIGN(SEGMENT_ALIGN);
8c2c3df3 160 __init_begin = .;
2ebe088b 161 __inittext_begin = .;
8c2c3df3
CM
162
163 INIT_TEXT_SECTION(8)
164 .exit.text : {
165 ARM_EXIT_KEEP(EXIT_TEXT)
166 }
da141706 167
2ebe088b
AB
168 . = ALIGN(4);
169 .altinstructions : {
170 __alt_instructions = .;
171 *(.altinstructions)
172 __alt_instructions_end = .;
173 }
174 .altinstr_replacement : {
175 *(.altinstr_replacement)
176 }
177
178 . = ALIGN(PAGE_SIZE);
179 __inittext_end = .;
180 __initdata_begin = .;
181
8c2c3df3
CM
182 .init.data : {
183 INIT_DATA
184 INIT_SETUP(16)
185 INIT_CALLS
186 CON_INITCALL
8c2c3df3 187 INIT_RAM_FS
1ce99bf4 188 *(.init.rodata.* .init.bss) /* from the EFI stub */
8c2c3df3
CM
189 }
190 .exit.data : {
191 ARM_EXIT_KEEP(EXIT_DATA)
192 }
193
98fb7548 194 PERCPU_SECTION(L1_CACHE_BYTES)
8c2c3df3 195
3bbd3db8 196 .rela.dyn : ALIGN(8) {
1e48ef7f 197 *(.rela .rela*)
1e48ef7f 198 }
e039ee4e 199
3bbd3db8
AB
200 __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR);
201 __rela_size = SIZEOF(.rela.dyn);
0cd3defe 202
97740051 203 . = ALIGN(SEGMENT_ALIGN);
2ebe088b 204 __initdata_end = .;
9aa4ec15
MR
205 __init_end = .;
206
3c620626 207 _data = .;
3c620626 208 _sdata = .;
e3067861 209 RW_DATA_SECTION(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
b6113038
JM
210
211 /*
212 * Data written with the MMU off but read with the MMU on requires
213 * cache lines to be invalidated, discarding up to a Cache Writeback
214 * Granule (CWG) of data from the cache. Keep the section that
215 * requires this type of maintenance to be in its own Cache Writeback
216 * Granule (CWG) area so the cache maintenance operations don't
217 * interfere with adjacent data.
218 */
219 .mmuoff.data.write : ALIGN(SZ_2K) {
220 __mmuoff_data_start = .;
221 *(.mmuoff.data.write)
222 }
223 . = ALIGN(SZ_2K);
224 .mmuoff.data.read : {
225 *(.mmuoff.data.read)
226 __mmuoff_data_end = .;
227 }
228
a352ea3e 229 PECOFF_EDATA_PADDING
cad27ef2 230 __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
3c620626 231 _edata = .;
8c2c3df3 232
8c2c3df3 233 BSS_SECTION(0, 0, 0)
bd00cd5f
MR
234
235 . = ALIGN(PAGE_SIZE);
2b5548b6
JY
236 init_pg_dir = .;
237 . += INIT_DIR_SIZE;
238 init_pg_end = .;
239
cad27ef2 240 __pecoff_data_size = ABSOLUTE(. - __initdata_begin);
8c2c3df3
CM
241 _end = .;
242
243 STABS_DEBUG
a2c1d73b
MR
244
245 HEAD_SYMBOLS
8c2c3df3 246}
2240bbb6
MZ
247
248/*
5dfe9d7d 249 * The HYP init code and ID map text can't be longer than a page each,
06f75a1f 250 * and should not cross a page boundary.
2240bbb6 251 */
06f75a1f
AB
252ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
253 "HYP init code too big or misaligned")
5dfe9d7d
AB
254ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
255 "ID map text too big or misaligned")
82869ac5
JM
256#ifdef CONFIG_HIBERNATION
257ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
258 <= SZ_4K, "Hibernate exit text too big or misaligned")
259#endif
6c27c408
WD
260#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
261ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE,
262 "Entry trampoline text too big")
263#endif
da57a369
MR
264/*
265 * If padding is applied before .head.text, virt<->phys conversions will fail.
266 */
ab893fb9 267ASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned")