x86: fix fragile computation of vsyscall address
[safe/jmp/linux-2.6] / arch / x86 / kernel / vmlinux.lds.S
1 /*
2  * ld script for the x86 kernel
3  *
4  * Historic 32-bit version written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>
5  *
6  * Modernisation, unification and other changes and fixes:
7  *   Copyright (C) 2007-2009  Sam Ravnborg <sam@ravnborg.org>
8  *
9  *
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.
15  */
16
17 #ifdef CONFIG_X86_32
18 #define LOAD_OFFSET __PAGE_OFFSET
19 #else
20 #define LOAD_OFFSET __START_KERNEL_map
21 #endif
22
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>
28 #include <asm/boot.h>
29
30 #undef i386     /* in case the preprocessor is a 32bit one */
31
32 OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT, CONFIG_OUTPUT_FORMAT, CONFIG_OUTPUT_FORMAT)
33
34 #ifdef CONFIG_X86_32
35 OUTPUT_ARCH(i386)
36 ENTRY(phys_startup_32)
37 jiffies = jiffies_64;
38 #else
39 OUTPUT_ARCH(i386:x86-64)
40 ENTRY(phys_startup_64)
41 jiffies_64 = jiffies;
42 #endif
43
44 PHDRS {
45         text PT_LOAD FLAGS(5);          /* R_E */
46         data PT_LOAD FLAGS(7);          /* RWE */
47 #ifdef CONFIG_X86_64
48         user PT_LOAD FLAGS(7);          /* RWE */
49 #ifdef CONFIG_SMP
50         percpu PT_LOAD FLAGS(7);        /* RWE */
51 #endif
52         init PT_LOAD FLAGS(7);          /* RWE */
53 #endif
54         note PT_NOTE FLAGS(0);          /* ___ */
55 }
56
57 SECTIONS
58 {
59 #ifdef CONFIG_X86_32
60         . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
61         phys_startup_32 = startup_32 - LOAD_OFFSET;
62 #else
63         . = __START_KERNEL;
64         phys_startup_64 = startup_64 - LOAD_OFFSET;
65 #endif
66
67         /* Text and read-only data */
68
69         /* bootstrapping code */
70         .text.head : AT(ADDR(.text.head) - LOAD_OFFSET) {
71                 _text = .;
72                 *(.text.head)
73         } :text = 0x9090
74
75         /* The rest of the text */
76         .text :  AT(ADDR(.text) - LOAD_OFFSET) {
77 #ifdef CONFIG_X86_32
78                 /* not really needed, already page aligned */
79                 . = ALIGN(PAGE_SIZE);
80                 *(.text.page_aligned)
81 #endif
82                 . = ALIGN(8);
83                 _stext = .;
84                 TEXT_TEXT
85                 SCHED_TEXT
86                 LOCK_TEXT
87                 KPROBES_TEXT
88                 IRQENTRY_TEXT
89                 *(.fixup)
90                 *(.gnu.warning)
91                 /* End of text section */
92                 _etext = .;
93         } :text = 0x9090
94
95         NOTES :text :note
96
97         /* Exception table */
98         . = ALIGN(16);
99         __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
100                 __start___ex_table = .;
101                 *(__ex_table)
102                 __stop___ex_table = .;
103         } :text = 0x9090
104
105         RO_DATA(PAGE_SIZE)
106
107         /* Data */
108         .data : AT(ADDR(.data) - LOAD_OFFSET) {
109                 /* Start of data section */
110                 _sdata = .;
111
112                 /* init_task */
113                 INIT_TASK_DATA(THREAD_SIZE)
114
115 #ifdef CONFIG_X86_32
116                 /* 32 bit has nosave before _edata */
117                 NOSAVE_DATA
118 #endif
119
120                 PAGE_ALIGNED_DATA(PAGE_SIZE)
121                 *(.data.idt)
122
123                 CACHELINE_ALIGNED_DATA(CONFIG_X86_L1_CACHE_BYTES)
124
125                 DATA_DATA
126                 CONSTRUCTORS
127
128                 /* rarely changed data like cpu maps */
129                 READ_MOSTLY_DATA(CONFIG_X86_INTERNODE_CACHE_BYTES)
130
131                 /* End of data section */
132                 _edata = .;
133         } :data
134
135 #ifdef CONFIG_X86_64
136
137 #define VSYSCALL_ADDR (-10*1024*1024)
138
139 #define VLOAD_OFFSET (VSYSCALL_ADDR - __vsyscall_0 + LOAD_OFFSET)
140 #define VLOAD(x) (ADDR(x) - VLOAD_OFFSET)
141
142 #define VVIRT_OFFSET (VSYSCALL_ADDR - __vsyscall_0)
143 #define VVIRT(x) (ADDR(x) - VVIRT_OFFSET)
144
145         . = ALIGN(4096);
146         __vsyscall_0 = .;
147
148         . = VSYSCALL_ADDR;
149         .vsyscall_0 : AT(VLOAD(.vsyscall_0)) {
150                 *(.vsyscall_0)
151         } :user
152
153         . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
154         .vsyscall_fn : AT(VLOAD(.vsyscall_fn)) {
155                 *(.vsyscall_fn)
156         }
157
158         . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
159         .vsyscall_gtod_data : AT(VLOAD(.vsyscall_gtod_data)) {
160                 *(.vsyscall_gtod_data)
161         }
162
163         vsyscall_gtod_data = VVIRT(.vsyscall_gtod_data);
164         .vsyscall_clock : AT(VLOAD(.vsyscall_clock)) {
165                 *(.vsyscall_clock)
166         }
167         vsyscall_clock = VVIRT(.vsyscall_clock);
168
169
170         .vsyscall_1 ADDR(.vsyscall_0) + 1024: AT(VLOAD(.vsyscall_1)) {
171                 *(.vsyscall_1)
172         }
173         .vsyscall_2 ADDR(.vsyscall_0) + 2048: AT(VLOAD(.vsyscall_2)) {
174                 *(.vsyscall_2)
175         }
176
177         .vgetcpu_mode : AT(VLOAD(.vgetcpu_mode)) {
178                 *(.vgetcpu_mode)
179         }
180         vgetcpu_mode = VVIRT(.vgetcpu_mode);
181
182         . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
183         .jiffies : AT(VLOAD(.jiffies)) {
184                 *(.jiffies)
185         }
186         jiffies = VVIRT(.jiffies);
187
188         .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) {
189                 *(.vsyscall_3)
190         }
191
192         . = __vsyscall_0 + PAGE_SIZE;
193
194 #undef VSYSCALL_ADDR
195 #undef VLOAD_OFFSET
196 #undef VLOAD
197 #undef VVIRT_OFFSET
198 #undef VVIRT
199
200 #endif /* CONFIG_X86_64 */
201
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 */
206         }
207
208 #if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
209         /*
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.
213          */
214         PERCPU_VADDR(0, :percpu)
215 #endif
216
217         .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {
218                 _sinittext = .;
219                 INIT_TEXT
220                 _einittext = .;
221         }
222 #ifdef CONFIG_X86_64
223         :init
224 #endif
225
226         .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
227                 INIT_DATA
228         }
229
230         . = ALIGN(16);
231         .init.setup : AT(ADDR(.init.setup) - LOAD_OFFSET) {
232                 __setup_start = .;
233                 *(.init.setup)
234                 __setup_end = .;
235         }
236         .initcall.init : AT(ADDR(.initcall.init) - LOAD_OFFSET) {
237                 __initcall_start = .;
238                 INITCALLS
239                 __initcall_end = .;
240         }
241
242         .con_initcall.init : AT(ADDR(.con_initcall.init) - LOAD_OFFSET) {
243                 __con_initcall_start = .;
244                 *(.con_initcall.init)
245                 __con_initcall_end = .;
246         }
247
248         .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
249                 __x86_cpu_dev_start = .;
250                 *(.x86_cpu_dev.init)
251                 __x86_cpu_dev_end = .;
252         }
253
254         SECURITY_INIT
255
256         . = ALIGN(8);
257         .parainstructions : AT(ADDR(.parainstructions) - LOAD_OFFSET) {
258                 __parainstructions = .;
259                 *(.parainstructions)
260                 __parainstructions_end = .;
261         }
262
263         . = ALIGN(8);
264         .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) {
265                 __alt_instructions = .;
266                 *(.altinstructions)
267                 __alt_instructions_end = .;
268         }
269
270         .altinstr_replacement : AT(ADDR(.altinstr_replacement) - LOAD_OFFSET) {
271                 *(.altinstr_replacement)
272         }
273
274         /*
275          * .exit.text is discard at runtime, not link time, to deal with
276          *  references from .altinstructions and .eh_frame
277          */
278         .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
279                 EXIT_TEXT
280         }
281
282         .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
283                 EXIT_DATA
284         }
285
286 #ifdef CONFIG_BLK_DEV_INITRD
287         . = ALIGN(PAGE_SIZE);
288         .init.ramfs : AT(ADDR(.init.ramfs) - LOAD_OFFSET) {
289                 __initramfs_start = .;
290                 *(.init.ramfs)
291                 __initramfs_end = .;
292         }
293 #endif
294
295 #if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
296         PERCPU(PAGE_SIZE)
297 #endif
298
299         . = ALIGN(PAGE_SIZE);
300
301         /* freed after init ends here */
302         .init.end : AT(ADDR(.init.end) - LOAD_OFFSET) {
303                 __init_end = .;
304         }
305
306         /*
307          * smp_locks might be freed after init
308          * start/end must be page aligned
309          */
310         . = ALIGN(PAGE_SIZE);
311         .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
312                 __smp_locks = .;
313                 *(.smp_locks)
314                 __smp_locks_end = .;
315                 . = ALIGN(PAGE_SIZE);
316         }
317
318 #ifdef CONFIG_X86_64
319         .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
320                 NOSAVE_DATA
321         }
322 #endif
323
324         /* BSS */
325         . = ALIGN(PAGE_SIZE);
326         .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
327                 __bss_start = .;
328                 *(.bss.page_aligned)
329                 *(.bss)
330                 . = ALIGN(4);
331                 __bss_stop = .;
332         }
333
334         . = ALIGN(PAGE_SIZE);
335         .brk : AT(ADDR(.brk) - LOAD_OFFSET) {
336                 __brk_base = .;
337                 . += 64 * 1024;         /* 64k alignment slop space */
338                 *(.brk_reservation)     /* areas brk users have reserved */
339                 __brk_limit = .;
340         }
341
342         .end : AT(ADDR(.end) - LOAD_OFFSET) {
343                 _end = .;
344         }
345
346         STABS_DEBUG
347         DWARF_DEBUG
348
349         /* Sections to be discarded */
350         DISCARDS
351         /DISCARD/ : { *(.eh_frame) }
352 }
353
354
355 #ifdef CONFIG_X86_32
356 . = ASSERT((_end - LOAD_OFFSET <= KERNEL_IMAGE_SIZE),
357            "kernel image bigger than KERNEL_IMAGE_SIZE");
358 #else
359 /*
360  * Per-cpu symbols which need to be offset from __per_cpu_load
361  * for the boot processor.
362  */
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);
366
367 /*
368  * Build-time check on the image size:
369  */
370 . = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
371            "kernel image bigger than KERNEL_IMAGE_SIZE");
372
373 #ifdef CONFIG_SMP
374 . = ASSERT((per_cpu__irq_stack_union == 0),
375            "irq_stack_union is not at start of per-cpu area");
376 #endif
377
378 #endif /* CONFIG_X86_32 */
379
380 #ifdef CONFIG_KEXEC
381 #include <asm/kexec.h>
382
383 . = ASSERT(kexec_control_code_size <= KEXEC_CONTROL_CODE_MAX_SIZE,
384            "kexec control code size is too big");
385 #endif
386