Sam Ravnborg | 17ce265 | 2009-04-29 09:47:18 +0200 | [diff] [blame] | 1 | /* |
| 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 Molnar | 91fd7fe | 2009-04-29 10:58:38 +0200 | [diff] [blame^] | 6 | * Modernisation, unification and other changes and fixes: |
| 7 | * Copyright (C) 2007-2009 Sam Ravnborg <sam@ravnborg.org> |
Sam Ravnborg | 17ce265 | 2009-04-29 09:47:18 +0200 | [diff] [blame] | 8 | * |
| 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 | |
| 32 | OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT, CONFIG_OUTPUT_FORMAT, CONFIG_OUTPUT_FORMAT) |
| 33 | |
| 34 | #ifdef CONFIG_X86_32 |
| 35 | OUTPUT_ARCH(i386) |
| 36 | ENTRY(phys_startup_32) |
| 37 | jiffies = jiffies_64; |
| 38 | #else |
| 39 | OUTPUT_ARCH(i386:x86-64) |
| 40 | ENTRY(phys_startup_64) |
| 41 | jiffies_64 = jiffies; |
| 42 | #endif |
| 43 | |
Sam Ravnborg | afb8095a | 2009-04-29 09:47:19 +0200 | [diff] [blame] | 44 | PHDRS { |
| 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 */ |
| 49 | data.init PT_LOAD FLAGS(7); /* RWE */ |
| 50 | #ifdef CONFIG_SMP |
| 51 | percpu PT_LOAD FLAGS(7); /* RWE */ |
| 52 | #endif |
| 53 | data.init2 PT_LOAD FLAGS(7); /* RWE */ |
| 54 | #endif |
| 55 | note PT_NOTE FLAGS(0); /* ___ */ |
| 56 | } |
Sam Ravnborg | 17ce265 | 2009-04-29 09:47:18 +0200 | [diff] [blame] | 57 | |
Sam Ravnborg | 444e0ae | 2009-04-29 09:47:20 +0200 | [diff] [blame] | 58 | SECTIONS |
| 59 | { |
| 60 | #ifdef CONFIG_X86_32 |
| 61 | . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR; |
| 62 | phys_startup_32 = startup_32 - LOAD_OFFSET; |
| 63 | #else |
| 64 | . = __START_KERNEL; |
| 65 | phys_startup_64 = startup_64 - LOAD_OFFSET; |
| 66 | #endif |
| 67 | |
Sam Ravnborg | dfc20895 | 2009-04-29 09:47:21 +0200 | [diff] [blame] | 68 | /* Text and read-only data */ |
| 69 | |
| 70 | /* bootstrapping code */ |
| 71 | .text.head : AT(ADDR(.text.head) - LOAD_OFFSET) { |
| 72 | _text = .; |
| 73 | *(.text.head) |
| 74 | } :text = 0x9090 |
| 75 | |
| 76 | /* The rest of the text */ |
| 77 | .text : AT(ADDR(.text) - LOAD_OFFSET) { |
| 78 | #ifdef CONFIG_X86_32 |
| 79 | /* not really needed, already page aligned */ |
| 80 | . = ALIGN(PAGE_SIZE); |
| 81 | *(.text.page_aligned) |
| 82 | #endif |
| 83 | . = ALIGN(8); |
| 84 | _stext = .; |
| 85 | TEXT_TEXT |
| 86 | SCHED_TEXT |
| 87 | LOCK_TEXT |
| 88 | KPROBES_TEXT |
| 89 | IRQENTRY_TEXT |
| 90 | *(.fixup) |
| 91 | *(.gnu.warning) |
| 92 | /* End of text section */ |
| 93 | _etext = .; |
| 94 | } :text = 0x9090 |
| 95 | |
| 96 | NOTES :text :note |
| 97 | |
Sam Ravnborg | 448bc3a | 2009-04-29 09:47:22 +0200 | [diff] [blame] | 98 | /* Exception table */ |
| 99 | . = ALIGN(16); |
| 100 | __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { |
| 101 | __start___ex_table = .; |
| 102 | *(__ex_table) |
| 103 | __stop___ex_table = .; |
| 104 | } :text = 0x9090 |
| 105 | |
| 106 | RODATA |
| 107 | |
Sam Ravnborg | 1f6397b | 2009-04-29 09:47:23 +0200 | [diff] [blame] | 108 | /* Data */ |
| 109 | . = ALIGN(PAGE_SIZE); |
| 110 | .data : AT(ADDR(.data) - LOAD_OFFSET) { |
| 111 | DATA_DATA |
| 112 | CONSTRUCTORS |
| 113 | |
| 114 | #ifdef CONFIG_X86_64 |
| 115 | /* End of data section */ |
| 116 | _edata = .; |
| 117 | #endif |
| 118 | } :data |
| 119 | |
| 120 | #ifdef CONFIG_X86_32 |
| 121 | /* 32 bit has nosave before _edata */ |
| 122 | . = ALIGN(PAGE_SIZE); |
| 123 | .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) { |
| 124 | __nosave_begin = .; |
| 125 | *(.data.nosave) |
| 126 | . = ALIGN(PAGE_SIZE); |
| 127 | __nosave_end = .; |
| 128 | } |
| 129 | #endif |
| 130 | |
| 131 | . = ALIGN(PAGE_SIZE); |
| 132 | .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) { |
| 133 | *(.data.page_aligned) |
| 134 | *(.data.idt) |
| 135 | } |
| 136 | |
| 137 | #ifdef CONFIG_X86_32 |
| 138 | . = ALIGN(32); |
| 139 | #else |
| 140 | . = ALIGN(PAGE_SIZE); |
| 141 | . = ALIGN(CONFIG_X86_L1_CACHE_BYTES); |
| 142 | #endif |
| 143 | .data.cacheline_aligned : |
| 144 | AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) { |
| 145 | *(.data.cacheline_aligned) |
| 146 | } |
| 147 | |
| 148 | /* rarely changed data like cpu maps */ |
| 149 | #ifdef CONFIG_X86_32 |
| 150 | . = ALIGN(32); |
| 151 | #else |
| 152 | . = ALIGN(CONFIG_X86_INTERNODE_CACHE_BYTES); |
| 153 | #endif |
| 154 | .data.read_mostly : AT(ADDR(.data.read_mostly) - LOAD_OFFSET) { |
| 155 | *(.data.read_mostly) |
| 156 | |
| 157 | #ifdef CONFIG_X86_32 |
| 158 | /* End of data section */ |
| 159 | _edata = .; |
| 160 | #endif |
| 161 | } |
| 162 | |
Sam Ravnborg | ff6f87e | 2009-04-29 09:47:24 +0200 | [diff] [blame] | 163 | #ifdef CONFIG_X86_64 |
| 164 | |
| 165 | #define VSYSCALL_ADDR (-10*1024*1024) |
| 166 | #define VSYSCALL_PHYS_ADDR ((LOADADDR(.data.read_mostly) + \ |
| 167 | SIZEOF(.data.read_mostly) + 4095) & ~(4095)) |
| 168 | #define VSYSCALL_VIRT_ADDR ((ADDR(.data.read_mostly) + \ |
| 169 | SIZEOF(.data.read_mostly) + 4095) & ~(4095)) |
| 170 | |
| 171 | #define VLOAD_OFFSET (VSYSCALL_ADDR - VSYSCALL_PHYS_ADDR) |
| 172 | #define VLOAD(x) (ADDR(x) - VLOAD_OFFSET) |
| 173 | |
| 174 | #define VVIRT_OFFSET (VSYSCALL_ADDR - VSYSCALL_VIRT_ADDR) |
| 175 | #define VVIRT(x) (ADDR(x) - VVIRT_OFFSET) |
| 176 | |
| 177 | . = VSYSCALL_ADDR; |
| 178 | .vsyscall_0 : AT(VSYSCALL_PHYS_ADDR) { |
| 179 | *(.vsyscall_0) |
| 180 | } :user |
| 181 | |
| 182 | __vsyscall_0 = VSYSCALL_VIRT_ADDR; |
| 183 | |
| 184 | . = ALIGN(CONFIG_X86_L1_CACHE_BYTES); |
| 185 | .vsyscall_fn : AT(VLOAD(.vsyscall_fn)) { |
| 186 | *(.vsyscall_fn) |
| 187 | } |
| 188 | |
| 189 | . = ALIGN(CONFIG_X86_L1_CACHE_BYTES); |
| 190 | .vsyscall_gtod_data : AT(VLOAD(.vsyscall_gtod_data)) { |
| 191 | *(.vsyscall_gtod_data) |
| 192 | } |
| 193 | |
| 194 | vsyscall_gtod_data = VVIRT(.vsyscall_gtod_data); |
| 195 | .vsyscall_clock : AT(VLOAD(.vsyscall_clock)) { |
| 196 | *(.vsyscall_clock) |
| 197 | } |
| 198 | vsyscall_clock = VVIRT(.vsyscall_clock); |
| 199 | |
| 200 | |
| 201 | .vsyscall_1 ADDR(.vsyscall_0) + 1024: AT(VLOAD(.vsyscall_1)) { |
| 202 | *(.vsyscall_1) |
| 203 | } |
| 204 | .vsyscall_2 ADDR(.vsyscall_0) + 2048: AT(VLOAD(.vsyscall_2)) { |
| 205 | *(.vsyscall_2) |
| 206 | } |
| 207 | |
| 208 | .vgetcpu_mode : AT(VLOAD(.vgetcpu_mode)) { |
| 209 | *(.vgetcpu_mode) |
| 210 | } |
| 211 | vgetcpu_mode = VVIRT(.vgetcpu_mode); |
| 212 | |
| 213 | . = ALIGN(CONFIG_X86_L1_CACHE_BYTES); |
| 214 | .jiffies : AT(VLOAD(.jiffies)) { |
| 215 | *(.jiffies) |
| 216 | } |
| 217 | jiffies = VVIRT(.jiffies); |
| 218 | |
| 219 | .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) { |
| 220 | *(.vsyscall_3) |
| 221 | } |
| 222 | |
| 223 | . = VSYSCALL_VIRT_ADDR + PAGE_SIZE; |
| 224 | |
| 225 | #undef VSYSCALL_ADDR |
| 226 | #undef VSYSCALL_PHYS_ADDR |
| 227 | #undef VSYSCALL_VIRT_ADDR |
| 228 | #undef VLOAD_OFFSET |
| 229 | #undef VLOAD |
| 230 | #undef VVIRT_OFFSET |
| 231 | #undef VVIRT |
| 232 | |
| 233 | #endif /* CONFIG_X86_64 */ |
Sam Ravnborg | dfc20895 | 2009-04-29 09:47:21 +0200 | [diff] [blame] | 234 | |
Sam Ravnborg | e58bdaa | 2009-04-29 09:47:25 +0200 | [diff] [blame] | 235 | /* init_task */ |
| 236 | . = ALIGN(THREAD_SIZE); |
| 237 | .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) { |
| 238 | *(.data.init_task) |
| 239 | } |
| 240 | #ifdef CONFIG_X86_64 |
| 241 | :data.init |
| 242 | #endif |
| 243 | |
| 244 | /* |
| 245 | * smp_locks might be freed after init |
| 246 | * start/end must be page aligned |
| 247 | */ |
| 248 | . = ALIGN(PAGE_SIZE); |
| 249 | .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) { |
| 250 | __smp_locks = .; |
| 251 | *(.smp_locks) |
| 252 | __smp_locks_end = .; |
| 253 | . = ALIGN(PAGE_SIZE); |
| 254 | } |
| 255 | |
| 256 | /* Init code and data - will be freed after init */ |
| 257 | . = ALIGN(PAGE_SIZE); |
| 258 | __init_begin = .; /* paired with __init_end */ |
| 259 | .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) { |
| 260 | _sinittext = .; |
| 261 | INIT_TEXT |
| 262 | _einittext = .; |
| 263 | } |
| 264 | |
| 265 | .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) { |
| 266 | INIT_DATA |
| 267 | } |
| 268 | |
| 269 | . = ALIGN(16); |
| 270 | .init.setup : AT(ADDR(.init.setup) - LOAD_OFFSET) { |
| 271 | __setup_start = .; |
| 272 | *(.init.setup) |
| 273 | __setup_end = .; |
| 274 | } |
| 275 | .initcall.init : AT(ADDR(.initcall.init) - LOAD_OFFSET) { |
| 276 | __initcall_start = .; |
| 277 | INITCALLS |
| 278 | __initcall_end = .; |
| 279 | } |
| 280 | |
| 281 | .con_initcall.init : AT(ADDR(.con_initcall.init) - LOAD_OFFSET) { |
| 282 | __con_initcall_start = .; |
| 283 | *(.con_initcall.init) |
| 284 | __con_initcall_end = .; |
| 285 | } |
| 286 | |
| 287 | .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) { |
| 288 | __x86_cpu_dev_start = .; |
| 289 | *(.x86_cpu_dev.init) |
| 290 | __x86_cpu_dev_end = .; |
| 291 | } |
| 292 | |
| 293 | SECURITY_INIT |
| 294 | |
Sam Ravnborg | ae61836 | 2009-04-29 09:47:26 +0200 | [diff] [blame] | 295 | . = ALIGN(8); |
| 296 | .parainstructions : AT(ADDR(.parainstructions) - LOAD_OFFSET) { |
| 297 | __parainstructions = .; |
| 298 | *(.parainstructions) |
| 299 | __parainstructions_end = .; |
| 300 | } |
| 301 | |
| 302 | . = ALIGN(8); |
| 303 | .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) { |
| 304 | __alt_instructions = .; |
| 305 | *(.altinstructions) |
| 306 | __alt_instructions_end = .; |
| 307 | } |
| 308 | |
| 309 | .altinstr_replacement : AT(ADDR(.altinstr_replacement) - LOAD_OFFSET) { |
| 310 | *(.altinstr_replacement) |
| 311 | } |
| 312 | |
Sam Ravnborg | bf6a574 | 2009-04-29 09:47:27 +0200 | [diff] [blame] | 313 | /* |
| 314 | * .exit.text is discard at runtime, not link time, to deal with |
| 315 | * references from .altinstructions and .eh_frame |
| 316 | */ |
| 317 | .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) { |
| 318 | EXIT_TEXT |
| 319 | } |
| 320 | |
| 321 | .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) { |
| 322 | EXIT_DATA |
| 323 | } |
| 324 | |
| 325 | #ifdef CONFIG_BLK_DEV_INITRD |
| 326 | . = ALIGN(PAGE_SIZE); |
| 327 | .init.ramfs : AT(ADDR(.init.ramfs) - LOAD_OFFSET) { |
| 328 | __initramfs_start = .; |
| 329 | *(.init.ramfs) |
| 330 | __initramfs_end = .; |
| 331 | } |
| 332 | #endif |
Sam Ravnborg | e58bdaa | 2009-04-29 09:47:25 +0200 | [diff] [blame] | 333 | |
Sam Ravnborg | 9d16e78 | 2009-04-29 09:47:28 +0200 | [diff] [blame] | 334 | #if defined(CONFIG_X86_64) && defined(CONFIG_SMP) |
| 335 | /* |
| 336 | * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the |
| 337 | * output PHDR, so the next output section - __data_nosave - should |
| 338 | * start another section data.init2. Also, pda should be at the head of |
| 339 | * percpu area. Preallocate it and define the percpu offset symbol |
| 340 | * so that it can be accessed as a percpu variable. |
| 341 | */ |
| 342 | . = ALIGN(PAGE_SIZE); |
| 343 | PERCPU_VADDR(0, :percpu) |
| 344 | #else |
| 345 | PERCPU(PAGE_SIZE) |
| 346 | #endif |
| 347 | |
| 348 | . = ALIGN(PAGE_SIZE); |
| 349 | /* freed after init ends here */ |
| 350 | __init_end = .; |
| 351 | |
| 352 | #ifdef CONFIG_X86_64 |
| 353 | .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) { |
| 354 | . = ALIGN(PAGE_SIZE); |
| 355 | __nosave_begin = .; |
| 356 | *(.data.nosave) |
| 357 | . = ALIGN(PAGE_SIZE); |
| 358 | __nosave_end = .; |
| 359 | } :data.init2 |
| 360 | /* use another section data.init2, see PERCPU_VADDR() above */ |
| 361 | #endif |
| 362 | |
Sam Ravnborg | 091e52c | 2009-04-29 09:47:29 +0200 | [diff] [blame] | 363 | /* BSS */ |
| 364 | . = ALIGN(PAGE_SIZE); |
| 365 | .bss : AT(ADDR(.bss) - LOAD_OFFSET) { |
| 366 | __bss_start = .; |
| 367 | *(.bss.page_aligned) |
| 368 | *(.bss) |
| 369 | . = ALIGN(4); |
| 370 | __bss_stop = .; |
| 371 | } |
Sam Ravnborg | 9d16e78 | 2009-04-29 09:47:28 +0200 | [diff] [blame] | 372 | |
Sam Ravnborg | 091e52c | 2009-04-29 09:47:29 +0200 | [diff] [blame] | 373 | . = ALIGN(PAGE_SIZE); |
| 374 | .brk : AT(ADDR(.brk) - LOAD_OFFSET) { |
| 375 | __brk_base = .; |
| 376 | . += 64 * 1024; /* 64k alignment slop space */ |
| 377 | *(.brk_reservation) /* areas brk users have reserved */ |
| 378 | __brk_limit = .; |
| 379 | } |
| 380 | |
| 381 | .end : AT(ADDR(.end) - LOAD_OFFSET) { |
| 382 | _end = .; |
| 383 | } |
| 384 | |
| 385 | /* Sections to be discarded */ |
| 386 | /DISCARD/ : { |
| 387 | *(.exitcall.exit) |
| 388 | *(.eh_frame) |
| 389 | *(.discard) |
| 390 | } |
Sam Ravnborg | 17ce265 | 2009-04-29 09:47:18 +0200 | [diff] [blame] | 391 | |
Sam Ravnborg | 444e0ae | 2009-04-29 09:47:20 +0200 | [diff] [blame] | 392 | STABS_DEBUG |
| 393 | DWARF_DEBUG |
| 394 | } |
| 395 | |
Sam Ravnborg | 17ce265 | 2009-04-29 09:47:18 +0200 | [diff] [blame] | 396 | |
| 397 | #ifdef CONFIG_X86_32 |
| 398 | ASSERT((_end - LOAD_OFFSET <= KERNEL_IMAGE_SIZE), |
| 399 | "kernel image bigger than KERNEL_IMAGE_SIZE") |
| 400 | #else |
| 401 | /* |
| 402 | * Per-cpu symbols which need to be offset from __per_cpu_load |
| 403 | * for the boot processor. |
| 404 | */ |
| 405 | #define INIT_PER_CPU(x) init_per_cpu__##x = per_cpu__##x + __per_cpu_load |
| 406 | INIT_PER_CPU(gdt_page); |
| 407 | INIT_PER_CPU(irq_stack_union); |
| 408 | |
| 409 | /* |
| 410 | * Build-time check on the image size: |
| 411 | */ |
| 412 | ASSERT((_end - _text <= KERNEL_IMAGE_SIZE), |
| 413 | "kernel image bigger than KERNEL_IMAGE_SIZE") |
| 414 | |
| 415 | #ifdef CONFIG_SMP |
| 416 | ASSERT((per_cpu__irq_stack_union == 0), |
| 417 | "irq_stack_union is not at start of per-cpu area"); |
| 418 | #endif |
| 419 | |
| 420 | #endif /* CONFIG_X86_32 */ |
| 421 | |
| 422 | #ifdef CONFIG_KEXEC |
| 423 | #include <asm/kexec.h> |
| 424 | |
| 425 | ASSERT(kexec_control_code_size <= KEXEC_CONTROL_CODE_MAX_SIZE, |
| 426 | "kexec control code size is too big") |
| 427 | #endif |
| 428 | |