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 | ||
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 | |
22 | OUTPUT_ARCH(aarch64) | |
af885f40 | 23 | ENTRY(_text) |
8c2c3df3 CM |
24 | |
25 | jiffies = 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 | */ | |
78 | PECOFF_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 |
87 | SECTIONS |
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) |
08cc55b2 | 102 | *(.dynsym .dynstr .hash) |
8c2c3df3 CM |
103 | } |
104 | ||
ab893fb9 | 105 | . = KIMAGE_VADDR + TEXT_OFFSET; |
8c2c3df3 CM |
106 | |
107 | .head.text : { | |
108 | _text = .; | |
109 | HEAD_TEXT | |
110 | } | |
111 | .text : { /* Real text segment */ | |
112 | _stext = .; /* Text and read-only data */ | |
8c2c3df3 CM |
113 | __exception_text_start = .; |
114 | *(.exception.text) | |
115 | __exception_text_end = .; | |
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 | ||
137 | RO_DATA(PAGE_SIZE) /* everything from this point to */ | |
138 | EXCEPTION_TABLE(8) /* __init_begin will be marked RO NX */ | |
c80b7ee8 | 139 | NOTES |
8c2c3df3 | 140 | |
8eb7e28d JY |
141 | . = ALIGN(PAGE_SIZE); |
142 | idmap_pg_dir = .; | |
143 | . += IDMAP_DIR_SIZE; | |
144 | ||
145 | #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 | |
146 | tramp_pg_dir = .; | |
147 | . += PAGE_SIZE; | |
148 | #endif | |
149 | ||
150 | #ifdef CONFIG_ARM64_SW_TTBR0_PAN | |
151 | reserved_ttbr0 = .; | |
152 | . += RESERVED_TTBR0_SIZE; | |
153 | #endif | |
154 | swapper_pg_dir = .; | |
155 | . += PAGE_SIZE; | |
156 | swapper_pg_end = .; | |
157 | ||
97740051 | 158 | . = ALIGN(SEGMENT_ALIGN); |
8c2c3df3 | 159 | __init_begin = .; |
2ebe088b | 160 | __inittext_begin = .; |
8c2c3df3 CM |
161 | |
162 | INIT_TEXT_SECTION(8) | |
163 | .exit.text : { | |
164 | ARM_EXIT_KEEP(EXIT_TEXT) | |
165 | } | |
da141706 | 166 | |
2ebe088b AB |
167 | . = ALIGN(4); |
168 | .altinstructions : { | |
169 | __alt_instructions = .; | |
170 | *(.altinstructions) | |
171 | __alt_instructions_end = .; | |
172 | } | |
173 | .altinstr_replacement : { | |
174 | *(.altinstr_replacement) | |
175 | } | |
176 | ||
177 | . = ALIGN(PAGE_SIZE); | |
178 | __inittext_end = .; | |
179 | __initdata_begin = .; | |
180 | ||
8c2c3df3 CM |
181 | .init.data : { |
182 | INIT_DATA | |
183 | INIT_SETUP(16) | |
184 | INIT_CALLS | |
185 | CON_INITCALL | |
186 | SECURITY_INITCALL | |
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 | |
1e48ef7f | 196 | .rela : ALIGN(8) { |
1e48ef7f | 197 | *(.rela .rela*) |
1e48ef7f | 198 | } |
e039ee4e | 199 | |
d6732fc4 | 200 | __rela_offset = ABSOLUTE(ADDR(.rela) - KIMAGE_VADDR); |
0cd3defe | 201 | __rela_size = SIZEOF(.rela); |
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 |
252 | ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, |
253 | "HYP init code too big or misaligned") | |
5dfe9d7d AB |
254 | ASSERT(__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 |
257 | ASSERT(__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 |
261 | ASSERT((__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 | 267 | ASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned") |