]>
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> | |
27 | #include <asm/cache.h> | |
28 | #include <asm/boot.h> | |
29 | ||
30 | #undef i386 /* in case the preprocessor is a 32bit one */ | |
31 | ||
32 | OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT, CONFIG_OUTPUT_FORMAT, CONFIG_OUTPUT_FORMAT) | |
33 | ||
34 | #ifdef CONFIG_X86_32 | |
35 | OUTPUT_ARCH(i386) | |
36 | ENTRY(phys_startup_32) | |
37 | jiffies = jiffies_64; | |
38 | #else | |
39 | OUTPUT_ARCH(i386:x86-64) | |
40 | ENTRY(phys_startup_64) | |
41 | jiffies_64 = jiffies; | |
42 | #endif | |
43 | ||
afb8095a SR |
44 | PHDRS { |
45 | text PT_LOAD FLAGS(5); /* R_E */ | |
46 | data PT_LOAD FLAGS(7); /* RWE */ | |
47 | #ifdef CONFIG_X86_64 | |
48 | user PT_LOAD FLAGS(7); /* RWE */ | |
49 | data.init PT_LOAD FLAGS(7); /* RWE */ | |
50 | #ifdef CONFIG_SMP | |
51 | percpu PT_LOAD FLAGS(7); /* RWE */ | |
52 | #endif | |
53 | data.init2 PT_LOAD FLAGS(7); /* RWE */ | |
54 | #endif | |
55 | note PT_NOTE FLAGS(0); /* ___ */ | |
56 | } | |
17ce265d | 57 | |
444e0ae4 SR |
58 | SECTIONS |
59 | { | |
60 | #ifdef CONFIG_X86_32 | |
61 | . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR; | |
62 | phys_startup_32 = startup_32 - LOAD_OFFSET; | |
63 | #else | |
64 | . = __START_KERNEL; | |
65 | phys_startup_64 = startup_64 - LOAD_OFFSET; | |
66 | #endif | |
67 | ||
dfc20895 SR |
68 | /* Text and read-only data */ |
69 | ||
70 | /* bootstrapping code */ | |
71 | .text.head : AT(ADDR(.text.head) - LOAD_OFFSET) { | |
72 | _text = .; | |
73 | *(.text.head) | |
74 | } :text = 0x9090 | |
75 | ||
76 | /* The rest of the text */ | |
77 | .text : AT(ADDR(.text) - LOAD_OFFSET) { | |
78 | #ifdef CONFIG_X86_32 | |
79 | /* not really needed, already page aligned */ | |
80 | . = ALIGN(PAGE_SIZE); | |
81 | *(.text.page_aligned) | |
82 | #endif | |
83 | . = ALIGN(8); | |
84 | _stext = .; | |
85 | TEXT_TEXT | |
86 | SCHED_TEXT | |
87 | LOCK_TEXT | |
88 | KPROBES_TEXT | |
89 | IRQENTRY_TEXT | |
90 | *(.fixup) | |
91 | *(.gnu.warning) | |
92 | /* End of text section */ | |
93 | _etext = .; | |
94 | } :text = 0x9090 | |
95 | ||
96 | NOTES :text :note | |
97 | ||
448bc3ab SR |
98 | /* Exception table */ |
99 | . = ALIGN(16); | |
100 | __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { | |
101 | __start___ex_table = .; | |
102 | *(__ex_table) | |
103 | __stop___ex_table = .; | |
104 | } :text = 0x9090 | |
105 | ||
106 | RODATA | |
107 | ||
1f6397ba SR |
108 | /* Data */ |
109 | . = ALIGN(PAGE_SIZE); | |
110 | .data : AT(ADDR(.data) - LOAD_OFFSET) { | |
111 | DATA_DATA | |
112 | CONSTRUCTORS | |
113 | ||
114 | #ifdef CONFIG_X86_64 | |
115 | /* End of data section */ | |
116 | _edata = .; | |
117 | #endif | |
118 | } :data | |
119 | ||
120 | #ifdef CONFIG_X86_32 | |
121 | /* 32 bit has nosave before _edata */ | |
122 | . = ALIGN(PAGE_SIZE); | |
123 | .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) { | |
124 | __nosave_begin = .; | |
125 | *(.data.nosave) | |
126 | . = ALIGN(PAGE_SIZE); | |
127 | __nosave_end = .; | |
128 | } | |
129 | #endif | |
130 | ||
131 | . = ALIGN(PAGE_SIZE); | |
132 | .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) { | |
133 | *(.data.page_aligned) | |
134 | *(.data.idt) | |
135 | } | |
136 | ||
137 | #ifdef CONFIG_X86_32 | |
138 | . = ALIGN(32); | |
139 | #else | |
140 | . = ALIGN(PAGE_SIZE); | |
141 | . = ALIGN(CONFIG_X86_L1_CACHE_BYTES); | |
142 | #endif | |
143 | .data.cacheline_aligned : | |
144 | AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) { | |
145 | *(.data.cacheline_aligned) | |
146 | } | |
147 | ||
148 | /* rarely changed data like cpu maps */ | |
149 | #ifdef CONFIG_X86_32 | |
150 | . = ALIGN(32); | |
151 | #else | |
152 | . = ALIGN(CONFIG_X86_INTERNODE_CACHE_BYTES); | |
153 | #endif | |
154 | .data.read_mostly : AT(ADDR(.data.read_mostly) - LOAD_OFFSET) { | |
155 | *(.data.read_mostly) | |
156 | ||
157 | #ifdef CONFIG_X86_32 | |
158 | /* End of data section */ | |
159 | _edata = .; | |
160 | #endif | |
161 | } | |
162 | ||
ff6f87e1 SR |
163 | #ifdef CONFIG_X86_64 |
164 | ||
165 | #define VSYSCALL_ADDR (-10*1024*1024) | |
166 | #define VSYSCALL_PHYS_ADDR ((LOADADDR(.data.read_mostly) + \ | |
167 | SIZEOF(.data.read_mostly) + 4095) & ~(4095)) | |
168 | #define VSYSCALL_VIRT_ADDR ((ADDR(.data.read_mostly) + \ | |
169 | SIZEOF(.data.read_mostly) + 4095) & ~(4095)) | |
170 | ||
171 | #define VLOAD_OFFSET (VSYSCALL_ADDR - VSYSCALL_PHYS_ADDR) | |
172 | #define VLOAD(x) (ADDR(x) - VLOAD_OFFSET) | |
173 | ||
174 | #define VVIRT_OFFSET (VSYSCALL_ADDR - VSYSCALL_VIRT_ADDR) | |
175 | #define VVIRT(x) (ADDR(x) - VVIRT_OFFSET) | |
176 | ||
177 | . = VSYSCALL_ADDR; | |
178 | .vsyscall_0 : AT(VSYSCALL_PHYS_ADDR) { | |
179 | *(.vsyscall_0) | |
180 | } :user | |
181 | ||
182 | __vsyscall_0 = VSYSCALL_VIRT_ADDR; | |
183 | ||
184 | . = ALIGN(CONFIG_X86_L1_CACHE_BYTES); | |
185 | .vsyscall_fn : AT(VLOAD(.vsyscall_fn)) { | |
186 | *(.vsyscall_fn) | |
187 | } | |
188 | ||
189 | . = ALIGN(CONFIG_X86_L1_CACHE_BYTES); | |
190 | .vsyscall_gtod_data : AT(VLOAD(.vsyscall_gtod_data)) { | |
191 | *(.vsyscall_gtod_data) | |
192 | } | |
193 | ||
194 | vsyscall_gtod_data = VVIRT(.vsyscall_gtod_data); | |
195 | .vsyscall_clock : AT(VLOAD(.vsyscall_clock)) { | |
196 | *(.vsyscall_clock) | |
197 | } | |
198 | vsyscall_clock = VVIRT(.vsyscall_clock); | |
199 | ||
200 | ||
201 | .vsyscall_1 ADDR(.vsyscall_0) + 1024: AT(VLOAD(.vsyscall_1)) { | |
202 | *(.vsyscall_1) | |
203 | } | |
204 | .vsyscall_2 ADDR(.vsyscall_0) + 2048: AT(VLOAD(.vsyscall_2)) { | |
205 | *(.vsyscall_2) | |
206 | } | |
207 | ||
208 | .vgetcpu_mode : AT(VLOAD(.vgetcpu_mode)) { | |
209 | *(.vgetcpu_mode) | |
210 | } | |
211 | vgetcpu_mode = VVIRT(.vgetcpu_mode); | |
212 | ||
213 | . = ALIGN(CONFIG_X86_L1_CACHE_BYTES); | |
214 | .jiffies : AT(VLOAD(.jiffies)) { | |
215 | *(.jiffies) | |
216 | } | |
217 | jiffies = VVIRT(.jiffies); | |
218 | ||
219 | .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) { | |
220 | *(.vsyscall_3) | |
221 | } | |
222 | ||
223 | . = VSYSCALL_VIRT_ADDR + PAGE_SIZE; | |
224 | ||
225 | #undef VSYSCALL_ADDR | |
226 | #undef VSYSCALL_PHYS_ADDR | |
227 | #undef VSYSCALL_VIRT_ADDR | |
228 | #undef VLOAD_OFFSET | |
229 | #undef VLOAD | |
230 | #undef VVIRT_OFFSET | |
231 | #undef VVIRT | |
232 | ||
233 | #endif /* CONFIG_X86_64 */ | |
dfc20895 | 234 | |
e58bdaa8 SR |
235 | /* init_task */ |
236 | . = ALIGN(THREAD_SIZE); | |
237 | .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) { | |
238 | *(.data.init_task) | |
239 | } | |
240 | #ifdef CONFIG_X86_64 | |
241 | :data.init | |
242 | #endif | |
243 | ||
244 | /* | |
245 | * smp_locks might be freed after init | |
246 | * start/end must be page aligned | |
247 | */ | |
248 | . = ALIGN(PAGE_SIZE); | |
249 | .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) { | |
250 | __smp_locks = .; | |
251 | *(.smp_locks) | |
252 | __smp_locks_end = .; | |
253 | . = ALIGN(PAGE_SIZE); | |
254 | } | |
255 | ||
256 | /* Init code and data - will be freed after init */ | |
257 | . = ALIGN(PAGE_SIZE); | |
e58bdaa8 | 258 | .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) { |
fd073194 | 259 | __init_begin = .; /* paired with __init_end */ |
e58bdaa8 SR |
260 | _sinittext = .; |
261 | INIT_TEXT | |
262 | _einittext = .; | |
263 | } | |
264 | ||
265 | .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) { | |
266 | INIT_DATA | |
267 | } | |
268 | ||
269 | . = ALIGN(16); | |
270 | .init.setup : AT(ADDR(.init.setup) - LOAD_OFFSET) { | |
271 | __setup_start = .; | |
272 | *(.init.setup) | |
273 | __setup_end = .; | |
274 | } | |
275 | .initcall.init : AT(ADDR(.initcall.init) - LOAD_OFFSET) { | |
276 | __initcall_start = .; | |
277 | INITCALLS | |
278 | __initcall_end = .; | |
279 | } | |
280 | ||
281 | .con_initcall.init : AT(ADDR(.con_initcall.init) - LOAD_OFFSET) { | |
282 | __con_initcall_start = .; | |
283 | *(.con_initcall.init) | |
284 | __con_initcall_end = .; | |
285 | } | |
286 | ||
287 | .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) { | |
288 | __x86_cpu_dev_start = .; | |
289 | *(.x86_cpu_dev.init) | |
290 | __x86_cpu_dev_end = .; | |
291 | } | |
292 | ||
293 | SECURITY_INIT | |
294 | ||
ae618362 SR |
295 | . = ALIGN(8); |
296 | .parainstructions : AT(ADDR(.parainstructions) - LOAD_OFFSET) { | |
297 | __parainstructions = .; | |
298 | *(.parainstructions) | |
299 | __parainstructions_end = .; | |
300 | } | |
301 | ||
302 | . = ALIGN(8); | |
303 | .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) { | |
304 | __alt_instructions = .; | |
305 | *(.altinstructions) | |
306 | __alt_instructions_end = .; | |
307 | } | |
308 | ||
309 | .altinstr_replacement : AT(ADDR(.altinstr_replacement) - LOAD_OFFSET) { | |
310 | *(.altinstr_replacement) | |
311 | } | |
312 | ||
bf6a5741 SR |
313 | /* |
314 | * .exit.text is discard at runtime, not link time, to deal with | |
315 | * references from .altinstructions and .eh_frame | |
316 | */ | |
317 | .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) { | |
318 | EXIT_TEXT | |
319 | } | |
320 | ||
321 | .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) { | |
322 | EXIT_DATA | |
323 | } | |
324 | ||
325 | #ifdef CONFIG_BLK_DEV_INITRD | |
326 | . = ALIGN(PAGE_SIZE); | |
327 | .init.ramfs : AT(ADDR(.init.ramfs) - LOAD_OFFSET) { | |
328 | __initramfs_start = .; | |
329 | *(.init.ramfs) | |
330 | __initramfs_end = .; | |
331 | } | |
332 | #endif | |
e58bdaa8 | 333 | |
9d16e783 SR |
334 | #if defined(CONFIG_X86_64) && defined(CONFIG_SMP) |
335 | /* | |
336 | * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the | |
337 | * output PHDR, so the next output section - __data_nosave - should | |
338 | * start another section data.init2. Also, pda should be at the head of | |
339 | * percpu area. Preallocate it and define the percpu offset symbol | |
340 | * so that it can be accessed as a percpu variable. | |
341 | */ | |
342 | . = ALIGN(PAGE_SIZE); | |
343 | PERCPU_VADDR(0, :percpu) | |
344 | #else | |
345 | PERCPU(PAGE_SIZE) | |
346 | #endif | |
347 | ||
348 | . = ALIGN(PAGE_SIZE); | |
fd073194 | 349 | |
9d16e783 | 350 | /* freed after init ends here */ |
fd073194 IM |
351 | .init.end : AT(ADDR(.init.end) - LOAD_OFFSET) { |
352 | __init_end = .; | |
353 | } | |
9d16e783 SR |
354 | |
355 | #ifdef CONFIG_X86_64 | |
356 | .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) { | |
357 | . = ALIGN(PAGE_SIZE); | |
358 | __nosave_begin = .; | |
359 | *(.data.nosave) | |
360 | . = ALIGN(PAGE_SIZE); | |
361 | __nosave_end = .; | |
362 | } :data.init2 | |
363 | /* use another section data.init2, see PERCPU_VADDR() above */ | |
364 | #endif | |
365 | ||
091e52c3 SR |
366 | /* BSS */ |
367 | . = ALIGN(PAGE_SIZE); | |
368 | .bss : AT(ADDR(.bss) - LOAD_OFFSET) { | |
369 | __bss_start = .; | |
370 | *(.bss.page_aligned) | |
371 | *(.bss) | |
372 | . = ALIGN(4); | |
373 | __bss_stop = .; | |
374 | } | |
9d16e783 | 375 | |
091e52c3 SR |
376 | . = ALIGN(PAGE_SIZE); |
377 | .brk : AT(ADDR(.brk) - LOAD_OFFSET) { | |
378 | __brk_base = .; | |
379 | . += 64 * 1024; /* 64k alignment slop space */ | |
380 | *(.brk_reservation) /* areas brk users have reserved */ | |
381 | __brk_limit = .; | |
382 | } | |
383 | ||
384 | .end : AT(ADDR(.end) - LOAD_OFFSET) { | |
385 | _end = .; | |
386 | } | |
387 | ||
388 | /* Sections to be discarded */ | |
389 | /DISCARD/ : { | |
390 | *(.exitcall.exit) | |
391 | *(.eh_frame) | |
392 | *(.discard) | |
393 | } | |
17ce265d | 394 | |
444e0ae4 SR |
395 | STABS_DEBUG |
396 | DWARF_DEBUG | |
397 | } | |
398 | ||
17ce265d SR |
399 | |
400 | #ifdef CONFIG_X86_32 | |
401 | ASSERT((_end - LOAD_OFFSET <= KERNEL_IMAGE_SIZE), | |
402 | "kernel image bigger than KERNEL_IMAGE_SIZE") | |
403 | #else | |
404 | /* | |
405 | * Per-cpu symbols which need to be offset from __per_cpu_load | |
406 | * for the boot processor. | |
407 | */ | |
408 | #define INIT_PER_CPU(x) init_per_cpu__##x = per_cpu__##x + __per_cpu_load | |
409 | INIT_PER_CPU(gdt_page); | |
410 | INIT_PER_CPU(irq_stack_union); | |
411 | ||
412 | /* | |
413 | * Build-time check on the image size: | |
414 | */ | |
415 | ASSERT((_end - _text <= KERNEL_IMAGE_SIZE), | |
416 | "kernel image bigger than KERNEL_IMAGE_SIZE") | |
417 | ||
418 | #ifdef CONFIG_SMP | |
419 | ASSERT((per_cpu__irq_stack_union == 0), | |
420 | "irq_stack_union is not at start of per-cpu area"); | |
421 | #endif | |
422 | ||
423 | #endif /* CONFIG_X86_32 */ | |
424 | ||
425 | #ifdef CONFIG_KEXEC | |
426 | #include <asm/kexec.h> | |
427 | ||
428 | ASSERT(kexec_control_code_size <= KEXEC_CONTROL_CODE_MAX_SIZE, | |
429 | "kexec control code size is too big") | |
430 | #endif | |
431 |