]>
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); \ |
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 | ||
c7b9adaf WD |
60 | #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 |
61 | #define TRAMP_TEXT \ | |
62 | . = ALIGN(PAGE_SIZE); \ | |
63 | VMLINUX_SYMBOL(__entry_tramp_text_start) = .; \ | |
64 | *(.entry.tramp.text) \ | |
65 | . = ALIGN(PAGE_SIZE); \ | |
66 | VMLINUX_SYMBOL(__entry_tramp_text_end) = .; | |
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 | |
97740051 | 141 | . = ALIGN(SEGMENT_ALIGN); |
8c2c3df3 | 142 | __init_begin = .; |
2ebe088b | 143 | __inittext_begin = .; |
8c2c3df3 CM |
144 | |
145 | INIT_TEXT_SECTION(8) | |
146 | .exit.text : { | |
147 | ARM_EXIT_KEEP(EXIT_TEXT) | |
148 | } | |
da141706 | 149 | |
2ebe088b AB |
150 | . = ALIGN(4); |
151 | .altinstructions : { | |
152 | __alt_instructions = .; | |
153 | *(.altinstructions) | |
154 | __alt_instructions_end = .; | |
155 | } | |
156 | .altinstr_replacement : { | |
157 | *(.altinstr_replacement) | |
158 | } | |
159 | ||
160 | . = ALIGN(PAGE_SIZE); | |
161 | __inittext_end = .; | |
162 | __initdata_begin = .; | |
163 | ||
8c2c3df3 CM |
164 | .init.data : { |
165 | INIT_DATA | |
166 | INIT_SETUP(16) | |
167 | INIT_CALLS | |
168 | CON_INITCALL | |
169 | SECURITY_INITCALL | |
170 | INIT_RAM_FS | |
1ce99bf4 | 171 | *(.init.rodata.* .init.bss) /* from the EFI stub */ |
8c2c3df3 CM |
172 | } |
173 | .exit.data : { | |
174 | ARM_EXIT_KEEP(EXIT_DATA) | |
175 | } | |
176 | ||
98fb7548 | 177 | PERCPU_SECTION(L1_CACHE_BYTES) |
8c2c3df3 | 178 | |
1e48ef7f | 179 | .rela : ALIGN(8) { |
1e48ef7f | 180 | *(.rela .rela*) |
1e48ef7f | 181 | } |
e039ee4e | 182 | |
d6732fc4 | 183 | __rela_offset = ABSOLUTE(ADDR(.rela) - KIMAGE_VADDR); |
0cd3defe | 184 | __rela_size = SIZEOF(.rela); |
0cd3defe | 185 | |
97740051 | 186 | . = ALIGN(SEGMENT_ALIGN); |
2ebe088b | 187 | __initdata_end = .; |
9aa4ec15 MR |
188 | __init_end = .; |
189 | ||
3c620626 | 190 | _data = .; |
3c620626 | 191 | _sdata = .; |
e3067861 | 192 | RW_DATA_SECTION(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN) |
b6113038 JM |
193 | |
194 | /* | |
195 | * Data written with the MMU off but read with the MMU on requires | |
196 | * cache lines to be invalidated, discarding up to a Cache Writeback | |
197 | * Granule (CWG) of data from the cache. Keep the section that | |
198 | * requires this type of maintenance to be in its own Cache Writeback | |
199 | * Granule (CWG) area so the cache maintenance operations don't | |
200 | * interfere with adjacent data. | |
201 | */ | |
202 | .mmuoff.data.write : ALIGN(SZ_2K) { | |
203 | __mmuoff_data_start = .; | |
204 | *(.mmuoff.data.write) | |
205 | } | |
206 | . = ALIGN(SZ_2K); | |
207 | .mmuoff.data.read : { | |
208 | *(.mmuoff.data.read) | |
209 | __mmuoff_data_end = .; | |
210 | } | |
211 | ||
a352ea3e | 212 | PECOFF_EDATA_PADDING |
cad27ef2 | 213 | __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin); |
3c620626 | 214 | _edata = .; |
8c2c3df3 | 215 | |
8c2c3df3 | 216 | BSS_SECTION(0, 0, 0) |
bd00cd5f MR |
217 | |
218 | . = ALIGN(PAGE_SIZE); | |
219 | idmap_pg_dir = .; | |
220 | . += IDMAP_DIR_SIZE; | |
1e1b8c04 SC |
221 | |
222 | #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 | |
223 | tramp_pg_dir = .; | |
224 | . += PAGE_SIZE; | |
225 | #endif | |
226 | ||
4b65a5db CM |
227 | #ifdef CONFIG_ARM64_SW_TTBR0_PAN |
228 | reserved_ttbr0 = .; | |
229 | . += RESERVED_TTBR0_SIZE; | |
230 | #endif | |
9dfe4828 SC |
231 | swapper_pg_dir = .; |
232 | . += SWAPPER_DIR_SIZE; | |
0370b31e | 233 | swapper_pg_end = .; |
4b65a5db | 234 | |
cad27ef2 | 235 | __pecoff_data_size = ABSOLUTE(. - __initdata_begin); |
8c2c3df3 CM |
236 | _end = .; |
237 | ||
238 | STABS_DEBUG | |
a2c1d73b MR |
239 | |
240 | HEAD_SYMBOLS | |
8c2c3df3 | 241 | } |
2240bbb6 MZ |
242 | |
243 | /* | |
5dfe9d7d | 244 | * The HYP init code and ID map text can't be longer than a page each, |
06f75a1f | 245 | * and should not cross a page boundary. |
2240bbb6 | 246 | */ |
06f75a1f AB |
247 | ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, |
248 | "HYP init code too big or misaligned") | |
5dfe9d7d AB |
249 | ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, |
250 | "ID map text too big or misaligned") | |
82869ac5 JM |
251 | #ifdef CONFIG_HIBERNATION |
252 | ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1)) | |
253 | <= SZ_4K, "Hibernate exit text too big or misaligned") | |
254 | #endif | |
6c27c408 WD |
255 | #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 |
256 | ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE, | |
257 | "Entry trampoline text too big") | |
258 | #endif | |
da57a369 MR |
259 | /* |
260 | * If padding is applied before .head.text, virt<->phys conversions will fail. | |
261 | */ | |
ab893fb9 | 262 | ASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned") |