2 * ld script for the x86 kernel
4 * Historic 32-bit version written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>
6 * Modernisation, unification and other changes and fixes:
7 * Copyright (C) 2007-2009 Sam Ravnborg <sam@ravnborg.org>
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.
18 #define LOAD_OFFSET __PAGE_OFFSET
20 #define LOAD_OFFSET __START_KERNEL_map
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>
30 #undef i386 /* in case the preprocessor is a 32bit one */
32 OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT, CONFIG_OUTPUT_FORMAT, CONFIG_OUTPUT_FORMAT)
36 ENTRY(phys_startup_32)
39 OUTPUT_ARCH(i386:x86-64)
40 ENTRY(phys_startup_64)
45 text PT_LOAD FLAGS(5); /* R_E */
46 data PT_LOAD FLAGS(7); /* RWE */
48 user PT_LOAD FLAGS(7); /* RWE */
49 data.init PT_LOAD FLAGS(7); /* RWE */
51 percpu PT_LOAD FLAGS(7); /* RWE */
53 data.init2 PT_LOAD FLAGS(7); /* RWE */
55 note PT_NOTE FLAGS(0); /* ___ */
61 . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
62 phys_startup_32 = startup_32 - LOAD_OFFSET;
65 phys_startup_64 = startup_64 - LOAD_OFFSET;
68 /* Text and read-only data */
70 /* bootstrapping code */
71 .text.head : AT(ADDR(.text.head) - LOAD_OFFSET) {
76 /* The rest of the text */
77 .text : AT(ADDR(.text) - LOAD_OFFSET) {
79 /* not really needed, already page aligned */
92 /* End of text section */
100 __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
101 __start___ex_table = .;
103 __stop___ex_table = .;
109 . = ALIGN(PAGE_SIZE);
110 .data : AT(ADDR(.data) - LOAD_OFFSET) {
115 /* End of data section */
121 /* 32 bit has nosave before _edata */
122 . = ALIGN(PAGE_SIZE);
123 .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
126 . = ALIGN(PAGE_SIZE);
131 . = ALIGN(PAGE_SIZE);
132 .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
133 *(.data.page_aligned)
140 . = ALIGN(PAGE_SIZE);
141 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
143 .data.cacheline_aligned :
144 AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) {
145 *(.data.cacheline_aligned)
148 /* rarely changed data like cpu maps */
152 . = ALIGN(CONFIG_X86_INTERNODE_CACHE_BYTES);
154 .data.read_mostly : AT(ADDR(.data.read_mostly) - LOAD_OFFSET) {
158 /* End of data section */
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))
171 #define VLOAD_OFFSET (VSYSCALL_ADDR - VSYSCALL_PHYS_ADDR)
172 #define VLOAD(x) (ADDR(x) - VLOAD_OFFSET)
174 #define VVIRT_OFFSET (VSYSCALL_ADDR - VSYSCALL_VIRT_ADDR)
175 #define VVIRT(x) (ADDR(x) - VVIRT_OFFSET)
178 .vsyscall_0 : AT(VSYSCALL_PHYS_ADDR) {
182 __vsyscall_0 = VSYSCALL_VIRT_ADDR;
184 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
185 .vsyscall_fn : AT(VLOAD(.vsyscall_fn)) {
189 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
190 .vsyscall_gtod_data : AT(VLOAD(.vsyscall_gtod_data)) {
191 *(.vsyscall_gtod_data)
194 vsyscall_gtod_data = VVIRT(.vsyscall_gtod_data);
195 .vsyscall_clock : AT(VLOAD(.vsyscall_clock)) {
198 vsyscall_clock = VVIRT(.vsyscall_clock);
201 .vsyscall_1 ADDR(.vsyscall_0) + 1024: AT(VLOAD(.vsyscall_1)) {
204 .vsyscall_2 ADDR(.vsyscall_0) + 2048: AT(VLOAD(.vsyscall_2)) {
208 .vgetcpu_mode : AT(VLOAD(.vgetcpu_mode)) {
211 vgetcpu_mode = VVIRT(.vgetcpu_mode);
213 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
214 .jiffies : AT(VLOAD(.jiffies)) {
217 jiffies = VVIRT(.jiffies);
219 .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) {
223 . = VSYSCALL_VIRT_ADDR + PAGE_SIZE;
226 #undef VSYSCALL_PHYS_ADDR
227 #undef VSYSCALL_VIRT_ADDR
233 #endif /* CONFIG_X86_64 */
236 . = ALIGN(THREAD_SIZE);
237 .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
245 * smp_locks might be freed after init
246 * start/end must be page aligned
248 . = ALIGN(PAGE_SIZE);
249 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
253 . = ALIGN(PAGE_SIZE);
256 /* Init code and data - will be freed after init */
257 . = ALIGN(PAGE_SIZE);
258 .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {
259 __init_begin = .; /* paired with __init_end */
265 .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
270 .init.setup : AT(ADDR(.init.setup) - LOAD_OFFSET) {
275 .initcall.init : AT(ADDR(.initcall.init) - LOAD_OFFSET) {
276 __initcall_start = .;
281 .con_initcall.init : AT(ADDR(.con_initcall.init) - LOAD_OFFSET) {
282 __con_initcall_start = .;
283 *(.con_initcall.init)
284 __con_initcall_end = .;
287 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
288 __x86_cpu_dev_start = .;
290 __x86_cpu_dev_end = .;
296 .parainstructions : AT(ADDR(.parainstructions) - LOAD_OFFSET) {
297 __parainstructions = .;
299 __parainstructions_end = .;
303 .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) {
304 __alt_instructions = .;
306 __alt_instructions_end = .;
309 .altinstr_replacement : AT(ADDR(.altinstr_replacement) - LOAD_OFFSET) {
310 *(.altinstr_replacement)
314 * .exit.text is discard at runtime, not link time, to deal with
315 * references from .altinstructions and .eh_frame
317 .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
321 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
325 #ifdef CONFIG_BLK_DEV_INITRD
326 . = ALIGN(PAGE_SIZE);
327 .init.ramfs : AT(ADDR(.init.ramfs) - LOAD_OFFSET) {
328 __initramfs_start = .;
334 #if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
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.
342 . = ALIGN(PAGE_SIZE);
343 PERCPU_VADDR(0, :percpu)
348 . = ALIGN(PAGE_SIZE);
350 /* freed after init ends here */
351 .init.end : AT(ADDR(.init.end) - LOAD_OFFSET) {
356 .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
357 . = ALIGN(PAGE_SIZE);
360 . = ALIGN(PAGE_SIZE);
363 /* use another section data.init2, see PERCPU_VADDR() above */
367 . = ALIGN(PAGE_SIZE);
368 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
376 . = ALIGN(PAGE_SIZE);
377 .brk : AT(ADDR(.brk) - LOAD_OFFSET) {
379 . += 64 * 1024; /* 64k alignment slop space */
380 *(.brk_reservation) /* areas brk users have reserved */
384 .end : AT(ADDR(.end) - LOAD_OFFSET) {
388 /* Sections to be discarded */
401 ASSERT((_end - LOAD_OFFSET <= KERNEL_IMAGE_SIZE),
402 "kernel image bigger than KERNEL_IMAGE_SIZE")
405 * Per-cpu symbols which need to be offset from __per_cpu_load
406 * for the boot processor.
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);
413 * Build-time check on the image size:
415 ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
416 "kernel image bigger than KERNEL_IMAGE_SIZE")
419 ASSERT((per_cpu__irq_stack_union == 0),
420 "irq_stack_union is not at start of per-cpu area");
423 #endif /* CONFIG_X86_32 */
426 #include <asm/kexec.h>
428 ASSERT(kexec_control_code_size <= KEXEC_CONTROL_CODE_MAX_SIZE,
429 "kexec control code size is too big")