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 */
50 percpu PT_LOAD FLAGS(7); /* RWE */
52 init PT_LOAD FLAGS(7); /* RWE */
54 note PT_NOTE FLAGS(0); /* ___ */
60 . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
61 phys_startup_32 = startup_32 - LOAD_OFFSET;
64 phys_startup_64 = startup_64 - LOAD_OFFSET;
67 /* Text and read-only data */
69 /* bootstrapping code */
70 .text.head : AT(ADDR(.text.head) - LOAD_OFFSET) {
75 /* The rest of the text */
76 .text : AT(ADDR(.text) - LOAD_OFFSET) {
78 /* not really needed, already page aligned */
91 /* End of text section */
99 __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
100 __start___ex_table = .;
102 __stop___ex_table = .;
108 .data : AT(ADDR(.data) - LOAD_OFFSET) {
109 /* Start of data section */
113 INIT_TASK_DATA(THREAD_SIZE)
116 /* 32 bit has nosave before _edata */
120 PAGE_ALIGNED_DATA(PAGE_SIZE)
123 CACHELINE_ALIGNED_DATA(CONFIG_X86_L1_CACHE_BYTES)
128 /* rarely changed data like cpu maps */
129 READ_MOSTLY_DATA(CONFIG_X86_INTERNODE_CACHE_BYTES)
131 /* End of data section */
137 #define VSYSCALL_ADDR (-10*1024*1024)
139 #define VLOAD_OFFSET (VSYSCALL_ADDR - __vsyscall_0 + LOAD_OFFSET)
140 #define VLOAD(x) (ADDR(x) - VLOAD_OFFSET)
142 #define VVIRT_OFFSET (VSYSCALL_ADDR - __vsyscall_0)
143 #define VVIRT(x) (ADDR(x) - VVIRT_OFFSET)
149 .vsyscall_0 : AT(VLOAD(.vsyscall_0)) {
153 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
154 .vsyscall_fn : AT(VLOAD(.vsyscall_fn)) {
158 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
159 .vsyscall_gtod_data : AT(VLOAD(.vsyscall_gtod_data)) {
160 *(.vsyscall_gtod_data)
163 vsyscall_gtod_data = VVIRT(.vsyscall_gtod_data);
164 .vsyscall_clock : AT(VLOAD(.vsyscall_clock)) {
167 vsyscall_clock = VVIRT(.vsyscall_clock);
170 .vsyscall_1 ADDR(.vsyscall_0) + 1024: AT(VLOAD(.vsyscall_1)) {
173 .vsyscall_2 ADDR(.vsyscall_0) + 2048: AT(VLOAD(.vsyscall_2)) {
177 .vgetcpu_mode : AT(VLOAD(.vgetcpu_mode)) {
180 vgetcpu_mode = VVIRT(.vgetcpu_mode);
182 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
183 .jiffies : AT(VLOAD(.jiffies)) {
186 jiffies = VVIRT(.jiffies);
188 .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) {
192 . = __vsyscall_0 + PAGE_SIZE;
200 #endif /* CONFIG_X86_64 */
202 /* Init code and data - will be freed after init */
203 . = ALIGN(PAGE_SIZE);
204 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
205 __init_begin = .; /* paired with __init_end */
208 #if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
210 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
211 * output PHDR, so the next output section - .init.text - should
212 * start another segment - init.
214 PERCPU_VADDR(0, :percpu)
217 .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {
226 .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
231 .init.setup : AT(ADDR(.init.setup) - LOAD_OFFSET) {
236 .initcall.init : AT(ADDR(.initcall.init) - LOAD_OFFSET) {
237 __initcall_start = .;
242 .con_initcall.init : AT(ADDR(.con_initcall.init) - LOAD_OFFSET) {
243 __con_initcall_start = .;
244 *(.con_initcall.init)
245 __con_initcall_end = .;
248 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
249 __x86_cpu_dev_start = .;
251 __x86_cpu_dev_end = .;
257 .parainstructions : AT(ADDR(.parainstructions) - LOAD_OFFSET) {
258 __parainstructions = .;
260 __parainstructions_end = .;
264 .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) {
265 __alt_instructions = .;
267 __alt_instructions_end = .;
270 .altinstr_replacement : AT(ADDR(.altinstr_replacement) - LOAD_OFFSET) {
271 *(.altinstr_replacement)
275 * .exit.text is discard at runtime, not link time, to deal with
276 * references from .altinstructions and .eh_frame
278 .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
282 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
286 #ifdef CONFIG_BLK_DEV_INITRD
287 . = ALIGN(PAGE_SIZE);
288 .init.ramfs : AT(ADDR(.init.ramfs) - LOAD_OFFSET) {
289 __initramfs_start = .;
295 #if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
299 . = ALIGN(PAGE_SIZE);
301 /* freed after init ends here */
302 .init.end : AT(ADDR(.init.end) - LOAD_OFFSET) {
307 * smp_locks might be freed after init
308 * start/end must be page aligned
310 . = ALIGN(PAGE_SIZE);
311 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
315 . = ALIGN(PAGE_SIZE);
319 .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
325 . = ALIGN(PAGE_SIZE);
326 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
334 . = ALIGN(PAGE_SIZE);
335 .brk : AT(ADDR(.brk) - LOAD_OFFSET) {
337 . += 64 * 1024; /* 64k alignment slop space */
338 *(.brk_reservation) /* areas brk users have reserved */
342 .end : AT(ADDR(.end) - LOAD_OFFSET) {
349 /* Sections to be discarded */
351 /DISCARD/ : { *(.eh_frame) }
356 . = ASSERT((_end - LOAD_OFFSET <= KERNEL_IMAGE_SIZE),
357 "kernel image bigger than KERNEL_IMAGE_SIZE");
360 * Per-cpu symbols which need to be offset from __per_cpu_load
361 * for the boot processor.
363 #define INIT_PER_CPU(x) init_per_cpu__##x = per_cpu__##x + __per_cpu_load
364 INIT_PER_CPU(gdt_page);
365 INIT_PER_CPU(irq_stack_union);
368 * Build-time check on the image size:
370 . = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
371 "kernel image bigger than KERNEL_IMAGE_SIZE");
374 . = ASSERT((per_cpu__irq_stack_union == 0),
375 "irq_stack_union is not at start of per-cpu area");
378 #endif /* CONFIG_X86_32 */
381 #include <asm/kexec.h>
383 . = ASSERT(kexec_control_code_size <= KEXEC_CONTROL_CODE_MAX_SIZE,
384 "kexec control code size is too big");