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