blob: c8742507b030bec22bb90fcdcfc12d5dcdb35da7 [file] [log] [blame]
Thomas Gleixner13a9cd42007-10-11 11:14:21 +02001/* 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>
Tejun Heo1a51e3a2009-01-13 20:41:35 +09008#include <asm/asm-offsets.h>
Jeremy Fitzhardinge0341c142009-02-13 11:14:01 -08009#include <asm/page_types.h>
Thomas Gleixner13a9cd42007-10-11 11:14:21 +020010
11#undef i386 /* in case the preprocessor is a 32bit one */
12
13OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64")
14OUTPUT_ARCH(i386:x86-64)
15ENTRY(phys_startup_64)
16jiffies_64 = jiffies;
Thomas Gleixner13a9cd42007-10-11 11:14:21 +020017PHDRS {
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 */
Tejun Heo3e5d8f92009-01-13 20:41:35 +090022#ifdef CONFIG_SMP
23 percpu PT_LOAD FLAGS(7); /* RWE */
24#endif
Yinghai Luef3892b2009-02-02 18:16:19 -080025 data.init2 PT_LOAD FLAGS(7); /* RWE */
Jan Beulich6360b1f2008-05-12 15:44:41 +020026 note PT_NOTE FLAGS(0); /* ___ */
Thomas Gleixner13a9cd42007-10-11 11:14:21 +020027}
28SECTIONS
29{
30 . = __START_KERNEL;
31 phys_startup_64 = startup_64 - LOAD_OFFSET;
Thomas Gleixner13a9cd42007-10-11 11:14:21 +020032 .text : AT(ADDR(.text) - LOAD_OFFSET) {
Jeremy Fitzhardingeb9719a42009-03-10 11:19:18 -070033 _text = .; /* Text and read-only data */
Thomas Gleixner13a9cd42007-10-11 11:14:21 +020034 /* First the code that has to be first for bootstrapping */
35 *(.text.head)
36 _stext = .;
37 /* Then the rest */
38 TEXT_TEXT
39 SCHED_TEXT
40 LOCK_TEXT
41 KPROBES_TEXT
Frederic Weisbeckera0343e82008-12-09 23:53:16 +010042 IRQENTRY_TEXT
Thomas Gleixner13a9cd42007-10-11 11:14:21 +020043 *(.fixup)
44 *(.gnu.warning)
Cyrill Gorcunov3cdac412008-02-17 18:17:17 +030045 _etext = .; /* End of text section */
Jan Beulichc0400032008-01-30 13:33:14 +010046 } :text = 0x9090
Thomas Gleixner13a9cd42007-10-11 11:14:21 +020047
Jan Beulich6360b1f2008-05-12 15:44:41 +020048 NOTES :text :note
49
Thomas Gleixner13a9cd42007-10-11 11:14:21 +020050 . = ALIGN(16); /* Exception table */
Jan Beulichc0400032008-01-30 13:33:14 +010051 __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
52 __start___ex_table = .;
53 *(__ex_table)
54 __stop___ex_table = .;
Jan Beulich6360b1f2008-05-12 15:44:41 +020055 } :text = 0x9090
Thomas Gleixner13a9cd42007-10-11 11:14:21 +020056
57 RODATA
58
Cyrill Gorcunov3cdac412008-02-17 18:17:17 +030059 . = ALIGN(PAGE_SIZE); /* Align data segment to page size boundary */
Thomas Gleixner13a9cd42007-10-11 11:14:21 +020060 /* Data */
61 .data : AT(ADDR(.data) - LOAD_OFFSET) {
62 DATA_DATA
63 CONSTRUCTORS
Jeremy Fitzhardingeb9719a42009-03-10 11:19:18 -070064 _edata = .; /* End of data section */
Thomas Gleixner13a9cd42007-10-11 11:14:21 +020065 } :data
66
Thomas Gleixner13a9cd42007-10-11 11:14:21 +020067
Thomas Gleixner13a9cd42007-10-11 11:14:21 +020068 .data.cacheline_aligned : AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) {
Jeremy Fitzhardingeb9719a42009-03-10 11:19:18 -070069 . = ALIGN(PAGE_SIZE);
70 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
Thomas Gleixner13a9cd42007-10-11 11:14:21 +020071 *(.data.cacheline_aligned)
72 }
73 . = ALIGN(CONFIG_X86_INTERNODE_CACHE_BYTES);
74 .data.read_mostly : AT(ADDR(.data.read_mostly) - LOAD_OFFSET) {
75 *(.data.read_mostly)
76 }
77
78#define VSYSCALL_ADDR (-10*1024*1024)
79#define VSYSCALL_PHYS_ADDR ((LOADADDR(.data.read_mostly) + SIZEOF(.data.read_mostly) + 4095) & ~(4095))
80#define VSYSCALL_VIRT_ADDR ((ADDR(.data.read_mostly) + SIZEOF(.data.read_mostly) + 4095) & ~(4095))
81
82#define VLOAD_OFFSET (VSYSCALL_ADDR - VSYSCALL_PHYS_ADDR)
83#define VLOAD(x) (ADDR(x) - VLOAD_OFFSET)
84
85#define VVIRT_OFFSET (VSYSCALL_ADDR - VSYSCALL_VIRT_ADDR)
86#define VVIRT(x) (ADDR(x) - VVIRT_OFFSET)
87
88 . = VSYSCALL_ADDR;
89 .vsyscall_0 : AT(VSYSCALL_PHYS_ADDR) { *(.vsyscall_0) } :user
90 __vsyscall_0 = VSYSCALL_VIRT_ADDR;
91
92 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
93 .vsyscall_fn : AT(VLOAD(.vsyscall_fn)) { *(.vsyscall_fn) }
94 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
95 .vsyscall_gtod_data : AT(VLOAD(.vsyscall_gtod_data))
96 { *(.vsyscall_gtod_data) }
97 vsyscall_gtod_data = VVIRT(.vsyscall_gtod_data);
98 .vsyscall_clock : AT(VLOAD(.vsyscall_clock))
99 { *(.vsyscall_clock) }
100 vsyscall_clock = VVIRT(.vsyscall_clock);
101
102
103 .vsyscall_1 ADDR(.vsyscall_0) + 1024: AT(VLOAD(.vsyscall_1))
104 { *(.vsyscall_1) }
105 .vsyscall_2 ADDR(.vsyscall_0) + 2048: AT(VLOAD(.vsyscall_2))
106 { *(.vsyscall_2) }
107
108 .vgetcpu_mode : AT(VLOAD(.vgetcpu_mode)) { *(.vgetcpu_mode) }
109 vgetcpu_mode = VVIRT(.vgetcpu_mode);
110
111 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
112 .jiffies : AT(VLOAD(.jiffies)) { *(.jiffies) }
113 jiffies = VVIRT(.jiffies);
114
115 .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3))
116 { *(.vsyscall_3) }
117
Cyrill Gorcunov3cdac412008-02-17 18:17:17 +0300118 . = VSYSCALL_VIRT_ADDR + PAGE_SIZE;
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200119
120#undef VSYSCALL_ADDR
121#undef VSYSCALL_PHYS_ADDR
122#undef VSYSCALL_VIRT_ADDR
123#undef VLOAD_OFFSET
124#undef VLOAD
125#undef VVIRT_OFFSET
126#undef VVIRT
127
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200128 .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
Jeremy Fitzhardingeb9719a42009-03-10 11:19:18 -0700129 . = ALIGN(THREAD_SIZE); /* init_task */
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200130 *(.data.init_task)
131 }:data.init
132
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200133 .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
Jeremy Fitzhardingeb9719a42009-03-10 11:19:18 -0700134 . = ALIGN(PAGE_SIZE);
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200135 *(.data.page_aligned)
136 }
137
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200138 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
Jeremy Fitzhardingeb9719a42009-03-10 11:19:18 -0700139 /* might get freed after init */
140 . = ALIGN(PAGE_SIZE);
141 __smp_alt_begin = .;
142 __smp_locks = .;
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200143 *(.smp_locks)
Jeremy Fitzhardingeb9719a42009-03-10 11:19:18 -0700144 __smp_locks_end = .;
145 . = ALIGN(PAGE_SIZE);
146 __smp_alt_end = .;
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200147 }
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200148
Cyrill Gorcunov3cdac412008-02-17 18:17:17 +0300149 . = ALIGN(PAGE_SIZE); /* Init code and data */
Jeremy Fitzhardingeb9719a42009-03-10 11:19:18 -0700150 __init_begin = .; /* paired with __init_end */
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200151 .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {
152 _sinittext = .;
Sam Ravnborg01ba2bd2008-01-20 14:15:03 +0100153 INIT_TEXT
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200154 _einittext = .;
155 }
Sam Ravnborg01ba2bd2008-01-20 14:15:03 +0100156 .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
157 __initdata_begin = .;
158 INIT_DATA
159 __initdata_end = .;
160 }
161
Jeremy Fitzhardingeb9719a42009-03-10 11:19:18 -0700162 .init.setup : AT(ADDR(.init.setup) - LOAD_OFFSET) {
163 . = ALIGN(16);
164 __setup_start = .;
165 *(.init.setup)
166 __setup_end = .;
167 }
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200168 .initcall.init : AT(ADDR(.initcall.init) - LOAD_OFFSET) {
Jeremy Fitzhardingeb9719a42009-03-10 11:19:18 -0700169 __initcall_start = .;
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200170 INITCALLS
Jeremy Fitzhardingeb9719a42009-03-10 11:19:18 -0700171 __initcall_end = .;
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200172 }
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200173 .con_initcall.init : AT(ADDR(.con_initcall.init) - LOAD_OFFSET) {
Jeremy Fitzhardingeb9719a42009-03-10 11:19:18 -0700174 __con_initcall_start = .;
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200175 *(.con_initcall.init)
Jeremy Fitzhardingeb9719a42009-03-10 11:19:18 -0700176 __con_initcall_end = .;
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200177 }
Yinghai Lu10a434f2008-09-04 21:09:45 +0200178 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
Jeremy Fitzhardingeb9719a42009-03-10 11:19:18 -0700179 __x86_cpu_dev_start = .;
Yinghai Lu10a434f2008-09-04 21:09:45 +0200180 *(.x86_cpu_dev.init)
Jeremy Fitzhardingeb9719a42009-03-10 11:19:18 -0700181 __x86_cpu_dev_end = .;
Thomas Petazzoni03ae5762008-02-15 12:00:23 +0100182 }
Petr Vandroveccb58ffc2008-10-12 10:51:03 +0200183 SECURITY_INIT
Glauber de Oliveira Costafbf51922008-01-30 13:33:19 +0100184
185 . = ALIGN(8);
186 .parainstructions : AT(ADDR(.parainstructions) - LOAD_OFFSET) {
Jeremy Fitzhardingeb9719a42009-03-10 11:19:18 -0700187 __parainstructions = .;
Glauber de Oliveira Costafbf51922008-01-30 13:33:19 +0100188 *(.parainstructions)
Jeremy Fitzhardingeb9719a42009-03-10 11:19:18 -0700189 __parainstructions_end = .;
Glauber de Oliveira Costafbf51922008-01-30 13:33:19 +0100190 }
191
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200192 .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) {
Jeremy Fitzhardingeb9719a42009-03-10 11:19:18 -0700193 . = ALIGN(8);
194 __alt_instructions = .;
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200195 *(.altinstructions)
Jeremy Fitzhardingeb9719a42009-03-10 11:19:18 -0700196 __alt_instructions_end = .;
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200197 }
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200198 .altinstr_replacement : AT(ADDR(.altinstr_replacement) - LOAD_OFFSET) {
199 *(.altinstr_replacement)
200 }
201 /* .exit.text is discard at runtime, not link time, to deal with references
202 from .altinstructions and .eh_frame */
Sam Ravnborg01ba2bd2008-01-20 14:15:03 +0100203 .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
204 EXIT_TEXT
205 }
206 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
207 EXIT_DATA
208 }
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200209
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200210#ifdef CONFIG_BLK_DEV_INITRD
Cyrill Gorcunov3cdac412008-02-17 18:17:17 +0300211 . = ALIGN(PAGE_SIZE);
Jeremy Fitzhardingeb9719a42009-03-10 11:19:18 -0700212 .init.ramfs : AT(ADDR(.init.ramfs) - LOAD_OFFSET) {
213 __initramfs_start = .;
214 *(.init.ramfs)
215 __initramfs_end = .;
216 }
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200217#endif
218
Tejun Heo3e5d8f92009-01-13 20:41:35 +0900219#ifdef CONFIG_SMP
220 /*
221 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
222 * output PHDR, so the next output section - __data_nosave - should
Yinghai Luef3892b2009-02-02 18:16:19 -0800223 * start another section data.init2. Also, pda should be at the head of
Tejun Heob12d8db2009-01-13 20:41:35 +0900224 * percpu area. Preallocate it and define the percpu offset symbol
225 * so that it can be accessed as a percpu variable.
Tejun Heo3e5d8f92009-01-13 20:41:35 +0900226 */
227 . = ALIGN(PAGE_SIZE);
Brian Gerst947e76c2009-01-19 12:21:28 +0900228 PERCPU_VADDR(0, :percpu)
Tejun Heo3e5d8f92009-01-13 20:41:35 +0900229#else
Cyrill Gorcunov3cdac412008-02-17 18:17:17 +0300230 PERCPU(PAGE_SIZE)
Tejun Heo3e5d8f92009-01-13 20:41:35 +0900231#endif
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200232
Cyrill Gorcunov3cdac412008-02-17 18:17:17 +0300233 . = ALIGN(PAGE_SIZE);
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200234 __init_end = .;
235
Tejun Heo3e5d8f92009-01-13 20:41:35 +0900236 .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
Jeremy Fitzhardingeb9719a42009-03-10 11:19:18 -0700237 . = ALIGN(PAGE_SIZE);
238 __nosave_begin = .;
239 *(.data.nosave)
240 . = ALIGN(PAGE_SIZE);
241 __nosave_end = .;
Yinghai Luef3892b2009-02-02 18:16:19 -0800242 } :data.init2 /* use another section data.init2, see PERCPU_VADDR() above */
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200243
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200244 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
Jeremy Fitzhardingeb9719a42009-03-10 11:19:18 -0700245 . = ALIGN(PAGE_SIZE);
246 __bss_start = .; /* BSS */
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200247 *(.bss.page_aligned)
248 *(.bss)
Jeremy Fitzhardingeb9719a42009-03-10 11:19:18 -0700249 __bss_stop = .;
Jeremy Fitzhardinge704439d2009-03-14 23:20:47 -0700250 }
Jeremy Fitzhardinge93dbda72009-02-26 17:35:44 -0800251
Jeremy Fitzhardinge704439d2009-03-14 23:20:47 -0700252 .brk : AT(ADDR(.brk) - LOAD_OFFSET) {
Jeremy Fitzhardinge93dbda72009-02-26 17:35:44 -0800253 . = ALIGN(PAGE_SIZE);
254 __brk_base = . ;
Jeremy Fitzhardinge704439d2009-03-14 23:20:47 -0700255 . += 64 * 1024 ; /* 64k alignment slop space */
Jeremy Fitzhardinge796216a2009-03-12 16:09:49 -0700256 *(.brk_reservation) /* areas brk users have reserved */
Jeremy Fitzhardinge93dbda72009-02-26 17:35:44 -0800257 __brk_limit = . ;
Jeremy Fitzhardingeb9719a42009-03-10 11:19:18 -0700258 }
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200259
260 _end = . ;
261
262 /* Sections to be discarded */
263 /DISCARD/ : {
264 *(.exitcall.exit)
265 *(.eh_frame)
Jeremy Fitzhardinge796216a2009-03-12 16:09:49 -0700266 *(.discard)
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200267 }
268
269 STABS_DEBUG
270
271 DWARF_DEBUG
272}
Ingo Molnarb4e04092008-02-21 13:45:16 +0100273
Brian Gerst2add8e22009-02-08 09:58:39 -0500274 /*
275 * Per-cpu symbols which need to be offset from __per_cpu_load
276 * for the boot processor.
277 */
278#define INIT_PER_CPU(x) init_per_cpu__##x = per_cpu__##x + __per_cpu_load
279INIT_PER_CPU(gdt_page);
280INIT_PER_CPU(irq_stack_union);
281
Ingo Molnarb4e04092008-02-21 13:45:16 +0100282/*
283 * Build-time check on the image size:
284 */
285ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
286 "kernel image bigger than KERNEL_IMAGE_SIZE")
Brian Gerst947e76c2009-01-19 12:21:28 +0900287
288#ifdef CONFIG_SMP
289ASSERT((per_cpu__irq_stack_union == 0),
290 "irq_stack_union is not at start of per-cpu area");
291#endif
Huang Yingfee7b0d2009-03-10 10:57:16 +0800292
293#ifdef CONFIG_KEXEC
294#include <asm/kexec.h>
295
296ASSERT(kexec_control_code_size <= KEXEC_CONTROL_CODE_MAX_SIZE,
297 "kexec control code size is too big")
298#endif