blob: b96ca472fa261539fb66a4ce66d3813fbf8513dd [file] [log] [blame]
Sam Ravnborg17ce2652009-04-29 09:47:18 +02001/*
2 * ld script for the x86 kernel
3 *
4 * Historic 32-bit version written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>
5 *
Ingo Molnar91fd7fe2009-04-29 10:58:38 +02006 * Modernisation, unification and other changes and fixes:
7 * Copyright (C) 2007-2009 Sam Ravnborg <sam@ravnborg.org>
Sam Ravnborg17ce2652009-04-29 09:47:18 +02008 *
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
32OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT, CONFIG_OUTPUT_FORMAT, CONFIG_OUTPUT_FORMAT)
33
34#ifdef CONFIG_X86_32
35OUTPUT_ARCH(i386)
36ENTRY(phys_startup_32)
37jiffies = jiffies_64;
38#else
39OUTPUT_ARCH(i386:x86-64)
40ENTRY(phys_startup_64)
41jiffies_64 = jiffies;
42#endif
43
Sam Ravnborgafb80952009-04-29 09:47:19 +020044PHDRS {
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 */
Sam Ravnborgafb80952009-04-29 09:47:19 +020049#ifdef CONFIG_SMP
50 percpu PT_LOAD FLAGS(7); /* RWE */
51#endif
Jan Beulichc62e4322009-08-25 14:50:53 +010052 init PT_LOAD FLAGS(7); /* RWE */
Sam Ravnborgafb80952009-04-29 09:47:19 +020053#endif
54 note PT_NOTE FLAGS(0); /* ___ */
55}
Sam Ravnborg17ce2652009-04-29 09:47:18 +020056
Sam Ravnborg444e0ae2009-04-29 09:47:20 +020057SECTIONS
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
Sam Ravnborgdfc208952009-04-29 09:47:21 +020067 /* 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
Sam Ravnborg448bc3a2009-04-29 09:47:22 +020097 /* 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
Jan Beulichc62e4322009-08-25 14:50:53 +0100105 RO_DATA(PAGE_SIZE)
Sam Ravnborg448bc3a2009-04-29 09:47:22 +0200106
Sam Ravnborg1f6397b2009-04-29 09:47:23 +0200107 /* Data */
Sam Ravnborg1f6397b2009-04-29 09:47:23 +0200108 .data : AT(ADDR(.data) - LOAD_OFFSET) {
Catalin Marinas12608662009-05-11 13:22:00 +0100109 /* Start of data section */
110 _sdata = .;
Jan Beulichc62e4322009-08-25 14:50:53 +0100111
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
Sam Ravnborg1f6397b2009-04-29 09:47:23 +0200125 DATA_DATA
126 CONSTRUCTORS
Sam Ravnborg1f6397b2009-04-29 09:47:23 +0200127
Jan Beulichc62e4322009-08-25 14:50:53 +0100128 /* rarely changed data like cpu maps */
129 READ_MOSTLY_DATA(CONFIG_X86_INTERNODE_CACHE_BYTES)
Sam Ravnborg1f6397b2009-04-29 09:47:23 +0200130
Sam Ravnborg1f6397b2009-04-29 09:47:23 +0200131 /* End of data section */
132 _edata = .;
Jan Beulichc62e4322009-08-25 14:50:53 +0100133 } :data
Sam Ravnborg1f6397b2009-04-29 09:47:23 +0200134
Sam Ravnborgff6f87e2009-04-29 09:47:24 +0200135#ifdef CONFIG_X86_64
136
137#define VSYSCALL_ADDR (-10*1024*1024)
Sam Ravnborgff6f87e2009-04-29 09:47:24 +0200138
Anders Kaseorgd2232462009-09-16 16:44:26 -0400139#define VLOAD_OFFSET (VSYSCALL_ADDR - __vsyscall_0 + LOAD_OFFSET)
Sam Ravnborgff6f87e2009-04-29 09:47:24 +0200140#define VLOAD(x) (ADDR(x) - VLOAD_OFFSET)
141
Anders Kaseorgd2232462009-09-16 16:44:26 -0400142#define VVIRT_OFFSET (VSYSCALL_ADDR - __vsyscall_0)
Sam Ravnborgff6f87e2009-04-29 09:47:24 +0200143#define VVIRT(x) (ADDR(x) - VVIRT_OFFSET)
144
Anders Kaseorgd2232462009-09-16 16:44:26 -0400145 . = ALIGN(4096);
146 __vsyscall_0 = .;
147
Sam Ravnborgff6f87e2009-04-29 09:47:24 +0200148 . = VSYSCALL_ADDR;
Anders Kaseorgd2232462009-09-16 16:44:26 -0400149 .vsyscall_0 : AT(VLOAD(.vsyscall_0)) {
Sam Ravnborgff6f87e2009-04-29 09:47:24 +0200150 *(.vsyscall_0)
151 } :user
152
Sam Ravnborgff6f87e2009-04-29 09:47:24 +0200153 . = 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
Anders Kaseorgd2232462009-09-16 16:44:26 -0400192 . = __vsyscall_0 + PAGE_SIZE;
Sam Ravnborgff6f87e2009-04-29 09:47:24 +0200193
194#undef VSYSCALL_ADDR
Sam Ravnborgff6f87e2009-04-29 09:47:24 +0200195#undef VLOAD_OFFSET
196#undef VLOAD
197#undef VVIRT_OFFSET
198#undef VVIRT
199
200#endif /* CONFIG_X86_64 */
Sam Ravnborgdfc208952009-04-29 09:47:21 +0200201
Sam Ravnborge58bdaa2009-04-29 09:47:25 +0200202 /* Init code and data - will be freed after init */
203 . = ALIGN(PAGE_SIZE);
Jan Beulichc62e4322009-08-25 14:50:53 +0100204 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
Ingo Molnarfd073192009-04-29 12:56:58 +0200205 __init_begin = .; /* paired with __init_end */
Jan Beulichc62e4322009-08-25 14:50:53 +0100206 }
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) {
Sam Ravnborge58bdaa2009-04-29 09:47:25 +0200218 _sinittext = .;
219 INIT_TEXT
220 _einittext = .;
221 }
Jan Beulichc62e4322009-08-25 14:50:53 +0100222#ifdef CONFIG_X86_64
223 :init
224#endif
Sam Ravnborge58bdaa2009-04-29 09:47:25 +0200225
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
Sam Ravnborgae618362009-04-29 09:47:26 +0200256 . = 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
Sam Ravnborgbf6a5742009-04-29 09:47:27 +0200274 /*
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
Sam Ravnborge58bdaa2009-04-29 09:47:25 +0200294
Jan Beulichc62e4322009-08-25 14:50:53 +0100295#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
Sam Ravnborg9d16e782009-04-29 09:47:28 +0200296 PERCPU(PAGE_SIZE)
297#endif
298
299 . = ALIGN(PAGE_SIZE);
Ingo Molnarfd073192009-04-29 12:56:58 +0200300
Sam Ravnborg9d16e782009-04-29 09:47:28 +0200301 /* freed after init ends here */
Ingo Molnarfd073192009-04-29 12:56:58 +0200302 .init.end : AT(ADDR(.init.end) - LOAD_OFFSET) {
303 __init_end = .;
304 }
Sam Ravnborg9d16e782009-04-29 09:47:28 +0200305
Jan Beulichc62e4322009-08-25 14:50:53 +0100306 /*
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
Sam Ravnborg9d16e782009-04-29 09:47:28 +0200318#ifdef CONFIG_X86_64
319 .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
Jan Beulichc62e4322009-08-25 14:50:53 +0100320 NOSAVE_DATA
321 }
Sam Ravnborg9d16e782009-04-29 09:47:28 +0200322#endif
323
Sam Ravnborg091e52c2009-04-29 09:47:29 +0200324 /* 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 }
Sam Ravnborg9d16e782009-04-29 09:47:28 +0200333
Sam Ravnborg091e52c2009-04-29 09:47:29 +0200334 . = 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
Sam Ravnborg444e0ae2009-04-29 09:47:20 +0200346 STABS_DEBUG
347 DWARF_DEBUG
Tejun Heo023bf6f2009-07-09 11:27:40 +0900348
349 /* Sections to be discarded */
350 DISCARDS
351 /DISCARD/ : { *(.eh_frame) }
Sam Ravnborg444e0ae2009-04-29 09:47:20 +0200352}
353
Sam Ravnborg17ce2652009-04-29 09:47:18 +0200354
355#ifdef CONFIG_X86_32
H. Peter Anvind2ba8b22009-08-03 14:44:54 -0700356. = ASSERT((_end - LOAD_OFFSET <= KERNEL_IMAGE_SIZE),
357 "kernel image bigger than KERNEL_IMAGE_SIZE");
Sam Ravnborg17ce2652009-04-29 09:47:18 +0200358#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
364INIT_PER_CPU(gdt_page);
365INIT_PER_CPU(irq_stack_union);
366
367/*
368 * Build-time check on the image size:
369 */
H. Peter Anvind2ba8b22009-08-03 14:44:54 -0700370. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
371 "kernel image bigger than KERNEL_IMAGE_SIZE");
Sam Ravnborg17ce2652009-04-29 09:47:18 +0200372
373#ifdef CONFIG_SMP
H. Peter Anvind2ba8b22009-08-03 14:44:54 -0700374. = ASSERT((per_cpu__irq_stack_union == 0),
375 "irq_stack_union is not at start of per-cpu area");
Sam Ravnborg17ce2652009-04-29 09:47:18 +0200376#endif
377
378#endif /* CONFIG_X86_32 */
379
380#ifdef CONFIG_KEXEC
381#include <asm/kexec.h>
382
H. Peter Anvind2ba8b22009-08-03 14:44:54 -0700383. = ASSERT(kexec_control_code_size <= KEXEC_CONTROL_CODE_MAX_SIZE,
384 "kexec control code size is too big");
Sam Ravnborg17ce2652009-04-29 09:47:18 +0200385#endif
386