x86-64: align RODATA kernel section to 2MB with CONFIG_DEBUG_RODATA
[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 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
45
46 #define X64_ALIGN_DEBUG_RODATA_BEGIN    . = ALIGN(HPAGE_SIZE);
47
48 #define X64_ALIGN_DEBUG_RODATA_END                              \
49                 . = ALIGN(HPAGE_SIZE);                          \
50                 __end_rodata_hpage_align = .;
51
52 #else
53
54 #define X64_ALIGN_DEBUG_RODATA_BEGIN
55 #define X64_ALIGN_DEBUG_RODATA_END
56
57 #endif
58
59 PHDRS {
60         text PT_LOAD FLAGS(5);          /* R_E */
61         data PT_LOAD FLAGS(7);          /* RWE */
62 #ifdef CONFIG_X86_64
63         user PT_LOAD FLAGS(5);          /* R_E */
64 #ifdef CONFIG_SMP
65         percpu PT_LOAD FLAGS(6);        /* RW_ */
66 #endif
67         init PT_LOAD FLAGS(7);          /* RWE */
68 #endif
69         note PT_NOTE FLAGS(0);          /* ___ */
70 }
71
72 SECTIONS
73 {
74 #ifdef CONFIG_X86_32
75         . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
76         phys_startup_32 = startup_32 - LOAD_OFFSET;
77 #else
78         . = __START_KERNEL;
79         phys_startup_64 = startup_64 - LOAD_OFFSET;
80 #endif
81
82         /* Text and read-only data */
83         .text :  AT(ADDR(.text) - LOAD_OFFSET) {
84                 _text = .;
85                 /* bootstrapping code */
86                 HEAD_TEXT
87 #ifdef CONFIG_X86_32
88                 . = ALIGN(PAGE_SIZE);
89                 *(.text.page_aligned)
90 #endif
91                 . = ALIGN(8);
92                 _stext = .;
93                 TEXT_TEXT
94                 SCHED_TEXT
95                 LOCK_TEXT
96                 KPROBES_TEXT
97                 IRQENTRY_TEXT
98                 *(.fixup)
99                 *(.gnu.warning)
100                 /* End of text section */
101                 _etext = .;
102         } :text = 0x9090
103
104         NOTES :text :note
105
106         EXCEPTION_TABLE(16) :text = 0x9090
107
108         X64_ALIGN_DEBUG_RODATA_BEGIN
109         RO_DATA(PAGE_SIZE)
110         X64_ALIGN_DEBUG_RODATA_END
111
112         /* Data */
113         .data : AT(ADDR(.data) - LOAD_OFFSET) {
114                 /* Start of data section */
115                 _sdata = .;
116
117                 /* init_task */
118                 INIT_TASK_DATA(THREAD_SIZE)
119
120 #ifdef CONFIG_X86_32
121                 /* 32 bit has nosave before _edata */
122                 NOSAVE_DATA
123 #endif
124
125                 PAGE_ALIGNED_DATA(PAGE_SIZE)
126
127                 CACHELINE_ALIGNED_DATA(CONFIG_X86_L1_CACHE_BYTES)
128
129                 DATA_DATA
130                 CONSTRUCTORS
131
132                 /* rarely changed data like cpu maps */
133                 READ_MOSTLY_DATA(CONFIG_X86_INTERNODE_CACHE_BYTES)
134
135                 /* End of data section */
136                 _edata = .;
137         } :data
138
139 #ifdef CONFIG_X86_64
140
141 #define VSYSCALL_ADDR (-10*1024*1024)
142
143 #define VLOAD_OFFSET (VSYSCALL_ADDR - __vsyscall_0 + LOAD_OFFSET)
144 #define VLOAD(x) (ADDR(x) - VLOAD_OFFSET)
145
146 #define VVIRT_OFFSET (VSYSCALL_ADDR - __vsyscall_0)
147 #define VVIRT(x) (ADDR(x) - VVIRT_OFFSET)
148
149         . = ALIGN(4096);
150         __vsyscall_0 = .;
151
152         . = VSYSCALL_ADDR;
153         .vsyscall_0 : AT(VLOAD(.vsyscall_0)) {
154                 *(.vsyscall_0)
155         } :user
156
157         . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
158         .vsyscall_fn : AT(VLOAD(.vsyscall_fn)) {
159                 *(.vsyscall_fn)
160         }
161
162         . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
163         .vsyscall_gtod_data : AT(VLOAD(.vsyscall_gtod_data)) {
164                 *(.vsyscall_gtod_data)
165         }
166
167         vsyscall_gtod_data = VVIRT(.vsyscall_gtod_data);
168         .vsyscall_clock : AT(VLOAD(.vsyscall_clock)) {
169                 *(.vsyscall_clock)
170         }
171         vsyscall_clock = VVIRT(.vsyscall_clock);
172
173
174         .vsyscall_1 ADDR(.vsyscall_0) + 1024: AT(VLOAD(.vsyscall_1)) {
175                 *(.vsyscall_1)
176         }
177         .vsyscall_2 ADDR(.vsyscall_0) + 2048: AT(VLOAD(.vsyscall_2)) {
178                 *(.vsyscall_2)
179         }
180
181         .vgetcpu_mode : AT(VLOAD(.vgetcpu_mode)) {
182                 *(.vgetcpu_mode)
183         }
184         vgetcpu_mode = VVIRT(.vgetcpu_mode);
185
186         . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
187         .jiffies : AT(VLOAD(.jiffies)) {
188                 *(.jiffies)
189         }
190         jiffies = VVIRT(.jiffies);
191
192         .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) {
193                 *(.vsyscall_3)
194         }
195
196         . = __vsyscall_0 + PAGE_SIZE;
197
198 #undef VSYSCALL_ADDR
199 #undef VLOAD_OFFSET
200 #undef VLOAD
201 #undef VVIRT_OFFSET
202 #undef VVIRT
203
204 #endif /* CONFIG_X86_64 */
205
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 */
210         }
211
212 #if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
213         /*
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.
217          */
218         PERCPU_VADDR(0, :percpu)
219 #endif
220
221         INIT_TEXT_SECTION(PAGE_SIZE)
222 #ifdef CONFIG_X86_64
223         :init
224 #endif
225
226         INIT_DATA_SECTION(16)
227
228         .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
229                 __x86_cpu_dev_start = .;
230                 *(.x86_cpu_dev.init)
231                 __x86_cpu_dev_end = .;
232         }
233
234         . = ALIGN(8);
235         .parainstructions : AT(ADDR(.parainstructions) - LOAD_OFFSET) {
236                 __parainstructions = .;
237                 *(.parainstructions)
238                 __parainstructions_end = .;
239         }
240
241         . = ALIGN(8);
242         .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) {
243                 __alt_instructions = .;
244                 *(.altinstructions)
245                 __alt_instructions_end = .;
246         }
247
248         .altinstr_replacement : AT(ADDR(.altinstr_replacement) - LOAD_OFFSET) {
249                 *(.altinstr_replacement)
250         }
251
252         /*
253          * .exit.text is discard at runtime, not link time, to deal with
254          *  references from .altinstructions and .eh_frame
255          */
256         .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
257                 EXIT_TEXT
258         }
259
260         .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
261                 EXIT_DATA
262         }
263
264 #if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
265         PERCPU(PAGE_SIZE)
266 #endif
267
268         . = ALIGN(PAGE_SIZE);
269
270         /* freed after init ends here */
271         .init.end : AT(ADDR(.init.end) - LOAD_OFFSET) {
272                 __init_end = .;
273         }
274
275         /*
276          * smp_locks might be freed after init
277          * start/end must be page aligned
278          */
279         . = ALIGN(PAGE_SIZE);
280         .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
281                 __smp_locks = .;
282                 *(.smp_locks)
283                 __smp_locks_end = .;
284                 . = ALIGN(PAGE_SIZE);
285         }
286
287 #ifdef CONFIG_X86_64
288         .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
289                 NOSAVE_DATA
290         }
291 #endif
292
293         /* BSS */
294         . = ALIGN(PAGE_SIZE);
295         .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
296                 __bss_start = .;
297                 *(.bss.page_aligned)
298                 *(.bss)
299                 . = ALIGN(4);
300                 __bss_stop = .;
301         }
302
303         . = ALIGN(PAGE_SIZE);
304         .brk : AT(ADDR(.brk) - LOAD_OFFSET) {
305                 __brk_base = .;
306                 . += 64 * 1024;         /* 64k alignment slop space */
307                 *(.brk_reservation)     /* areas brk users have reserved */
308                 __brk_limit = .;
309         }
310
311         .end : AT(ADDR(.end) - LOAD_OFFSET) {
312                 _end = .;
313         }
314
315         STABS_DEBUG
316         DWARF_DEBUG
317
318         /* Sections to be discarded */
319         DISCARDS
320         /DISCARD/ : { *(.eh_frame) }
321 }
322
323
324 #ifdef CONFIG_X86_32
325 . = ASSERT((_end - LOAD_OFFSET <= KERNEL_IMAGE_SIZE),
326            "kernel image bigger than KERNEL_IMAGE_SIZE");
327 #else
328 /*
329  * Per-cpu symbols which need to be offset from __per_cpu_load
330  * for the boot processor.
331  */
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);
335
336 /*
337  * Build-time check on the image size:
338  */
339 . = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
340            "kernel image bigger than KERNEL_IMAGE_SIZE");
341
342 #ifdef CONFIG_SMP
343 . = ASSERT((per_cpu__irq_stack_union == 0),
344            "irq_stack_union is not at start of per-cpu area");
345 #endif
346
347 #endif /* CONFIG_X86_32 */
348
349 #ifdef CONFIG_KEXEC
350 #include <asm/kexec.h>
351
352 . = ASSERT(kexec_control_code_size <= KEXEC_CONTROL_CODE_MAX_SIZE,
353            "kexec control code size is too big");
354 #endif
355