License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[linux-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); \
2240bbb6
MZ
37 VMLINUX_SYMBOL(__hyp_idmap_text_start) = .; \
38 *(.hyp.idmap.text) \
39 VMLINUX_SYMBOL(__hyp_idmap_text_end) = .; \
40 VMLINUX_SYMBOL(__hyp_text_start) = .; \
41 *(.hyp.text) \
42 VMLINUX_SYMBOL(__hyp_text_end) = .;
43
5dfe9d7d
AB
44#define IDMAP_TEXT \
45 . = ALIGN(SZ_4K); \
46 VMLINUX_SYMBOL(__idmap_text_start) = .; \
47 *(.idmap.text) \
48 VMLINUX_SYMBOL(__idmap_text_end) = .;
49
82869ac5
JM
50#ifdef CONFIG_HIBERNATION
51#define HIBERNATE_TEXT \
52 . = ALIGN(SZ_4K); \
53 VMLINUX_SYMBOL(__hibernate_exit_text_start) = .;\
54 *(.hibernate_exit.text) \
55 VMLINUX_SYMBOL(__hibernate_exit_text_end) = .;
56#else
57#define HIBERNATE_TEXT
58#endif
59
a352ea3e
AB
60/*
61 * The size of the PE/COFF section that covers the kernel image, which
62 * runs from stext to _edata, must be a round multiple of the PE/COFF
63 * FileAlignment, which we set to its minimum value of 0x200. 'stext'
64 * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
65 * boundary should be sufficient.
66 */
67PECOFF_FILE_ALIGNMENT = 0x200;
68
69#ifdef CONFIG_EFI
70#define PECOFF_EDATA_PADDING \
71 .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
72#else
73#define PECOFF_EDATA_PADDING
74#endif
75
8c2c3df3
CM
76SECTIONS
77{
78 /*
79 * XXX: The linker does not define how output sections are
80 * assigned to input sections when there are multiple statements
81 * matching the same input section name. There is no documented
82 * order of matching.
83 */
84 /DISCARD/ : {
85 ARM_EXIT_DISCARD(EXIT_TEXT)
86 ARM_EXIT_DISCARD(EXIT_DATA)
87 EXIT_CALL
88 *(.discard)
89 *(.discard.*)
1e48ef7f 90 *(.interp .dynamic)
08cc55b2 91 *(.dynsym .dynstr .hash)
8c2c3df3
CM
92 }
93
ab893fb9 94 . = KIMAGE_VADDR + TEXT_OFFSET;
8c2c3df3
CM
95
96 .head.text : {
97 _text = .;
98 HEAD_TEXT
99 }
100 .text : { /* Real text segment */
101 _stext = .; /* Text and read-only data */
8c2c3df3
CM
102 __exception_text_start = .;
103 *(.exception.text)
104 __exception_text_end = .;
105 IRQENTRY_TEXT
be7635e7 106 SOFTIRQENTRY_TEXT
888b3c87 107 ENTRY_TEXT
8c2c3df3
CM
108 TEXT_TEXT
109 SCHED_TEXT
6727ad9e 110 CPUIDLE_TEXT
8c2c3df3 111 LOCK_TEXT
2dd0e8d2 112 KPROBES_TEXT
2240bbb6 113 HYPERVISOR_TEXT
5dfe9d7d 114 IDMAP_TEXT
82869ac5 115 HIBERNATE_TEXT
8c2c3df3
CM
116 *(.fixup)
117 *(.gnu.warning)
118 . = ALIGN(16);
119 *(.got) /* Global offset table */
120 }
121
97740051 122 . = ALIGN(SEGMENT_ALIGN);
9fdc14c5
AB
123 _etext = .; /* End of text section */
124
125 RO_DATA(PAGE_SIZE) /* everything from this point to */
126 EXCEPTION_TABLE(8) /* __init_begin will be marked RO NX */
c80b7ee8 127 NOTES
8c2c3df3 128
97740051 129 . = ALIGN(SEGMENT_ALIGN);
8c2c3df3 130 __init_begin = .;
2ebe088b 131 __inittext_begin = .;
8c2c3df3
CM
132
133 INIT_TEXT_SECTION(8)
134 .exit.text : {
135 ARM_EXIT_KEEP(EXIT_TEXT)
136 }
da141706 137
2ebe088b
AB
138 . = ALIGN(4);
139 .altinstructions : {
140 __alt_instructions = .;
141 *(.altinstructions)
142 __alt_instructions_end = .;
143 }
144 .altinstr_replacement : {
145 *(.altinstr_replacement)
146 }
147
148 . = ALIGN(PAGE_SIZE);
149 __inittext_end = .;
150 __initdata_begin = .;
151
8c2c3df3
CM
152 .init.data : {
153 INIT_DATA
154 INIT_SETUP(16)
155 INIT_CALLS
156 CON_INITCALL
157 SECURITY_INITCALL
158 INIT_RAM_FS
1ce99bf4 159 *(.init.rodata.* .init.bss) /* from the EFI stub */
8c2c3df3
CM
160 }
161 .exit.data : {
162 ARM_EXIT_KEEP(EXIT_DATA)
163 }
164
98fb7548 165 PERCPU_SECTION(L1_CACHE_BYTES)
8c2c3df3 166
1e48ef7f 167 .rela : ALIGN(8) {
1e48ef7f 168 *(.rela .rela*)
1e48ef7f 169 }
e039ee4e 170
d6732fc4 171 __rela_offset = ABSOLUTE(ADDR(.rela) - KIMAGE_VADDR);
0cd3defe 172 __rela_size = SIZEOF(.rela);
0cd3defe 173
97740051 174 . = ALIGN(SEGMENT_ALIGN);
2ebe088b 175 __initdata_end = .;
9aa4ec15
MR
176 __init_end = .;
177
3c620626 178 _data = .;
3c620626 179 _sdata = .;
e3067861 180 RW_DATA_SECTION(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
b6113038
JM
181
182 /*
183 * Data written with the MMU off but read with the MMU on requires
184 * cache lines to be invalidated, discarding up to a Cache Writeback
185 * Granule (CWG) of data from the cache. Keep the section that
186 * requires this type of maintenance to be in its own Cache Writeback
187 * Granule (CWG) area so the cache maintenance operations don't
188 * interfere with adjacent data.
189 */
190 .mmuoff.data.write : ALIGN(SZ_2K) {
191 __mmuoff_data_start = .;
192 *(.mmuoff.data.write)
193 }
194 . = ALIGN(SZ_2K);
195 .mmuoff.data.read : {
196 *(.mmuoff.data.read)
197 __mmuoff_data_end = .;
198 }
199
a352ea3e 200 PECOFF_EDATA_PADDING
cad27ef2 201 __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
3c620626 202 _edata = .;
8c2c3df3 203
8c2c3df3 204 BSS_SECTION(0, 0, 0)
bd00cd5f
MR
205
206 . = ALIGN(PAGE_SIZE);
207 idmap_pg_dir = .;
208 . += IDMAP_DIR_SIZE;
209 swapper_pg_dir = .;
210 . += SWAPPER_DIR_SIZE;
211
4b65a5db
CM
212#ifdef CONFIG_ARM64_SW_TTBR0_PAN
213 reserved_ttbr0 = .;
214 . += RESERVED_TTBR0_SIZE;
215#endif
216
cad27ef2 217 __pecoff_data_size = ABSOLUTE(. - __initdata_begin);
8c2c3df3
CM
218 _end = .;
219
220 STABS_DEBUG
a2c1d73b
MR
221
222 HEAD_SYMBOLS
8c2c3df3 223}
2240bbb6
MZ
224
225/*
5dfe9d7d 226 * The HYP init code and ID map text can't be longer than a page each,
06f75a1f 227 * and should not cross a page boundary.
2240bbb6 228 */
06f75a1f
AB
229ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
230 "HYP init code too big or misaligned")
5dfe9d7d
AB
231ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
232 "ID map text too big or misaligned")
82869ac5
JM
233#ifdef CONFIG_HIBERNATION
234ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
235 <= SZ_4K, "Hibernate exit text too big or misaligned")
236#endif
da57a369
MR
237
238/*
239 * If padding is applied before .head.text, virt<->phys conversions will fail.
240 */
ab893fb9 241ASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned")