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