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)
138 #define VSYSCALL_PHYS_ADDR ((LOADADDR(.data) + SIZEOF(.data) + \
139 PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
140 #define VSYSCALL_VIRT_ADDR ((ADDR(.data) + SIZEOF(.data) + \
141 PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
143 #define VLOAD_OFFSET (VSYSCALL_ADDR - VSYSCALL_PHYS_ADDR)
144 #define VLOAD(x) (ADDR(x) - VLOAD_OFFSET)
146 #define VVIRT_OFFSET (VSYSCALL_ADDR - VSYSCALL_VIRT_ADDR)
147 #define VVIRT(x) (ADDR(x) - VVIRT_OFFSET)
150 .vsyscall_0 : AT(VSYSCALL_PHYS_ADDR) {
154 __vsyscall_0 = VSYSCALL_VIRT_ADDR;
156 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
157 .vsyscall_fn : AT(VLOAD(.vsyscall_fn)) {
161 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
162 .vsyscall_gtod_data : AT(VLOAD(.vsyscall_gtod_data)) {
163 *(.vsyscall_gtod_data)
166 vsyscall_gtod_data = VVIRT(.vsyscall_gtod_data);
167 .vsyscall_clock : AT(VLOAD(.vsyscall_clock)) {
170 vsyscall_clock = VVIRT(.vsyscall_clock);
173 .vsyscall_1 ADDR(.vsyscall_0) + 1024: AT(VLOAD(.vsyscall_1)) {
176 .vsyscall_2 ADDR(.vsyscall_0) + 2048: AT(VLOAD(.vsyscall_2)) {
180 .vgetcpu_mode : AT(VLOAD(.vgetcpu_mode)) {
183 vgetcpu_mode = VVIRT(.vgetcpu_mode);
185 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
186 .jiffies : AT(VLOAD(.jiffies)) {
189 jiffies = VVIRT(.jiffies);
191 .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) {
195 . = VSYSCALL_VIRT_ADDR + PAGE_SIZE;
198 #undef VSYSCALL_PHYS_ADDR
199 #undef VSYSCALL_VIRT_ADDR
205 #endif /* CONFIG_X86_64 */
207 /* Init code and data - will be freed after init */
208 . = ALIGN(PAGE_SIZE);
209 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
210 __init_begin = .; /* paired with __init_end */
213 #if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
215 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
216 * output PHDR, so the next output section - .init.text - should
217 * start another segment - init.
219 PERCPU_VADDR(0, :percpu)
222 .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {
231 .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
236 .init.setup : AT(ADDR(.init.setup) - LOAD_OFFSET) {
241 .initcall.init : AT(ADDR(.initcall.init) - LOAD_OFFSET) {
242 __initcall_start = .;
247 .con_initcall.init : AT(ADDR(.con_initcall.init) - LOAD_OFFSET) {
248 __con_initcall_start = .;
249 *(.con_initcall.init)
250 __con_initcall_end = .;
253 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
254 __x86_cpu_dev_start = .;
256 __x86_cpu_dev_end = .;
262 .parainstructions : AT(ADDR(.parainstructions) - LOAD_OFFSET) {
263 __parainstructions = .;
265 __parainstructions_end = .;
269 .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) {
270 __alt_instructions = .;
272 __alt_instructions_end = .;
275 .altinstr_replacement : AT(ADDR(.altinstr_replacement) - LOAD_OFFSET) {
276 *(.altinstr_replacement)
280 * .exit.text is discard at runtime, not link time, to deal with
281 * references from .altinstructions and .eh_frame
283 .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
287 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
291 #ifdef CONFIG_BLK_DEV_INITRD
292 . = ALIGN(PAGE_SIZE);
293 .init.ramfs : AT(ADDR(.init.ramfs) - LOAD_OFFSET) {
294 __initramfs_start = .;
300 #if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
304 . = ALIGN(PAGE_SIZE);
306 /* freed after init ends here */
307 .init.end : AT(ADDR(.init.end) - LOAD_OFFSET) {
312 * smp_locks might be freed after init
313 * start/end must be page aligned
315 . = ALIGN(PAGE_SIZE);
316 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
320 . = ALIGN(PAGE_SIZE);
324 .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
330 . = ALIGN(PAGE_SIZE);
331 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
339 . = ALIGN(PAGE_SIZE);
340 .brk : AT(ADDR(.brk) - LOAD_OFFSET) {
342 . += 64 * 1024; /* 64k alignment slop space */
343 *(.brk_reservation) /* areas brk users have reserved */
347 .end : AT(ADDR(.end) - LOAD_OFFSET) {
351 /* Sections to be discarded */
364 . = ASSERT((_end - LOAD_OFFSET <= KERNEL_IMAGE_SIZE),
365 "kernel image bigger than KERNEL_IMAGE_SIZE");
368 * Per-cpu symbols which need to be offset from __per_cpu_load
369 * for the boot processor.
371 #define INIT_PER_CPU(x) init_per_cpu__##x = per_cpu__##x + __per_cpu_load
372 INIT_PER_CPU(gdt_page);
373 INIT_PER_CPU(irq_stack_union);
376 * Build-time check on the image size:
378 . = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
379 "kernel image bigger than KERNEL_IMAGE_SIZE");
382 . = ASSERT((per_cpu__irq_stack_union == 0),
383 "irq_stack_union is not at start of per-cpu area");
386 #endif /* CONFIG_X86_32 */
389 #include <asm/kexec.h>
391 . = ASSERT(kexec_control_code_size <= KEXEC_CONTROL_CODE_MAX_SIZE,
392 "kexec control code size is too big");