blob: c9740996430ab9ac9b448e3003f80cccc124d3d0 [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>
Thomas Gleixner13a9cd42007-10-11 11:14:21 +02009#include <asm/page.h>
10
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
Jan Beulich6360b1f2008-05-12 15:44:41 +020025 note PT_NOTE FLAGS(0); /* ___ */
Thomas Gleixner13a9cd42007-10-11 11:14:21 +020026}
27SECTIONS
28{
29 . = __START_KERNEL;
30 phys_startup_64 = startup_64 - LOAD_OFFSET;
31 _text = .; /* Text and read-only data */
32 .text : AT(ADDR(.text) - LOAD_OFFSET) {
33 /* First the code that has to be first for bootstrapping */
34 *(.text.head)
35 _stext = .;
36 /* Then the rest */
37 TEXT_TEXT
38 SCHED_TEXT
39 LOCK_TEXT
40 KPROBES_TEXT
Frederic Weisbeckera0343e82008-12-09 23:53:16 +010041 IRQENTRY_TEXT
Thomas Gleixner13a9cd42007-10-11 11:14:21 +020042 *(.fixup)
43 *(.gnu.warning)
Cyrill Gorcunov3cdac412008-02-17 18:17:17 +030044 _etext = .; /* End of text section */
Jan Beulichc0400032008-01-30 13:33:14 +010045 } :text = 0x9090
Thomas Gleixner13a9cd42007-10-11 11:14:21 +020046
Jan Beulich6360b1f2008-05-12 15:44:41 +020047 NOTES :text :note
48
Thomas Gleixner13a9cd42007-10-11 11:14:21 +020049 . = ALIGN(16); /* Exception table */
Jan Beulichc0400032008-01-30 13:33:14 +010050 __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
51 __start___ex_table = .;
52 *(__ex_table)
53 __stop___ex_table = .;
Jan Beulich6360b1f2008-05-12 15:44:41 +020054 } :text = 0x9090
Thomas Gleixner13a9cd42007-10-11 11:14:21 +020055
56 RODATA
57
Cyrill Gorcunov3cdac412008-02-17 18:17:17 +030058 . = ALIGN(PAGE_SIZE); /* Align data segment to page size boundary */
Thomas Gleixner13a9cd42007-10-11 11:14:21 +020059 /* Data */
60 .data : AT(ADDR(.data) - LOAD_OFFSET) {
61 DATA_DATA
62 CONSTRUCTORS
63 } :data
64
65 _edata = .; /* End of data section */
66
67 . = ALIGN(PAGE_SIZE);
68 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
69 .data.cacheline_aligned : AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) {
70 *(.data.cacheline_aligned)
71 }
72 . = ALIGN(CONFIG_X86_INTERNODE_CACHE_BYTES);
73 .data.read_mostly : AT(ADDR(.data.read_mostly) - LOAD_OFFSET) {
74 *(.data.read_mostly)
75 }
76
77#define VSYSCALL_ADDR (-10*1024*1024)
78#define VSYSCALL_PHYS_ADDR ((LOADADDR(.data.read_mostly) + SIZEOF(.data.read_mostly) + 4095) & ~(4095))
79#define VSYSCALL_VIRT_ADDR ((ADDR(.data.read_mostly) + SIZEOF(.data.read_mostly) + 4095) & ~(4095))
80
81#define VLOAD_OFFSET (VSYSCALL_ADDR - VSYSCALL_PHYS_ADDR)
82#define VLOAD(x) (ADDR(x) - VLOAD_OFFSET)
83
84#define VVIRT_OFFSET (VSYSCALL_ADDR - VSYSCALL_VIRT_ADDR)
85#define VVIRT(x) (ADDR(x) - VVIRT_OFFSET)
86
87 . = VSYSCALL_ADDR;
88 .vsyscall_0 : AT(VSYSCALL_PHYS_ADDR) { *(.vsyscall_0) } :user
89 __vsyscall_0 = VSYSCALL_VIRT_ADDR;
90
91 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
92 .vsyscall_fn : AT(VLOAD(.vsyscall_fn)) { *(.vsyscall_fn) }
93 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
94 .vsyscall_gtod_data : AT(VLOAD(.vsyscall_gtod_data))
95 { *(.vsyscall_gtod_data) }
96 vsyscall_gtod_data = VVIRT(.vsyscall_gtod_data);
97 .vsyscall_clock : AT(VLOAD(.vsyscall_clock))
98 { *(.vsyscall_clock) }
99 vsyscall_clock = VVIRT(.vsyscall_clock);
100
101
102 .vsyscall_1 ADDR(.vsyscall_0) + 1024: AT(VLOAD(.vsyscall_1))
103 { *(.vsyscall_1) }
104 .vsyscall_2 ADDR(.vsyscall_0) + 2048: AT(VLOAD(.vsyscall_2))
105 { *(.vsyscall_2) }
106
107 .vgetcpu_mode : AT(VLOAD(.vgetcpu_mode)) { *(.vgetcpu_mode) }
108 vgetcpu_mode = VVIRT(.vgetcpu_mode);
109
110 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
111 .jiffies : AT(VLOAD(.jiffies)) { *(.jiffies) }
112 jiffies = VVIRT(.jiffies);
113
114 .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3))
115 { *(.vsyscall_3) }
116
Cyrill Gorcunov3cdac412008-02-17 18:17:17 +0300117 . = VSYSCALL_VIRT_ADDR + PAGE_SIZE;
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200118
119#undef VSYSCALL_ADDR
120#undef VSYSCALL_PHYS_ADDR
121#undef VSYSCALL_VIRT_ADDR
122#undef VLOAD_OFFSET
123#undef VLOAD
124#undef VVIRT_OFFSET
125#undef VVIRT
126
Cyrill Gorcunov85c42d02008-02-17 18:17:18 +0300127 . = ALIGN(THREAD_SIZE); /* init_task */
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200128 .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
129 *(.data.init_task)
130 }:data.init
131
Cyrill Gorcunov3cdac412008-02-17 18:17:17 +0300132 . = ALIGN(PAGE_SIZE);
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200133 .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
134 *(.data.page_aligned)
135 }
136
137 /* might get freed after init */
Cyrill Gorcunov3cdac412008-02-17 18:17:17 +0300138 . = ALIGN(PAGE_SIZE);
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200139 __smp_alt_begin = .;
140 __smp_locks = .;
141 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
142 *(.smp_locks)
143 }
144 __smp_locks_end = .;
Cyrill Gorcunov3cdac412008-02-17 18:17:17 +0300145 . = ALIGN(PAGE_SIZE);
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200146 __smp_alt_end = .;
147
Cyrill Gorcunov3cdac412008-02-17 18:17:17 +0300148 . = ALIGN(PAGE_SIZE); /* Init code and data */
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200149 __init_begin = .;
150 .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {
151 _sinittext = .;
Sam Ravnborg01ba2bd2008-01-20 14:15:03 +0100152 INIT_TEXT
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200153 _einittext = .;
154 }
Sam Ravnborg01ba2bd2008-01-20 14:15:03 +0100155 .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
156 __initdata_begin = .;
157 INIT_DATA
158 __initdata_end = .;
159 }
160
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200161 . = ALIGN(16);
162 __setup_start = .;
163 .init.setup : AT(ADDR(.init.setup) - LOAD_OFFSET) { *(.init.setup) }
164 __setup_end = .;
165 __initcall_start = .;
166 .initcall.init : AT(ADDR(.initcall.init) - LOAD_OFFSET) {
167 INITCALLS
168 }
169 __initcall_end = .;
170 __con_initcall_start = .;
171 .con_initcall.init : AT(ADDR(.con_initcall.init) - LOAD_OFFSET) {
172 *(.con_initcall.init)
173 }
174 __con_initcall_end = .;
Yinghai Lu10a434f2008-09-04 21:09:45 +0200175 __x86_cpu_dev_start = .;
176 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
177 *(.x86_cpu_dev.init)
Thomas Petazzoni03ae5762008-02-15 12:00:23 +0100178 }
Yinghai Lu10a434f2008-09-04 21:09:45 +0200179 __x86_cpu_dev_end = .;
Petr Vandroveccb58ffc2008-10-12 10:51:03 +0200180 SECURITY_INIT
Glauber de Oliveira Costafbf51922008-01-30 13:33:19 +0100181
182 . = ALIGN(8);
183 .parainstructions : AT(ADDR(.parainstructions) - LOAD_OFFSET) {
184 __parainstructions = .;
185 *(.parainstructions)
186 __parainstructions_end = .;
187 }
188
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200189 . = ALIGN(8);
190 __alt_instructions = .;
191 .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) {
192 *(.altinstructions)
193 }
Cyrill Gorcunov3cdac412008-02-17 18:17:17 +0300194 __alt_instructions_end = .;
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200195 .altinstr_replacement : AT(ADDR(.altinstr_replacement) - LOAD_OFFSET) {
196 *(.altinstr_replacement)
197 }
198 /* .exit.text is discard at runtime, not link time, to deal with references
199 from .altinstructions and .eh_frame */
Sam Ravnborg01ba2bd2008-01-20 14:15:03 +0100200 .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
201 EXIT_TEXT
202 }
203 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
204 EXIT_DATA
205 }
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200206
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200207#ifdef CONFIG_BLK_DEV_INITRD
Cyrill Gorcunov3cdac412008-02-17 18:17:17 +0300208 . = ALIGN(PAGE_SIZE);
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200209 __initramfs_start = .;
210 .init.ramfs : AT(ADDR(.init.ramfs) - LOAD_OFFSET) { *(.init.ramfs) }
211 __initramfs_end = .;
212#endif
213
Tejun Heo3e5d8f92009-01-13 20:41:35 +0900214#ifdef CONFIG_SMP
215 /*
216 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
217 * output PHDR, so the next output section - __data_nosave - should
Tejun Heo1a51e3a2009-01-13 20:41:35 +0900218 * switch it back to data.init. Also, pda should be at the head of
Tejun Heob12d8db2009-01-13 20:41:35 +0900219 * percpu area. Preallocate it and define the percpu offset symbol
220 * so that it can be accessed as a percpu variable.
Tejun Heo3e5d8f92009-01-13 20:41:35 +0900221 */
222 . = ALIGN(PAGE_SIZE);
Brian Gerst947e76c2009-01-19 12:21:28 +0900223 PERCPU_VADDR(0, :percpu)
Tejun Heo3e5d8f92009-01-13 20:41:35 +0900224#else
Cyrill Gorcunov3cdac412008-02-17 18:17:17 +0300225 PERCPU(PAGE_SIZE)
Tejun Heo3e5d8f92009-01-13 20:41:35 +0900226#endif
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200227
Cyrill Gorcunov3cdac412008-02-17 18:17:17 +0300228 . = ALIGN(PAGE_SIZE);
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200229 __init_end = .;
230
Cyrill Gorcunov3cdac412008-02-17 18:17:17 +0300231 . = ALIGN(PAGE_SIZE);
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200232 __nosave_begin = .;
Tejun Heo3e5d8f92009-01-13 20:41:35 +0900233 .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
234 *(.data.nosave)
235 } :data.init /* switch back to data.init, see PERCPU_VADDR() above */
Cyrill Gorcunov3cdac412008-02-17 18:17:17 +0300236 . = ALIGN(PAGE_SIZE);
Thomas Gleixner13a9cd42007-10-11 11:14:21 +0200237 __nosave_end = .;
238
239 __bss_start = .; /* BSS */
240 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
241 *(.bss.page_aligned)
242 *(.bss)
243 }
244 __bss_stop = .;
245
246 _end = . ;
247
248 /* Sections to be discarded */
249 /DISCARD/ : {
250 *(.exitcall.exit)
251 *(.eh_frame)
252 }
253
254 STABS_DEBUG
255
256 DWARF_DEBUG
257}
Ingo Molnarb4e04092008-02-21 13:45:16 +0100258
259/*
260 * Build-time check on the image size:
261 */
262ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
263 "kernel image bigger than KERNEL_IMAGE_SIZE")
Brian Gerst947e76c2009-01-19 12:21:28 +0900264
265#ifdef CONFIG_SMP
266ASSERT((per_cpu__irq_stack_union == 0),
267 "irq_stack_union is not at start of per-cpu area");
268#endif