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(5); /* R_E */
50 percpu PT_LOAD FLAGS(6); /* RW_ */
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 */
68 .text : AT(ADDR(.text) - LOAD_OFFSET) {
70 /* bootstrapping code */
85 /* End of text section */
91 EXCEPTION_TABLE(16) :text = 0x9090
96 .data : AT(ADDR(.data) - LOAD_OFFSET) {
97 /* Start of data section */
101 INIT_TASK_DATA(THREAD_SIZE)
104 /* 32 bit has nosave before _edata */
108 PAGE_ALIGNED_DATA(PAGE_SIZE)
110 CACHELINE_ALIGNED_DATA(CONFIG_X86_L1_CACHE_BYTES)
115 /* rarely changed data like cpu maps */
116 READ_MOSTLY_DATA(CONFIG_X86_INTERNODE_CACHE_BYTES)
118 /* End of data section */
124 #define VSYSCALL_ADDR (-10*1024*1024)
126 #define VLOAD_OFFSET (VSYSCALL_ADDR - __vsyscall_0 + LOAD_OFFSET)
127 #define VLOAD(x) (ADDR(x) - VLOAD_OFFSET)
129 #define VVIRT_OFFSET (VSYSCALL_ADDR - __vsyscall_0)
130 #define VVIRT(x) (ADDR(x) - VVIRT_OFFSET)
136 .vsyscall_0 : AT(VLOAD(.vsyscall_0)) {
140 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
141 .vsyscall_fn : AT(VLOAD(.vsyscall_fn)) {
145 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
146 .vsyscall_gtod_data : AT(VLOAD(.vsyscall_gtod_data)) {
147 *(.vsyscall_gtod_data)
150 vsyscall_gtod_data = VVIRT(.vsyscall_gtod_data);
151 .vsyscall_clock : AT(VLOAD(.vsyscall_clock)) {
154 vsyscall_clock = VVIRT(.vsyscall_clock);
157 .vsyscall_1 ADDR(.vsyscall_0) + 1024: AT(VLOAD(.vsyscall_1)) {
160 .vsyscall_2 ADDR(.vsyscall_0) + 2048: AT(VLOAD(.vsyscall_2)) {
164 .vgetcpu_mode : AT(VLOAD(.vgetcpu_mode)) {
167 vgetcpu_mode = VVIRT(.vgetcpu_mode);
169 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
170 .jiffies : AT(VLOAD(.jiffies)) {
173 jiffies = VVIRT(.jiffies);
175 .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) {
179 . = __vsyscall_0 + PAGE_SIZE;
187 #endif /* CONFIG_X86_64 */
189 /* Init code and data - will be freed after init */
190 . = ALIGN(PAGE_SIZE);
191 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
192 __init_begin = .; /* paired with __init_end */
195 #if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
197 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
198 * output PHDR, so the next output section - .init.text - should
199 * start another segment - init.
201 PERCPU_VADDR(0, :percpu)
204 INIT_TEXT_SECTION(PAGE_SIZE)
209 INIT_DATA_SECTION(16)
211 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
212 __x86_cpu_dev_start = .;
214 __x86_cpu_dev_end = .;
218 .parainstructions : AT(ADDR(.parainstructions) - LOAD_OFFSET) {
219 __parainstructions = .;
221 __parainstructions_end = .;
225 .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) {
226 __alt_instructions = .;
228 __alt_instructions_end = .;
231 .altinstr_replacement : AT(ADDR(.altinstr_replacement) - LOAD_OFFSET) {
232 *(.altinstr_replacement)
236 * .exit.text is discard at runtime, not link time, to deal with
237 * references from .altinstructions and .eh_frame
239 .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
243 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
247 #if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
251 . = ALIGN(PAGE_SIZE);
253 /* freed after init ends here */
254 .init.end : AT(ADDR(.init.end) - LOAD_OFFSET) {
259 * smp_locks might be freed after init
260 * start/end must be page aligned
262 . = ALIGN(PAGE_SIZE);
263 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
267 . = ALIGN(PAGE_SIZE);
271 .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
277 . = ALIGN(PAGE_SIZE);
278 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
286 . = ALIGN(PAGE_SIZE);
287 .brk : AT(ADDR(.brk) - LOAD_OFFSET) {
289 . += 64 * 1024; /* 64k alignment slop space */
290 *(.brk_reservation) /* areas brk users have reserved */
294 .end : AT(ADDR(.end) - LOAD_OFFSET) {
301 /* Sections to be discarded */
303 /DISCARD/ : { *(.eh_frame) }
308 . = ASSERT((_end - LOAD_OFFSET <= KERNEL_IMAGE_SIZE),
309 "kernel image bigger than KERNEL_IMAGE_SIZE");
312 * Per-cpu symbols which need to be offset from __per_cpu_load
313 * for the boot processor.
315 #define INIT_PER_CPU(x) init_per_cpu__##x = per_cpu__##x + __per_cpu_load
316 INIT_PER_CPU(gdt_page);
317 INIT_PER_CPU(irq_stack_union);
320 * Build-time check on the image size:
322 . = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
323 "kernel image bigger than KERNEL_IMAGE_SIZE");
326 . = ASSERT((per_cpu__irq_stack_union == 0),
327 "irq_stack_union is not at start of per-cpu area");
330 #endif /* CONFIG_X86_32 */
333 #include <asm/kexec.h>
335 . = ASSERT(kexec_control_code_size <= KEXEC_CONTROL_CODE_MAX_SIZE,
336 "kexec control code size is too big");