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) {
111 /* Start of data section */
117 /* End of data section */
123 /* 32 bit has nosave before _edata */
124 . = ALIGN(PAGE_SIZE);
125 .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
128 . = ALIGN(PAGE_SIZE);
133 . = ALIGN(PAGE_SIZE);
134 .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
135 *(.data.page_aligned)
142 . = ALIGN(PAGE_SIZE);
143 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
145 .data.cacheline_aligned :
146 AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) {
147 *(.data.cacheline_aligned)
150 /* rarely changed data like cpu maps */
154 . = ALIGN(CONFIG_X86_INTERNODE_CACHE_BYTES);
156 .data.read_mostly : AT(ADDR(.data.read_mostly) - LOAD_OFFSET) {
160 /* End of data section */
167 #define VSYSCALL_ADDR (-10*1024*1024)
168 #define VSYSCALL_PHYS_ADDR ((LOADADDR(.data.read_mostly) + \
169 SIZEOF(.data.read_mostly) + 4095) & ~(4095))
170 #define VSYSCALL_VIRT_ADDR ((ADDR(.data.read_mostly) + \
171 SIZEOF(.data.read_mostly) + 4095) & ~(4095))
173 #define VLOAD_OFFSET (VSYSCALL_ADDR - VSYSCALL_PHYS_ADDR)
174 #define VLOAD(x) (ADDR(x) - VLOAD_OFFSET)
176 #define VVIRT_OFFSET (VSYSCALL_ADDR - VSYSCALL_VIRT_ADDR)
177 #define VVIRT(x) (ADDR(x) - VVIRT_OFFSET)
180 .vsyscall_0 : AT(VSYSCALL_PHYS_ADDR) {
184 __vsyscall_0 = VSYSCALL_VIRT_ADDR;
186 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
187 .vsyscall_fn : AT(VLOAD(.vsyscall_fn)) {
191 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
192 .vsyscall_gtod_data : AT(VLOAD(.vsyscall_gtod_data)) {
193 *(.vsyscall_gtod_data)
196 vsyscall_gtod_data = VVIRT(.vsyscall_gtod_data);
197 .vsyscall_clock : AT(VLOAD(.vsyscall_clock)) {
200 vsyscall_clock = VVIRT(.vsyscall_clock);
203 .vsyscall_1 ADDR(.vsyscall_0) + 1024: AT(VLOAD(.vsyscall_1)) {
206 .vsyscall_2 ADDR(.vsyscall_0) + 2048: AT(VLOAD(.vsyscall_2)) {
210 .vgetcpu_mode : AT(VLOAD(.vgetcpu_mode)) {
213 vgetcpu_mode = VVIRT(.vgetcpu_mode);
215 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
216 .jiffies : AT(VLOAD(.jiffies)) {
219 jiffies = VVIRT(.jiffies);
221 .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) {
225 . = VSYSCALL_VIRT_ADDR + PAGE_SIZE;
228 #undef VSYSCALL_PHYS_ADDR
229 #undef VSYSCALL_VIRT_ADDR
235 #endif /* CONFIG_X86_64 */
238 . = ALIGN(THREAD_SIZE);
239 .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
247 * smp_locks might be freed after init
248 * start/end must be page aligned
250 . = ALIGN(PAGE_SIZE);
251 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
255 . = ALIGN(PAGE_SIZE);
258 /* Init code and data - will be freed after init */
259 . = ALIGN(PAGE_SIZE);
260 .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {
261 __init_begin = .; /* paired with __init_end */
267 .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
272 .init.setup : AT(ADDR(.init.setup) - LOAD_OFFSET) {
277 .initcall.init : AT(ADDR(.initcall.init) - LOAD_OFFSET) {
278 __initcall_start = .;
283 .con_initcall.init : AT(ADDR(.con_initcall.init) - LOAD_OFFSET) {
284 __con_initcall_start = .;
285 *(.con_initcall.init)
286 __con_initcall_end = .;
289 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
290 __x86_cpu_dev_start = .;
292 __x86_cpu_dev_end = .;
298 .parainstructions : AT(ADDR(.parainstructions) - LOAD_OFFSET) {
299 __parainstructions = .;
301 __parainstructions_end = .;
305 .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) {
306 __alt_instructions = .;
308 __alt_instructions_end = .;
311 .altinstr_replacement : AT(ADDR(.altinstr_replacement) - LOAD_OFFSET) {
312 *(.altinstr_replacement)
316 * .exit.text is discard at runtime, not link time, to deal with
317 * references from .altinstructions and .eh_frame
319 .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
323 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
327 #ifdef CONFIG_BLK_DEV_INITRD
328 . = ALIGN(PAGE_SIZE);
329 .init.ramfs : AT(ADDR(.init.ramfs) - LOAD_OFFSET) {
330 __initramfs_start = .;
336 #if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
338 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
339 * output PHDR, so the next output section - __data_nosave - should
340 * start another section data.init2. Also, pda should be at the head of
341 * percpu area. Preallocate it and define the percpu offset symbol
342 * so that it can be accessed as a percpu variable.
344 . = ALIGN(PAGE_SIZE);
345 PERCPU_VADDR(0, :percpu)
350 . = ALIGN(PAGE_SIZE);
352 /* freed after init ends here */
353 .init.end : AT(ADDR(.init.end) - LOAD_OFFSET) {
358 .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
359 . = ALIGN(PAGE_SIZE);
362 . = ALIGN(PAGE_SIZE);
365 /* use another section data.init2, see PERCPU_VADDR() above */
369 . = ALIGN(PAGE_SIZE);
370 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
378 . = ALIGN(PAGE_SIZE);
379 .brk : AT(ADDR(.brk) - LOAD_OFFSET) {
381 . += 64 * 1024; /* 64k alignment slop space */
382 *(.brk_reservation) /* areas brk users have reserved */
386 .end : AT(ADDR(.end) - LOAD_OFFSET) {
390 /* Sections to be discarded */
403 ASSERT((_end - LOAD_OFFSET <= KERNEL_IMAGE_SIZE),
404 "kernel image bigger than KERNEL_IMAGE_SIZE")
407 * Per-cpu symbols which need to be offset from __per_cpu_load
408 * for the boot processor.
410 #define INIT_PER_CPU(x) init_per_cpu__##x = per_cpu__##x + __per_cpu_load
411 INIT_PER_CPU(gdt_page);
412 INIT_PER_CPU(irq_stack_union);
415 * Build-time check on the image size:
417 ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
418 "kernel image bigger than KERNEL_IMAGE_SIZE")
421 ASSERT((per_cpu__irq_stack_union == 0),
422 "irq_stack_union is not at start of per-cpu area");
425 #endif /* CONFIG_X86_32 */
428 #include <asm/kexec.h>
430 ASSERT(kexec_control_code_size <= KEXEC_CONTROL_CODE_MAX_SIZE,
431 "kexec control code size is too big")