]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
17ce265d SR |
2 | /* |
3 | * ld script for the x86 kernel | |
4 | * | |
5 | * Historic 32-bit version written by Martin Mares <mj@atrey.karlin.mff.cuni.cz> | |
6 | * | |
91fd7fe8 IM |
7 | * Modernisation, unification and other changes and fixes: |
8 | * Copyright (C) 2007-2009 Sam Ravnborg <sam@ravnborg.org> | |
17ce265d SR |
9 | * |
10 | * | |
11 | * Don't define absolute symbols until and unless you know that symbol | |
12 | * value is should remain constant even if kernel image is relocated | |
13 | * at run time. Absolute symbols are not relocated. If symbol value should | |
14 | * change if kernel is relocated, make the symbol section relative and | |
15 | * put it inside the section definition. | |
16 | */ | |
17 | ||
18 | #ifdef CONFIG_X86_32 | |
19 | #define LOAD_OFFSET __PAGE_OFFSET | |
20 | #else | |
21 | #define LOAD_OFFSET __START_KERNEL_map | |
22 | #endif | |
23 | ||
24 | #include <asm-generic/vmlinux.lds.h> | |
25 | #include <asm/asm-offsets.h> | |
26 | #include <asm/thread_info.h> | |
27 | #include <asm/page_types.h> | |
ee9f8fce | 28 | #include <asm/orc_lookup.h> |
17ce265d SR |
29 | #include <asm/cache.h> |
30 | #include <asm/boot.h> | |
31 | ||
32 | #undef i386 /* in case the preprocessor is a 32bit one */ | |
33 | ||
34 | OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT, CONFIG_OUTPUT_FORMAT, CONFIG_OUTPUT_FORMAT) | |
35 | ||
36 | #ifdef CONFIG_X86_32 | |
37 | OUTPUT_ARCH(i386) | |
38 | ENTRY(phys_startup_32) | |
6b35eb9d | 39 | jiffies = jiffies_64; |
17ce265d SR |
40 | #else |
41 | OUTPUT_ARCH(i386:x86-64) | |
42 | ENTRY(phys_startup_64) | |
6b35eb9d | 43 | jiffies_64 = jiffies; |
17ce265d SR |
44 | #endif |
45 | ||
9ccaf77c | 46 | #if defined(CONFIG_X86_64) |
d6cc1c3a | 47 | /* |
9ccaf77c KC |
48 | * On 64-bit, align RODATA to 2MB so we retain large page mappings for |
49 | * boundaries spanning kernel text, rodata and data sections. | |
d6cc1c3a SS |
50 | * |
51 | * However, kernel identity mappings will have different RWX permissions | |
52 | * to the pages mapping to text and to the pages padding (which are freed) the | |
53 | * text section. Hence kernel identity mappings will be broken to smaller | |
54 | * pages. For 64-bit, kernel text and kernel identity mappings are different, | |
9ccaf77c KC |
55 | * so we can enable protection checks as well as retain 2MB large page |
56 | * mappings for kernel text. | |
d6cc1c3a | 57 | */ |
9ccaf77c | 58 | #define X64_ALIGN_RODATA_BEGIN . = ALIGN(HPAGE_SIZE); |
74e08179 | 59 | |
9ccaf77c | 60 | #define X64_ALIGN_RODATA_END \ |
74e08179 SS |
61 | . = ALIGN(HPAGE_SIZE); \ |
62 | __end_rodata_hpage_align = .; | |
63 | ||
64 | #else | |
65 | ||
9ccaf77c KC |
66 | #define X64_ALIGN_RODATA_BEGIN |
67 | #define X64_ALIGN_RODATA_END | |
74e08179 SS |
68 | |
69 | #endif | |
70 | ||
afb8095a SR |
71 | PHDRS { |
72 | text PT_LOAD FLAGS(5); /* R_E */ | |
5bd5a452 | 73 | data PT_LOAD FLAGS(6); /* RW_ */ |
afb8095a | 74 | #ifdef CONFIG_X86_64 |
afb8095a | 75 | #ifdef CONFIG_SMP |
8d0cc631 | 76 | percpu PT_LOAD FLAGS(6); /* RW_ */ |
afb8095a | 77 | #endif |
c62e4320 | 78 | init PT_LOAD FLAGS(7); /* RWE */ |
afb8095a SR |
79 | #endif |
80 | note PT_NOTE FLAGS(0); /* ___ */ | |
81 | } | |
17ce265d | 82 | |
444e0ae4 SR |
83 | SECTIONS |
84 | { | |
85 | #ifdef CONFIG_X86_32 | |
142b9e6c AB |
86 | . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR; |
87 | phys_startup_32 = ABSOLUTE(startup_32 - LOAD_OFFSET); | |
444e0ae4 | 88 | #else |
142b9e6c AB |
89 | . = __START_KERNEL; |
90 | phys_startup_64 = ABSOLUTE(startup_64 - LOAD_OFFSET); | |
444e0ae4 SR |
91 | #endif |
92 | ||
dfc20895 | 93 | /* Text and read-only data */ |
dfc20895 | 94 | .text : AT(ADDR(.text) - LOAD_OFFSET) { |
4ae59b91 | 95 | _text = .; |
e728f61c | 96 | _stext = .; |
4ae59b91 TA |
97 | /* bootstrapping code */ |
98 | HEAD_TEXT | |
dfc20895 | 99 | . = ALIGN(8); |
dfc20895 SR |
100 | TEXT_TEXT |
101 | SCHED_TEXT | |
6727ad9e | 102 | CPUIDLE_TEXT |
dfc20895 SR |
103 | LOCK_TEXT |
104 | KPROBES_TEXT | |
ea714547 | 105 | ENTRY_TEXT |
dfc20895 | 106 | IRQENTRY_TEXT |
be7635e7 | 107 | SOFTIRQENTRY_TEXT |
dfc20895 SR |
108 | *(.fixup) |
109 | *(.gnu.warning) | |
110 | /* End of text section */ | |
111 | _etext = .; | |
112 | } :text = 0x9090 | |
113 | ||
114 | NOTES :text :note | |
115 | ||
123f3e1d | 116 | EXCEPTION_TABLE(16) :text = 0x9090 |
448bc3ab | 117 | |
5bd5a452 MC |
118 | /* .text should occupy whole number of pages */ |
119 | . = ALIGN(PAGE_SIZE); | |
9ccaf77c | 120 | X64_ALIGN_RODATA_BEGIN |
c62e4320 | 121 | RO_DATA(PAGE_SIZE) |
9ccaf77c | 122 | X64_ALIGN_RODATA_END |
448bc3ab | 123 | |
1f6397ba | 124 | /* Data */ |
1f6397ba | 125 | .data : AT(ADDR(.data) - LOAD_OFFSET) { |
1260866a CM |
126 | /* Start of data section */ |
127 | _sdata = .; | |
c62e4320 JB |
128 | |
129 | /* init_task */ | |
130 | INIT_TASK_DATA(THREAD_SIZE) | |
1f6397ba SR |
131 | |
132 | #ifdef CONFIG_X86_32 | |
c62e4320 JB |
133 | /* 32 bit has nosave before _edata */ |
134 | NOSAVE_DATA | |
1f6397ba SR |
135 | #endif |
136 | ||
c62e4320 | 137 | PAGE_ALIGNED_DATA(PAGE_SIZE) |
1f6397ba | 138 | |
350f8f56 | 139 | CACHELINE_ALIGNED_DATA(L1_CACHE_BYTES) |
1f6397ba | 140 | |
c62e4320 JB |
141 | DATA_DATA |
142 | CONSTRUCTORS | |
143 | ||
144 | /* rarely changed data like cpu maps */ | |
350f8f56 | 145 | READ_MOSTLY_DATA(INTERNODE_CACHE_BYTES) |
1f6397ba | 146 | |
1f6397ba SR |
147 | /* End of data section */ |
148 | _edata = .; | |
c62e4320 | 149 | } :data |
1f6397ba | 150 | |
b5effd38 | 151 | BUG_TABLE |
ff6f87e1 | 152 | |
ee9f8fce JP |
153 | ORC_UNWIND_TABLE |
154 | ||
9c40818d AL |
155 | . = ALIGN(PAGE_SIZE); |
156 | __vvar_page = .; | |
157 | ||
158 | .vvar : AT(ADDR(.vvar) - LOAD_OFFSET) { | |
f670bb76 AL |
159 | /* work around gold bug 13023 */ |
160 | __vvar_beginning_hack = .; | |
9c40818d | 161 | |
f670bb76 AL |
162 | /* Place all vvars at the offsets in asm/vvar.h. */ |
163 | #define EMIT_VVAR(name, offset) \ | |
164 | . = __vvar_beginning_hack + offset; \ | |
9c40818d AL |
165 | *(.vvar_ ## name) |
166 | #define __VVAR_KERNEL_LDS | |
167 | #include <asm/vvar.h> | |
168 | #undef __VVAR_KERNEL_LDS | |
169 | #undef EMIT_VVAR | |
170 | ||
309944be AL |
171 | /* |
172 | * Pad the rest of the page with zeros. Otherwise the loader | |
173 | * can leave garbage here. | |
174 | */ | |
175 | . = __vvar_beginning_hack + PAGE_SIZE; | |
9c40818d AL |
176 | } :data |
177 | ||
178 | . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE); | |
179 | ||
c62e4320 JB |
180 | /* Init code and data - will be freed after init */ |
181 | . = ALIGN(PAGE_SIZE); | |
182 | .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) { | |
183 | __init_begin = .; /* paired with __init_end */ | |
e58bdaa8 | 184 | } |
e58bdaa8 | 185 | |
c62e4320 | 186 | #if defined(CONFIG_X86_64) && defined(CONFIG_SMP) |
e58bdaa8 | 187 | /* |
c62e4320 JB |
188 | * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the |
189 | * output PHDR, so the next output section - .init.text - should | |
190 | * start another segment - init. | |
e58bdaa8 | 191 | */ |
19df0c2f | 192 | PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu) |
97b67ae5 JB |
193 | ASSERT(SIZEOF(.data..percpu) < CONFIG_PHYSICAL_START, |
194 | "per-CPU data too large - increase CONFIG_PHYSICAL_START") | |
c62e4320 | 195 | #endif |
e58bdaa8 | 196 | |
123f3e1d | 197 | INIT_TEXT_SECTION(PAGE_SIZE) |
c62e4320 JB |
198 | #ifdef CONFIG_X86_64 |
199 | :init | |
200 | #endif | |
e58bdaa8 | 201 | |
337e4cc8 BP |
202 | /* |
203 | * Section for code used exclusively before alternatives are run. All | |
204 | * references to such code must be patched out by alternatives, normally | |
205 | * by using X86_FEATURE_ALWAYS CPU feature bit. | |
206 | * | |
207 | * See static_cpu_has() for an example. | |
208 | */ | |
209 | .altinstr_aux : AT(ADDR(.altinstr_aux) - LOAD_OFFSET) { | |
210 | *(.altinstr_aux) | |
211 | } | |
212 | ||
123f3e1d | 213 | INIT_DATA_SECTION(16) |
e58bdaa8 SR |
214 | |
215 | .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) { | |
216 | __x86_cpu_dev_start = .; | |
217 | *(.x86_cpu_dev.init) | |
218 | __x86_cpu_dev_end = .; | |
219 | } | |
220 | ||
66ac5013 DC |
221 | #ifdef CONFIG_X86_INTEL_MID |
222 | .x86_intel_mid_dev.init : AT(ADDR(.x86_intel_mid_dev.init) - \ | |
223 | LOAD_OFFSET) { | |
224 | __x86_intel_mid_dev_start = .; | |
225 | *(.x86_intel_mid_dev.init) | |
226 | __x86_intel_mid_dev_end = .; | |
227 | } | |
228 | #endif | |
229 | ||
6f44d033 KRW |
230 | /* |
231 | * start address and size of operations which during runtime | |
232 | * can be patched with virtualization friendly instructions or | |
233 | * baremetal native ones. Think page table operations. | |
234 | * Details in paravirt_types.h | |
235 | */ | |
ae618362 SR |
236 | . = ALIGN(8); |
237 | .parainstructions : AT(ADDR(.parainstructions) - LOAD_OFFSET) { | |
238 | __parainstructions = .; | |
239 | *(.parainstructions) | |
240 | __parainstructions_end = .; | |
241 | } | |
242 | ||
6f44d033 KRW |
243 | /* |
244 | * struct alt_inst entries. From the header (alternative.h): | |
245 | * "Alternative instructions for different CPU types or capabilities" | |
246 | * Think locking instructions on spinlocks. | |
247 | */ | |
ae618362 SR |
248 | . = ALIGN(8); |
249 | .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) { | |
250 | __alt_instructions = .; | |
251 | *(.altinstructions) | |
252 | __alt_instructions_end = .; | |
253 | } | |
254 | ||
6f44d033 KRW |
255 | /* |
256 | * And here are the replacement instructions. The linker sticks | |
257 | * them as binary blobs. The .altinstructions has enough data to | |
258 | * get the address and the length of them to patch the kernel safely. | |
259 | */ | |
ae618362 SR |
260 | .altinstr_replacement : AT(ADDR(.altinstr_replacement) - LOAD_OFFSET) { |
261 | *(.altinstr_replacement) | |
262 | } | |
263 | ||
6f44d033 KRW |
264 | /* |
265 | * struct iommu_table_entry entries are injected in this section. | |
266 | * It is an array of IOMMUs which during run time gets sorted depending | |
267 | * on its dependency order. After rootfs_initcall is complete | |
268 | * this section can be safely removed. | |
269 | */ | |
0444ad93 KRW |
270 | .iommu_table : AT(ADDR(.iommu_table) - LOAD_OFFSET) { |
271 | __iommu_table = .; | |
272 | *(.iommu_table) | |
0444ad93 KRW |
273 | __iommu_table_end = .; |
274 | } | |
4822b7fc | 275 | |
107e0e0c SS |
276 | . = ALIGN(8); |
277 | .apicdrivers : AT(ADDR(.apicdrivers) - LOAD_OFFSET) { | |
278 | __apicdrivers = .; | |
279 | *(.apicdrivers); | |
280 | __apicdrivers_end = .; | |
281 | } | |
282 | ||
7ac41ccf | 283 | . = ALIGN(8); |
bf6a5741 SR |
284 | /* |
285 | * .exit.text is discard at runtime, not link time, to deal with | |
286 | * references from .altinstructions and .eh_frame | |
287 | */ | |
288 | .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) { | |
289 | EXIT_TEXT | |
290 | } | |
291 | ||
292 | .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) { | |
293 | EXIT_DATA | |
294 | } | |
295 | ||
c62e4320 | 296 | #if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP) |
0415b00d | 297 | PERCPU_SECTION(INTERNODE_CACHE_BYTES) |
9d16e783 SR |
298 | #endif |
299 | ||
300 | . = ALIGN(PAGE_SIZE); | |
fd073194 | 301 | |
9d16e783 | 302 | /* freed after init ends here */ |
fd073194 IM |
303 | .init.end : AT(ADDR(.init.end) - LOAD_OFFSET) { |
304 | __init_end = .; | |
305 | } | |
9d16e783 | 306 | |
c62e4320 JB |
307 | /* |
308 | * smp_locks might be freed after init | |
309 | * start/end must be page aligned | |
310 | */ | |
311 | . = ALIGN(PAGE_SIZE); | |
312 | .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) { | |
313 | __smp_locks = .; | |
314 | *(.smp_locks) | |
c62e4320 | 315 | . = ALIGN(PAGE_SIZE); |
596b711e | 316 | __smp_locks_end = .; |
c62e4320 JB |
317 | } |
318 | ||
9d16e783 SR |
319 | #ifdef CONFIG_X86_64 |
320 | .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) { | |
c62e4320 JB |
321 | NOSAVE_DATA |
322 | } | |
9d16e783 SR |
323 | #endif |
324 | ||
091e52c3 SR |
325 | /* BSS */ |
326 | . = ALIGN(PAGE_SIZE); | |
327 | .bss : AT(ADDR(.bss) - LOAD_OFFSET) { | |
328 | __bss_start = .; | |
7c74df07 | 329 | *(.bss..page_aligned) |
091e52c3 | 330 | *(.bss) |
5bd5a452 | 331 | . = ALIGN(PAGE_SIZE); |
091e52c3 SR |
332 | __bss_stop = .; |
333 | } | |
9d16e783 | 334 | |
091e52c3 SR |
335 | . = ALIGN(PAGE_SIZE); |
336 | .brk : AT(ADDR(.brk) - LOAD_OFFSET) { | |
337 | __brk_base = .; | |
338 | . += 64 * 1024; /* 64k alignment slop space */ | |
339 | *(.brk_reservation) /* areas brk users have reserved */ | |
340 | __brk_limit = .; | |
341 | } | |
342 | ||
974f221c | 343 | . = ALIGN(PAGE_SIZE); /* keep VO_INIT_SIZE page aligned */ |
873b5271 | 344 | _end = .; |
091e52c3 | 345 | |
444e0ae4 SR |
346 | STABS_DEBUG |
347 | DWARF_DEBUG | |
023bf6f1 TH |
348 | |
349 | /* Sections to be discarded */ | |
350 | DISCARDS | |
9a99417a JP |
351 | /DISCARD/ : { |
352 | *(.eh_frame) | |
9a99417a | 353 | } |
444e0ae4 SR |
354 | } |
355 | ||
17ce265d SR |
356 | |
357 | #ifdef CONFIG_X86_32 | |
a5912f6b IM |
358 | /* |
359 | * The ASSERT() sink to . is intentional, for binutils 2.14 compatibility: | |
360 | */ | |
d2ba8b21 PA |
361 | . = ASSERT((_end - LOAD_OFFSET <= KERNEL_IMAGE_SIZE), |
362 | "kernel image bigger than KERNEL_IMAGE_SIZE"); | |
17ce265d SR |
363 | #else |
364 | /* | |
365 | * Per-cpu symbols which need to be offset from __per_cpu_load | |
366 | * for the boot processor. | |
367 | */ | |
dd17c8f7 | 368 | #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load |
17ce265d SR |
369 | INIT_PER_CPU(gdt_page); |
370 | INIT_PER_CPU(irq_stack_union); | |
371 | ||
372 | /* | |
373 | * Build-time check on the image size: | |
374 | */ | |
d2ba8b21 PA |
375 | . = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE), |
376 | "kernel image bigger than KERNEL_IMAGE_SIZE"); | |
17ce265d SR |
377 | |
378 | #ifdef CONFIG_SMP | |
dd17c8f7 | 379 | . = ASSERT((irq_stack_union == 0), |
d2ba8b21 | 380 | "irq_stack_union is not at start of per-cpu area"); |
17ce265d SR |
381 | #endif |
382 | ||
383 | #endif /* CONFIG_X86_32 */ | |
384 | ||
2965faa5 | 385 | #ifdef CONFIG_KEXEC_CORE |
17ce265d SR |
386 | #include <asm/kexec.h> |
387 | ||
d2ba8b21 PA |
388 | . = ASSERT(kexec_control_code_size <= KEXEC_CONTROL_CODE_MAX_SIZE, |
389 | "kexec control code size is too big"); | |
17ce265d SR |
390 | #endif |
391 |