blob: 14763790e4156d6ad922b46671e758e584ea6625 [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
Suresh Siddha74e08172009-10-14 14:46:56 -070044#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
Sam Ravnborgafb80952009-04-29 09:47:19 +020059PHDRS {
60 text PT_LOAD FLAGS(5); /* R_E */
61 data PT_LOAD FLAGS(7); /* RWE */
62#ifdef CONFIG_X86_64
Jan Beulich8d0cc632009-09-04 09:18:07 +010063 user PT_LOAD FLAGS(5); /* R_E */
Sam Ravnborgafb80952009-04-29 09:47:19 +020064#ifdef CONFIG_SMP
Jan Beulich8d0cc632009-09-04 09:18:07 +010065 percpu PT_LOAD FLAGS(6); /* RW_ */
Sam Ravnborgafb80952009-04-29 09:47:19 +020066#endif
Jan Beulichc62e4322009-08-25 14:50:53 +010067 init PT_LOAD FLAGS(7); /* RWE */
Sam Ravnborgafb80952009-04-29 09:47:19 +020068#endif
69 note PT_NOTE FLAGS(0); /* ___ */
70}
Sam Ravnborg17ce2652009-04-29 09:47:18 +020071
Sam Ravnborg444e0ae2009-04-29 09:47:20 +020072SECTIONS
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
Sam Ravnborgdfc208952009-04-29 09:47:21 +020082 /* Text and read-only data */
Sam Ravnborgdfc208952009-04-29 09:47:21 +020083 .text : AT(ADDR(.text) - LOAD_OFFSET) {
Tim Abbott4ae59b92009-09-16 16:44:28 -040084 _text = .;
85 /* bootstrapping code */
86 HEAD_TEXT
Sam Ravnborgdfc208952009-04-29 09:47:21 +020087#ifdef CONFIG_X86_32
Sam Ravnborgdfc208952009-04-29 09:47:21 +020088 . = 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
Tim Abbott123f3e12009-09-16 16:44:30 -0400106 EXCEPTION_TABLE(16) :text = 0x9090
Sam Ravnborg448bc3a2009-04-29 09:47:22 +0200107
Suresh Siddha74e08172009-10-14 14:46:56 -0700108 X64_ALIGN_DEBUG_RODATA_BEGIN
Jan Beulichc62e4322009-08-25 14:50:53 +0100109 RO_DATA(PAGE_SIZE)
Suresh Siddha74e08172009-10-14 14:46:56 -0700110 X64_ALIGN_DEBUG_RODATA_END
Sam Ravnborg448bc3a2009-04-29 09:47:22 +0200111
Sam Ravnborg1f6397b2009-04-29 09:47:23 +0200112 /* Data */
Sam Ravnborg1f6397b2009-04-29 09:47:23 +0200113 .data : AT(ADDR(.data) - LOAD_OFFSET) {
Catalin Marinas12608662009-05-11 13:22:00 +0100114 /* Start of data section */
115 _sdata = .;
Jan Beulichc62e4322009-08-25 14:50:53 +0100116
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)
Jan Beulichc62e4322009-08-25 14:50:53 +0100126
127 CACHELINE_ALIGNED_DATA(CONFIG_X86_L1_CACHE_BYTES)
128
Sam Ravnborg1f6397b2009-04-29 09:47:23 +0200129 DATA_DATA
130 CONSTRUCTORS
Sam Ravnborg1f6397b2009-04-29 09:47:23 +0200131
Jan Beulichc62e4322009-08-25 14:50:53 +0100132 /* rarely changed data like cpu maps */
133 READ_MOSTLY_DATA(CONFIG_X86_INTERNODE_CACHE_BYTES)
Sam Ravnborg1f6397b2009-04-29 09:47:23 +0200134
Sam Ravnborg1f6397b2009-04-29 09:47:23 +0200135 /* End of data section */
136 _edata = .;
Jan Beulichc62e4322009-08-25 14:50:53 +0100137 } :data
Sam Ravnborg1f6397b2009-04-29 09:47:23 +0200138
Sam Ravnborgff6f87e2009-04-29 09:47:24 +0200139#ifdef CONFIG_X86_64
140
141#define VSYSCALL_ADDR (-10*1024*1024)
Sam Ravnborgff6f87e2009-04-29 09:47:24 +0200142
Anders Kaseorgd2232462009-09-16 16:44:26 -0400143#define VLOAD_OFFSET (VSYSCALL_ADDR - __vsyscall_0 + LOAD_OFFSET)
Sam Ravnborgff6f87e2009-04-29 09:47:24 +0200144#define VLOAD(x) (ADDR(x) - VLOAD_OFFSET)
145
Anders Kaseorgd2232462009-09-16 16:44:26 -0400146#define VVIRT_OFFSET (VSYSCALL_ADDR - __vsyscall_0)
Sam Ravnborgff6f87e2009-04-29 09:47:24 +0200147#define VVIRT(x) (ADDR(x) - VVIRT_OFFSET)
148
Anders Kaseorgd2232462009-09-16 16:44:26 -0400149 . = ALIGN(4096);
150 __vsyscall_0 = .;
151
Sam Ravnborgff6f87e2009-04-29 09:47:24 +0200152 . = VSYSCALL_ADDR;
Anders Kaseorgd2232462009-09-16 16:44:26 -0400153 .vsyscall_0 : AT(VLOAD(.vsyscall_0)) {
Sam Ravnborgff6f87e2009-04-29 09:47:24 +0200154 *(.vsyscall_0)
155 } :user
156
Sam Ravnborgff6f87e2009-04-29 09:47:24 +0200157 . = 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
Anders Kaseorgd2232462009-09-16 16:44:26 -0400196 . = __vsyscall_0 + PAGE_SIZE;
Sam Ravnborgff6f87e2009-04-29 09:47:24 +0200197
198#undef VSYSCALL_ADDR
Sam Ravnborgff6f87e2009-04-29 09:47:24 +0200199#undef VLOAD_OFFSET
200#undef VLOAD
201#undef VVIRT_OFFSET
202#undef VVIRT
203
204#endif /* CONFIG_X86_64 */
Sam Ravnborgdfc208952009-04-29 09:47:21 +0200205
Sam Ravnborge58bdaa2009-04-29 09:47:25 +0200206 /* Init code and data - will be freed after init */
207 . = ALIGN(PAGE_SIZE);
Jan Beulichc62e4322009-08-25 14:50:53 +0100208 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
Ingo Molnarfd073192009-04-29 12:56:58 +0200209 __init_begin = .; /* paired with __init_end */
Jan Beulichc62e4322009-08-25 14:50:53 +0100210 }
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
Tim Abbott123f3e12009-09-16 16:44:30 -0400221 INIT_TEXT_SECTION(PAGE_SIZE)
Jan Beulichc62e4322009-08-25 14:50:53 +0100222#ifdef CONFIG_X86_64
223 :init
224#endif
Sam Ravnborge58bdaa2009-04-29 09:47:25 +0200225
Tim Abbott123f3e12009-09-16 16:44:30 -0400226 INIT_DATA_SECTION(16)
Sam Ravnborge58bdaa2009-04-29 09:47:25 +0200227
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
Sam Ravnborgae618362009-04-29 09:47:26 +0200234 . = 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
Sam Ravnborgbf6a5742009-04-29 09:47:27 +0200252 /*
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
Jan Beulichc62e4322009-08-25 14:50:53 +0100264#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
Sam Ravnborg9d16e782009-04-29 09:47:28 +0200265 PERCPU(PAGE_SIZE)
266#endif
267
268 . = ALIGN(PAGE_SIZE);
Ingo Molnarfd073192009-04-29 12:56:58 +0200269
Sam Ravnborg9d16e782009-04-29 09:47:28 +0200270 /* freed after init ends here */
Ingo Molnarfd073192009-04-29 12:56:58 +0200271 .init.end : AT(ADDR(.init.end) - LOAD_OFFSET) {
272 __init_end = .;
273 }
Sam Ravnborg9d16e782009-04-29 09:47:28 +0200274
Jan Beulichc62e4322009-08-25 14:50:53 +0100275 /*
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
Sam Ravnborg9d16e782009-04-29 09:47:28 +0200287#ifdef CONFIG_X86_64
288 .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
Jan Beulichc62e4322009-08-25 14:50:53 +0100289 NOSAVE_DATA
290 }
Sam Ravnborg9d16e782009-04-29 09:47:28 +0200291#endif
292
Sam Ravnborg091e52c2009-04-29 09:47:29 +0200293 /* 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 }
Sam Ravnborg9d16e782009-04-29 09:47:28 +0200302
Sam Ravnborg091e52c2009-04-29 09:47:29 +0200303 . = 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
Sam Ravnborg444e0ae2009-04-29 09:47:20 +0200315 STABS_DEBUG
316 DWARF_DEBUG
Tejun Heo023bf6f2009-07-09 11:27:40 +0900317
318 /* Sections to be discarded */
319 DISCARDS
320 /DISCARD/ : { *(.eh_frame) }
Sam Ravnborg444e0ae2009-04-29 09:47:20 +0200321}
322
Sam Ravnborg17ce2652009-04-29 09:47:18 +0200323
324#ifdef CONFIG_X86_32
H. Peter Anvind2ba8b22009-08-03 14:44:54 -0700325. = ASSERT((_end - LOAD_OFFSET <= KERNEL_IMAGE_SIZE),
326 "kernel image bigger than KERNEL_IMAGE_SIZE");
Sam Ravnborg17ce2652009-04-29 09:47:18 +0200327#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
333INIT_PER_CPU(gdt_page);
334INIT_PER_CPU(irq_stack_union);
335
336/*
337 * Build-time check on the image size:
338 */
H. Peter Anvind2ba8b22009-08-03 14:44:54 -0700339. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
340 "kernel image bigger than KERNEL_IMAGE_SIZE");
Sam Ravnborg17ce2652009-04-29 09:47:18 +0200341
342#ifdef CONFIG_SMP
H. Peter Anvind2ba8b22009-08-03 14:44:54 -0700343. = ASSERT((per_cpu__irq_stack_union == 0),
344 "irq_stack_union is not at start of per-cpu area");
Sam Ravnborg17ce2652009-04-29 09:47:18 +0200345#endif
346
347#endif /* CONFIG_X86_32 */
348
349#ifdef CONFIG_KEXEC
350#include <asm/kexec.h>
351
H. Peter Anvind2ba8b22009-08-03 14:44:54 -0700352. = ASSERT(kexec_control_code_size <= KEXEC_CONTROL_CODE_MAX_SIZE,
353 "kexec control code size is too big");
Sam Ravnborg17ce2652009-04-29 09:47:18 +0200354#endif
355