x86: beautify vmlinux_64.lds.S
[safe/jmp/linux-2.6] / arch / x86 / kernel / vmlinux_64.lds.S
1 /* ld script to make x86-64 Linux kernel
2  * Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>;
3  */
4
5 #define LOAD_OFFSET __START_KERNEL_map
6
7 #include <asm-generic/vmlinux.lds.h>
8 #include <asm/asm-offsets.h>
9 #include <asm/page_types.h>
10
11 #undef i386     /* in case the preprocessor is a 32bit one */
12
13 OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64")
14 OUTPUT_ARCH(i386:x86-64)
15 ENTRY(phys_startup_64)
16 jiffies_64 = jiffies;
17 PHDRS {
18         text PT_LOAD FLAGS(5);          /* R_E */
19         data PT_LOAD FLAGS(7);          /* RWE */
20         user PT_LOAD FLAGS(7);          /* RWE */
21         data.init PT_LOAD FLAGS(7);     /* RWE */
22 #ifdef CONFIG_SMP
23         percpu PT_LOAD FLAGS(7);        /* RWE */
24 #endif
25         data.init2 PT_LOAD FLAGS(7);    /* RWE */
26         note PT_NOTE FLAGS(0);          /* ___ */
27 }
28 SECTIONS
29 {
30         . = __START_KERNEL;
31         phys_startup_64 = startup_64 - LOAD_OFFSET;
32
33         /* Text and read-only data */
34         .text :  AT(ADDR(.text) - LOAD_OFFSET) {
35                 _text = .;
36                 /* First the code that has to be first for bootstrapping */
37                 *(.text.head)
38                 _stext = .;
39                 /* Then the rest */
40                 TEXT_TEXT
41                 SCHED_TEXT
42                 LOCK_TEXT
43                 KPROBES_TEXT
44                 IRQENTRY_TEXT
45                 *(.fixup)
46                 *(.gnu.warning)
47                 /* End of text section */
48                 _etext = .;
49         } :text = 0x9090
50
51         NOTES :text :note
52
53         /* Exception table */
54         . = ALIGN(16);
55         __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
56                 __start___ex_table = .;
57                  *(__ex_table)
58                 __stop___ex_table = .;
59         } :text = 0x9090
60
61         RODATA
62
63         /* Align data segment to page size boundary */
64         . = ALIGN(PAGE_SIZE);
65         /* Data */
66         .data : AT(ADDR(.data) - LOAD_OFFSET) {
67                 DATA_DATA
68                 CONSTRUCTORS
69                 /* End of data section */
70                 _edata = .;
71         } :data
72
73
74         .data.cacheline_aligned :
75                 AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) {
76                 . = ALIGN(PAGE_SIZE);
77                 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
78                 *(.data.cacheline_aligned)
79         }
80
81         . = ALIGN(CONFIG_X86_INTERNODE_CACHE_BYTES);
82         .data.read_mostly : AT(ADDR(.data.read_mostly) - LOAD_OFFSET) {
83                 *(.data.read_mostly)
84         }
85
86 #define VSYSCALL_ADDR (-10*1024*1024)
87 #define VSYSCALL_PHYS_ADDR ((LOADADDR(.data.read_mostly) + \
88                             SIZEOF(.data.read_mostly) + 4095) & ~(4095))
89 #define VSYSCALL_VIRT_ADDR ((ADDR(.data.read_mostly) + \
90                             SIZEOF(.data.read_mostly) + 4095) & ~(4095))
91
92 #define VLOAD_OFFSET (VSYSCALL_ADDR - VSYSCALL_PHYS_ADDR)
93 #define VLOAD(x) (ADDR(x) - VLOAD_OFFSET)
94
95 #define VVIRT_OFFSET (VSYSCALL_ADDR - VSYSCALL_VIRT_ADDR)
96 #define VVIRT(x) (ADDR(x) - VVIRT_OFFSET)
97
98         . = VSYSCALL_ADDR;
99         .vsyscall_0 : AT(VSYSCALL_PHYS_ADDR) {
100                 *(.vsyscall_0)
101         } :user
102
103         __vsyscall_0 = VSYSCALL_VIRT_ADDR;
104
105         . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
106         .vsyscall_fn : AT(VLOAD(.vsyscall_fn)) {
107                 *(.vsyscall_fn)
108         }
109
110         . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
111         .vsyscall_gtod_data : AT(VLOAD(.vsyscall_gtod_data)) {
112                 *(.vsyscall_gtod_data)
113         }
114
115         vsyscall_gtod_data = VVIRT(.vsyscall_gtod_data);
116         .vsyscall_clock : AT(VLOAD(.vsyscall_clock)) {
117                 *(.vsyscall_clock)
118         }
119         vsyscall_clock = VVIRT(.vsyscall_clock);
120
121
122         .vsyscall_1 ADDR(.vsyscall_0) + 1024: AT(VLOAD(.vsyscall_1)) {
123                 *(.vsyscall_1)
124         }
125         .vsyscall_2 ADDR(.vsyscall_0) + 2048: AT(VLOAD(.vsyscall_2)) {
126                 *(.vsyscall_2)
127         }
128
129         .vgetcpu_mode : AT(VLOAD(.vgetcpu_mode)) {
130                 *(.vgetcpu_mode)
131         }
132         vgetcpu_mode = VVIRT(.vgetcpu_mode);
133
134         . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
135         .jiffies : AT(VLOAD(.jiffies)) {
136                 *(.jiffies)
137         }
138         jiffies = VVIRT(.jiffies);
139
140         .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) {
141                 *(.vsyscall_3)
142         }
143
144         . = VSYSCALL_VIRT_ADDR + PAGE_SIZE;
145
146 #undef VSYSCALL_ADDR
147 #undef VSYSCALL_PHYS_ADDR
148 #undef VSYSCALL_VIRT_ADDR
149 #undef VLOAD_OFFSET
150 #undef VLOAD
151 #undef VVIRT_OFFSET
152 #undef VVIRT
153
154         /* init_task */
155         .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
156                 . = ALIGN(THREAD_SIZE);
157                 *(.data.init_task)
158         } :data.init
159
160         .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
161                 . = ALIGN(PAGE_SIZE);
162                 *(.data.page_aligned)
163         }
164
165         .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
166                 /* might get freed after init */
167                 . = ALIGN(PAGE_SIZE);
168                 __smp_alt_begin = .;
169                 __smp_locks = .;
170                 *(.smp_locks)
171                 __smp_locks_end = .;
172                 . = ALIGN(PAGE_SIZE);
173                 __smp_alt_end = .;
174         }
175
176         /* Init code and data */
177         . = ALIGN(PAGE_SIZE);
178         __init_begin = .;       /* paired with __init_end */
179         .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {
180                 _sinittext = .;
181                 INIT_TEXT
182                 _einittext = .;
183         }
184
185         .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
186                 __initdata_begin = .;
187                 INIT_DATA
188                 __initdata_end = .;
189         }
190
191         .init.setup : AT(ADDR(.init.setup) - LOAD_OFFSET) {
192                 . = ALIGN(16);
193                 __setup_start = .;
194                 *(.init.setup)
195                 __setup_end = .;
196         }
197
198         .initcall.init : AT(ADDR(.initcall.init) - LOAD_OFFSET) {
199                 __initcall_start = .;
200                 INITCALLS
201                 __initcall_end = .;
202         }
203
204         .con_initcall.init : AT(ADDR(.con_initcall.init) - LOAD_OFFSET) {
205                 __con_initcall_start = .;
206                 *(.con_initcall.init)
207                 __con_initcall_end = .;
208         }
209
210         .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
211                 __x86_cpu_dev_start = .;
212                 *(.x86_cpu_dev.init)
213                 __x86_cpu_dev_end = .;
214         }
215
216         SECURITY_INIT
217
218         . = ALIGN(8);
219         .parainstructions : AT(ADDR(.parainstructions) - LOAD_OFFSET) {
220                 __parainstructions = .;
221                 *(.parainstructions)
222                 __parainstructions_end = .;
223         }
224
225         .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) {
226                 . = ALIGN(8);
227                 __alt_instructions = .;
228                 *(.altinstructions)
229                 __alt_instructions_end = .;
230         }
231
232         .altinstr_replacement : AT(ADDR(.altinstr_replacement) - LOAD_OFFSET) {
233                 *(.altinstr_replacement)
234         }
235
236         /*
237          * .exit.text is discard at runtime, not link time, to deal with
238          *  references from .altinstructions and .eh_frame
239          */
240         .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
241                 EXIT_TEXT
242         }
243
244         .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
245                 EXIT_DATA
246         }
247
248 #ifdef CONFIG_BLK_DEV_INITRD
249         . = ALIGN(PAGE_SIZE);
250         .init.ramfs : AT(ADDR(.init.ramfs) - LOAD_OFFSET) {
251                 __initramfs_start = .;
252                 *(.init.ramfs)
253                 __initramfs_end = .;
254         }
255 #endif
256
257 #ifdef CONFIG_SMP
258         /*
259          * percpu offsets are zero-based on SMP.  PERCPU_VADDR() changes the
260          * output PHDR, so the next output section - __data_nosave - should
261          * start another section data.init2.  Also, pda should be at the head of
262          * percpu area.  Preallocate it and define the percpu offset symbol
263          * so that it can be accessed as a percpu variable.
264          */
265         . = ALIGN(PAGE_SIZE);
266         PERCPU_VADDR(0, :percpu)
267 #else
268         PERCPU(PAGE_SIZE)
269 #endif
270
271         . = ALIGN(PAGE_SIZE);
272         __init_end = .;
273
274         .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
275                 . = ALIGN(PAGE_SIZE);
276                 __nosave_begin = .;
277                 *(.data.nosave)
278                 . = ALIGN(PAGE_SIZE);
279                 __nosave_end = .;
280         } :data.init2
281         /* use another section data.init2, see PERCPU_VADDR() above */
282
283         .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
284                 . = ALIGN(PAGE_SIZE);
285                 __bss_start = .;                /* BSS */
286                 *(.bss.page_aligned)
287                 *(.bss)
288                 __bss_stop = .;
289         }
290
291         .brk : AT(ADDR(.brk) - LOAD_OFFSET) {
292                 . = ALIGN(PAGE_SIZE);
293                 __brk_base = .;
294                 . += 64 * 1024;         /* 64k alignment slop space */
295                 *(.brk_reservation)     /* areas brk users have reserved */
296                 __brk_limit = .;
297         }
298
299         _end = . ;
300
301         /* Sections to be discarded */
302         /DISCARD/ : {
303                 *(.exitcall.exit)
304                 *(.eh_frame)
305                 *(.discard)
306         }
307
308         STABS_DEBUG
309         DWARF_DEBUG
310 }
311
312 /*
313  * Per-cpu symbols which need to be offset from __per_cpu_load
314  * for the boot processor.
315  */
316 #define INIT_PER_CPU(x) init_per_cpu__##x = per_cpu__##x + __per_cpu_load
317 INIT_PER_CPU(gdt_page);
318 INIT_PER_CPU(irq_stack_union);
319
320 /*
321  * Build-time check on the image size:
322  */
323 ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
324         "kernel image bigger than KERNEL_IMAGE_SIZE")
325
326 #ifdef CONFIG_SMP
327 ASSERT((per_cpu__irq_stack_union == 0),
328         "irq_stack_union is not at start of per-cpu area");
329 #endif
330
331 #ifdef CONFIG_KEXEC
332 #include <asm/kexec.h>
333
334 ASSERT(kexec_control_code_size <= KEXEC_CONTROL_CODE_MAX_SIZE,
335        "kexec control code size is too big")
336 #endif