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)
44 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
46 #define X64_ALIGN_DEBUG_RODATA_BEGIN . = ALIGN(HPAGE_SIZE);
48 #define X64_ALIGN_DEBUG_RODATA_END \
49 . = ALIGN(HPAGE_SIZE); \
50 __end_rodata_hpage_align = .;
54 #define X64_ALIGN_DEBUG_RODATA_BEGIN
55 #define X64_ALIGN_DEBUG_RODATA_END
60 text PT_LOAD FLAGS(5); /* R_E */
61 data PT_LOAD FLAGS(7); /* RWE */
63 user PT_LOAD FLAGS(5); /* R_E */
65 percpu PT_LOAD FLAGS(6); /* RW_ */
67 init PT_LOAD FLAGS(7); /* RWE */
69 note PT_NOTE FLAGS(0); /* ___ */
75 . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
76 phys_startup_32 = startup_32 - LOAD_OFFSET;
79 phys_startup_64 = startup_64 - LOAD_OFFSET;
82 /* Text and read-only data */
83 .text : AT(ADDR(.text) - LOAD_OFFSET) {
85 /* bootstrapping code */
100 /* End of text section */
106 EXCEPTION_TABLE(16) :text = 0x9090
108 X64_ALIGN_DEBUG_RODATA_BEGIN
110 X64_ALIGN_DEBUG_RODATA_END
113 .data : AT(ADDR(.data) - LOAD_OFFSET) {
114 /* Start of data section */
118 INIT_TASK_DATA(THREAD_SIZE)
121 /* 32 bit has nosave before _edata */
125 PAGE_ALIGNED_DATA(PAGE_SIZE)
127 CACHELINE_ALIGNED_DATA(CONFIG_X86_L1_CACHE_BYTES)
132 /* rarely changed data like cpu maps */
133 READ_MOSTLY_DATA(CONFIG_X86_INTERNODE_CACHE_BYTES)
135 /* End of data section */
141 #define VSYSCALL_ADDR (-10*1024*1024)
143 #define VLOAD_OFFSET (VSYSCALL_ADDR - __vsyscall_0 + LOAD_OFFSET)
144 #define VLOAD(x) (ADDR(x) - VLOAD_OFFSET)
146 #define VVIRT_OFFSET (VSYSCALL_ADDR - __vsyscall_0)
147 #define VVIRT(x) (ADDR(x) - VVIRT_OFFSET)
153 .vsyscall_0 : AT(VLOAD(.vsyscall_0)) {
157 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
158 .vsyscall_fn : AT(VLOAD(.vsyscall_fn)) {
162 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
163 .vsyscall_gtod_data : AT(VLOAD(.vsyscall_gtod_data)) {
164 *(.vsyscall_gtod_data)
167 vsyscall_gtod_data = VVIRT(.vsyscall_gtod_data);
168 .vsyscall_clock : AT(VLOAD(.vsyscall_clock)) {
171 vsyscall_clock = VVIRT(.vsyscall_clock);
174 .vsyscall_1 ADDR(.vsyscall_0) + 1024: AT(VLOAD(.vsyscall_1)) {
177 .vsyscall_2 ADDR(.vsyscall_0) + 2048: AT(VLOAD(.vsyscall_2)) {
181 .vgetcpu_mode : AT(VLOAD(.vgetcpu_mode)) {
184 vgetcpu_mode = VVIRT(.vgetcpu_mode);
186 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
187 .jiffies : AT(VLOAD(.jiffies)) {
190 jiffies = VVIRT(.jiffies);
192 .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) {
196 . = __vsyscall_0 + PAGE_SIZE;
204 #endif /* CONFIG_X86_64 */
206 /* Init code and data - will be freed after init */
207 . = ALIGN(PAGE_SIZE);
208 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
209 __init_begin = .; /* paired with __init_end */
212 #if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
214 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
215 * output PHDR, so the next output section - .init.text - should
216 * start another segment - init.
218 PERCPU_VADDR(0, :percpu)
221 INIT_TEXT_SECTION(PAGE_SIZE)
226 INIT_DATA_SECTION(16)
228 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
229 __x86_cpu_dev_start = .;
231 __x86_cpu_dev_end = .;
235 .parainstructions : AT(ADDR(.parainstructions) - LOAD_OFFSET) {
236 __parainstructions = .;
238 __parainstructions_end = .;
242 .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) {
243 __alt_instructions = .;
245 __alt_instructions_end = .;
248 .altinstr_replacement : AT(ADDR(.altinstr_replacement) - LOAD_OFFSET) {
249 *(.altinstr_replacement)
253 * .exit.text is discard at runtime, not link time, to deal with
254 * references from .altinstructions and .eh_frame
256 .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
260 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
264 #if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
268 . = ALIGN(PAGE_SIZE);
270 /* freed after init ends here */
271 .init.end : AT(ADDR(.init.end) - LOAD_OFFSET) {
276 * smp_locks might be freed after init
277 * start/end must be page aligned
279 . = ALIGN(PAGE_SIZE);
280 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
284 . = ALIGN(PAGE_SIZE);
288 .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
294 . = ALIGN(PAGE_SIZE);
295 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
303 . = ALIGN(PAGE_SIZE);
304 .brk : AT(ADDR(.brk) - LOAD_OFFSET) {
306 . += 64 * 1024; /* 64k alignment slop space */
307 *(.brk_reservation) /* areas brk users have reserved */
311 .end : AT(ADDR(.end) - LOAD_OFFSET) {
318 /* Sections to be discarded */
320 /DISCARD/ : { *(.eh_frame) }
325 . = ASSERT((_end - LOAD_OFFSET <= KERNEL_IMAGE_SIZE),
326 "kernel image bigger than KERNEL_IMAGE_SIZE");
329 * Per-cpu symbols which need to be offset from __per_cpu_load
330 * for the boot processor.
332 #define INIT_PER_CPU(x) init_per_cpu__##x = per_cpu__##x + __per_cpu_load
333 INIT_PER_CPU(gdt_page);
334 INIT_PER_CPU(irq_stack_union);
337 * Build-time check on the image size:
339 . = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
340 "kernel image bigger than KERNEL_IMAGE_SIZE");
343 . = ASSERT((per_cpu__irq_stack_union == 0),
344 "irq_stack_union is not at start of per-cpu area");
347 #endif /* CONFIG_X86_32 */
350 #include <asm/kexec.h>
352 . = ASSERT(kexec_control_code_size <= KEXEC_CONTROL_CODE_MAX_SIZE,
353 "kexec control code size is too big");