1 /* 2 * Helper macros to support writing architecture specific 3 * linker scripts. 4 * 5 * A minimal linker scripts has following content: 6 * [This is a sample, architectures may have special requiriements] 7 * 8 * OUTPUT_FORMAT(...) 9 * OUTPUT_ARCH(...) 10 * ENTRY(...) 11 * SECTIONS 12 * { 13 * . = START; 14 * __init_begin = .; 15 * HEAD_TEXT_SECTION 16 * INIT_TEXT_SECTION(PAGE_SIZE) 17 * INIT_DATA_SECTION(...) 18 * PERCPU_SECTION(CACHELINE_SIZE) 19 * __init_end = .; 20 * 21 * _stext = .; 22 * TEXT_SECTION = 0 23 * _etext = .; 24 * 25 * _sdata = .; 26 * RO_DATA_SECTION(PAGE_SIZE) 27 * RW_DATA_SECTION(...) 28 * _edata = .; 29 * 30 * EXCEPTION_TABLE(...) 31 * NOTES 32 * 33 * BSS_SECTION(0, 0, 0) 34 * _end = .; 35 * 36 * STABS_DEBUG 37 * DWARF_DEBUG 38 * 39 * DISCARDS // must be the last 40 * } 41 * 42 * [__init_begin, __init_end] is the init section that may be freed after init 43 * // __init_begin and __init_end should be page aligned, so that we can 44 * // free the whole .init memory 45 * [_stext, _etext] is the text section 46 * [_sdata, _edata] is the data section 47 * 48 * Some of the included output section have their own set of constants. 49 * Examples are: [__initramfs_start, __initramfs_end] for initramfs and 50 * [__nosave_begin, __nosave_end] for the nosave data 51 */ 52 53 #ifndef LOAD_OFFSET 54 #define LOAD_OFFSET 0 55 #endif 56 57 #include <linux/export.h> 58 59 /* Align . to a 8 byte boundary equals to maximum function alignment. */ 60 #define ALIGN_FUNCTION() . = ALIGN(8) 61 62 /* 63 * LD_DEAD_CODE_DATA_ELIMINATION option enables -fdata-sections, which 64 * generates .data.identifier sections, which need to be pulled in with 65 * .data. We don't want to pull in .data..other sections, which Linux 66 * has defined. Same for text and bss. 67 */ 68 #ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION 69 #define TEXT_MAIN .text .text.[0-9a-zA-Z_]* 70 #define TEXT_CFI_MAIN .text.cfi .text.[0-9a-zA-Z_]*.cfi 71 #define DATA_MAIN .data .data.[0-9a-zA-Z_]* 72 #define BSS_MAIN .bss .bss.[0-9a-zA-Z_]* 73 #else 74 #define TEXT_MAIN .text 75 #define TEXT_CFI_MAIN .text.cfi 76 #define DATA_MAIN .data 77 #define BSS_MAIN .bss 78 #endif 79 80 /* 81 * Align to a 32 byte boundary equal to the 82 * alignment gcc 4.5 uses for a struct 83 */ 84 #define STRUCT_ALIGNMENT 32 85 #define STRUCT_ALIGN() . = ALIGN(STRUCT_ALIGNMENT) 86 87 /* The actual configuration determine if the init/exit sections 88 * are handled as text/data or they can be discarded (which 89 * often happens at runtime) 90 */ 91 #ifdef CONFIG_HOTPLUG_CPU 92 #define CPU_KEEP(sec) *(.cpu##sec) 93 #define CPU_DISCARD(sec) 94 #else 95 #define CPU_KEEP(sec) 96 #define CPU_DISCARD(sec) *(.cpu##sec) 97 #endif 98 99 #if defined(CONFIG_MEMORY_HOTPLUG) 100 #define MEM_KEEP(sec) *(.mem##sec) 101 #define MEM_DISCARD(sec) 102 #else 103 #define MEM_KEEP(sec) 104 #define MEM_DISCARD(sec) *(.mem##sec) 105 #endif 106 107 #ifdef CONFIG_FTRACE_MCOUNT_RECORD 108 #define MCOUNT_REC() . = ALIGN(8); \ 109 VMLINUX_SYMBOL(__start_mcount_loc) = .; \ 110 KEEP(*(__mcount_loc)) \ 111 VMLINUX_SYMBOL(__stop_mcount_loc) = .; 112 #else 113 #define MCOUNT_REC() 114 #endif 115 116 #ifdef CONFIG_TRACE_BRANCH_PROFILING 117 #define LIKELY_PROFILE() VMLINUX_SYMBOL(__start_annotated_branch_profile) = .; \ 118 *(_ftrace_annotated_branch) \ 119 VMLINUX_SYMBOL(__stop_annotated_branch_profile) = .; 120 #else 121 #define LIKELY_PROFILE() 122 #endif 123 124 #ifdef CONFIG_PROFILE_ALL_BRANCHES 125 #define BRANCH_PROFILE() VMLINUX_SYMBOL(__start_branch_profile) = .; \ 126 *(_ftrace_branch) \ 127 VMLINUX_SYMBOL(__stop_branch_profile) = .; 128 #else 129 #define BRANCH_PROFILE() 130 #endif 131 132 #ifdef CONFIG_KPROBES 133 #define KPROBE_BLACKLIST() . = ALIGN(8); \ 134 VMLINUX_SYMBOL(__start_kprobe_blacklist) = .; \ 135 KEEP(*(_kprobe_blacklist)) \ 136 VMLINUX_SYMBOL(__stop_kprobe_blacklist) = .; 137 #else 138 #define KPROBE_BLACKLIST() 139 #endif 140 141 #ifdef CONFIG_EVENT_TRACING 142 #define FTRACE_EVENTS() . = ALIGN(8); \ 143 VMLINUX_SYMBOL(__start_ftrace_events) = .; \ 144 KEEP(*(_ftrace_events)) \ 145 VMLINUX_SYMBOL(__stop_ftrace_events) = .; \ 146 VMLINUX_SYMBOL(__start_ftrace_eval_maps) = .; \ 147 KEEP(*(_ftrace_eval_map)) \ 148 VMLINUX_SYMBOL(__stop_ftrace_eval_maps) = .; 149 #else 150 #define FTRACE_EVENTS() 151 #endif 152 153 #ifdef CONFIG_TRACING 154 #define TRACE_PRINTKS() VMLINUX_SYMBOL(__start___trace_bprintk_fmt) = .; \ 155 KEEP(*(__trace_printk_fmt)) /* Trace_printk fmt' pointer */ \ 156 VMLINUX_SYMBOL(__stop___trace_bprintk_fmt) = .; 157 #define TRACEPOINT_STR() VMLINUX_SYMBOL(__start___tracepoint_str) = .; \ 158 KEEP(*(__tracepoint_str)) /* Trace_printk fmt' pointer */ \ 159 VMLINUX_SYMBOL(__stop___tracepoint_str) = .; 160 #else 161 #define TRACE_PRINTKS() 162 #define TRACEPOINT_STR() 163 #endif 164 165 #ifdef CONFIG_FTRACE_SYSCALLS 166 #define TRACE_SYSCALLS() . = ALIGN(8); \ 167 VMLINUX_SYMBOL(__start_syscalls_metadata) = .; \ 168 KEEP(*(__syscalls_metadata)) \ 169 VMLINUX_SYMBOL(__stop_syscalls_metadata) = .; 170 #else 171 #define TRACE_SYSCALLS() 172 #endif 173 174 #ifdef CONFIG_SERIAL_EARLYCON 175 #define EARLYCON_TABLE() . = ALIGN(8); \ 176 VMLINUX_SYMBOL(__earlycon_table) = .; \ 177 KEEP(*(__earlycon_table)) \ 178 VMLINUX_SYMBOL(__earlycon_table_end) = .; 179 #else 180 #define EARLYCON_TABLE() 181 #endif 182 183 #define ___OF_TABLE(cfg, name) _OF_TABLE_##cfg(name) 184 #define __OF_TABLE(cfg, name) ___OF_TABLE(cfg, name) 185 #define OF_TABLE(cfg, name) __OF_TABLE(IS_ENABLED(cfg), name) 186 #define _OF_TABLE_0(name) 187 #define _OF_TABLE_1(name) \ 188 . = ALIGN(8); \ 189 VMLINUX_SYMBOL(__##name##_of_table) = .; \ 190 KEEP(*(__##name##_of_table)) \ 191 KEEP(*(__##name##_of_table_end)) 192 193 #define TIMER_OF_TABLES() OF_TABLE(CONFIG_TIMER_OF, timer) 194 #define IRQCHIP_OF_MATCH_TABLE() OF_TABLE(CONFIG_IRQCHIP, irqchip) 195 #define CLK_OF_TABLES() OF_TABLE(CONFIG_COMMON_CLK, clk) 196 #define IOMMU_OF_TABLES() OF_TABLE(CONFIG_OF_IOMMU, iommu) 197 #define RESERVEDMEM_OF_TABLES() OF_TABLE(CONFIG_OF_RESERVED_MEM, reservedmem) 198 #define CPU_METHOD_OF_TABLES() OF_TABLE(CONFIG_SMP, cpu_method) 199 #define CPUIDLE_METHOD_OF_TABLES() OF_TABLE(CONFIG_CPU_IDLE, cpuidle_method) 200 201 #ifdef CONFIG_ACPI 202 #define ACPI_PROBE_TABLE(name) \ 203 . = ALIGN(8); \ 204 VMLINUX_SYMBOL(__##name##_acpi_probe_table) = .; \ 205 KEEP(*(__##name##_acpi_probe_table)) \ 206 VMLINUX_SYMBOL(__##name##_acpi_probe_table_end) = .; 207 #else 208 #define ACPI_PROBE_TABLE(name) 209 #endif 210 211 #define KERNEL_DTB() \ 212 STRUCT_ALIGN(); \ 213 VMLINUX_SYMBOL(__dtb_start) = .; \ 214 KEEP(*(.dtb.init.rodata)) \ 215 VMLINUX_SYMBOL(__dtb_end) = .; 216 217 /* 218 * .data section 219 */ 220 #define DATA_DATA \ 221 *(.xiptext) \ 222 *(DATA_MAIN) \ 223 *(.ref.data) \ 224 *(.data..shared_aligned) /* percpu related */ \ 225 MEM_KEEP(init.data) \ 226 MEM_KEEP(exit.data) \ 227 *(.data.unlikely) \ 228 STRUCT_ALIGN(); \ 229 *(__tracepoints) \ 230 /* implement dynamic printk debug */ \ 231 . = ALIGN(8); \ 232 VMLINUX_SYMBOL(__start___jump_table) = .; \ 233 KEEP(*(__jump_table)) \ 234 VMLINUX_SYMBOL(__stop___jump_table) = .; \ 235 . = ALIGN(8); \ 236 VMLINUX_SYMBOL(__start___verbose) = .; \ 237 KEEP(*(__verbose)) \ 238 VMLINUX_SYMBOL(__stop___verbose) = .; \ 239 LIKELY_PROFILE() \ 240 BRANCH_PROFILE() \ 241 TRACE_PRINTKS() \ 242 TRACEPOINT_STR() 243 244 /* 245 * Data section helpers 246 */ 247 #define NOSAVE_DATA \ 248 . = ALIGN(PAGE_SIZE); \ 249 VMLINUX_SYMBOL(__nosave_begin) = .; \ 250 *(.data..nosave) \ 251 . = ALIGN(PAGE_SIZE); \ 252 VMLINUX_SYMBOL(__nosave_end) = .; 253 254 #define PAGE_ALIGNED_DATA(page_align) \ 255 . = ALIGN(page_align); \ 256 *(.data..page_aligned) 257 258 #define READ_MOSTLY_DATA(align) \ 259 . = ALIGN(align); \ 260 *(.data..read_mostly) \ 261 . = ALIGN(align); 262 263 #define CACHELINE_ALIGNED_DATA(align) \ 264 . = ALIGN(align); \ 265 *(.data..cacheline_aligned) 266 267 #define INIT_TASK_DATA(align) \ 268 . = ALIGN(align); \ 269 VMLINUX_SYMBOL(__start_init_task) = .; \ 270 *(.data..init_task) \ 271 VMLINUX_SYMBOL(__end_init_task) = .; 272 273 /* 274 * Allow architectures to handle ro_after_init data on their 275 * own by defining an empty RO_AFTER_INIT_DATA. 276 */ 277 #ifndef RO_AFTER_INIT_DATA 278 #define RO_AFTER_INIT_DATA \ 279 VMLINUX_SYMBOL(__start_ro_after_init) = .; \ 280 *(.data..ro_after_init) \ 281 VMLINUX_SYMBOL(__end_ro_after_init) = .; 282 #endif 283 284 /* 285 * Read only Data 286 */ 287 #define RO_DATA_SECTION(align) \ 288 . = ALIGN((align)); \ 289 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \ 290 VMLINUX_SYMBOL(__start_rodata) = .; \ 291 *(.rodata) *(.rodata.*) \ 292 RO_AFTER_INIT_DATA /* Read only after init */ \ 293 KEEP(*(__vermagic)) /* Kernel version magic */ \ 294 . = ALIGN(8); \ 295 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \ 296 KEEP(*(__tracepoints_ptrs)) /* Tracepoints: pointer array */ \ 297 VMLINUX_SYMBOL(__stop___tracepoints_ptrs) = .; \ 298 *(__tracepoints_strings)/* Tracepoints: strings */ \ 299 } \ 300 \ 301 .rodata1 : AT(ADDR(.rodata1) - LOAD_OFFSET) { \ 302 *(.rodata1) \ 303 } \ 304 \ 305 /* PCI quirks */ \ 306 .pci_fixup : AT(ADDR(.pci_fixup) - LOAD_OFFSET) { \ 307 VMLINUX_SYMBOL(__start_pci_fixups_early) = .; \ 308 KEEP(*(.pci_fixup_early)) \ 309 VMLINUX_SYMBOL(__end_pci_fixups_early) = .; \ 310 VMLINUX_SYMBOL(__start_pci_fixups_header) = .; \ 311 KEEP(*(.pci_fixup_header)) \ 312 VMLINUX_SYMBOL(__end_pci_fixups_header) = .; \ 313 VMLINUX_SYMBOL(__start_pci_fixups_final) = .; \ 314 KEEP(*(.pci_fixup_final)) \ 315 VMLINUX_SYMBOL(__end_pci_fixups_final) = .; \ 316 VMLINUX_SYMBOL(__start_pci_fixups_enable) = .; \ 317 KEEP(*(.pci_fixup_enable)) \ 318 VMLINUX_SYMBOL(__end_pci_fixups_enable) = .; \ 319 VMLINUX_SYMBOL(__start_pci_fixups_resume) = .; \ 320 KEEP(*(.pci_fixup_resume)) \ 321 VMLINUX_SYMBOL(__end_pci_fixups_resume) = .; \ 322 VMLINUX_SYMBOL(__start_pci_fixups_resume_early) = .; \ 323 KEEP(*(.pci_fixup_resume_early)) \ 324 VMLINUX_SYMBOL(__end_pci_fixups_resume_early) = .; \ 325 VMLINUX_SYMBOL(__start_pci_fixups_suspend) = .; \ 326 KEEP(*(.pci_fixup_suspend)) \ 327 VMLINUX_SYMBOL(__end_pci_fixups_suspend) = .; \ 328 VMLINUX_SYMBOL(__start_pci_fixups_suspend_late) = .; \ 329 KEEP(*(.pci_fixup_suspend_late)) \ 330 VMLINUX_SYMBOL(__end_pci_fixups_suspend_late) = .; \ 331 } \ 332 \ 333 /* Built-in firmware blobs */ \ 334 .builtin_fw : AT(ADDR(.builtin_fw) - LOAD_OFFSET) { \ 335 VMLINUX_SYMBOL(__start_builtin_fw) = .; \ 336 KEEP(*(.builtin_fw)) \ 337 VMLINUX_SYMBOL(__end_builtin_fw) = .; \ 338 } \ 339 \ 340 TRACEDATA \ 341 \ 342 /* Kernel symbol table: Normal symbols */ \ 343 __ksymtab : AT(ADDR(__ksymtab) - LOAD_OFFSET) { \ 344 VMLINUX_SYMBOL(__start___ksymtab) = .; \ 345 KEEP(*(SORT(___ksymtab+*))) \ 346 VMLINUX_SYMBOL(__stop___ksymtab) = .; \ 347 } \ 348 \ 349 /* Kernel symbol table: GPL-only symbols */ \ 350 __ksymtab_gpl : AT(ADDR(__ksymtab_gpl) - LOAD_OFFSET) { \ 351 VMLINUX_SYMBOL(__start___ksymtab_gpl) = .; \ 352 KEEP(*(SORT(___ksymtab_gpl+*))) \ 353 VMLINUX_SYMBOL(__stop___ksymtab_gpl) = .; \ 354 } \ 355 \ 356 /* Kernel symbol table: Normal unused symbols */ \ 357 __ksymtab_unused : AT(ADDR(__ksymtab_unused) - LOAD_OFFSET) { \ 358 VMLINUX_SYMBOL(__start___ksymtab_unused) = .; \ 359 KEEP(*(SORT(___ksymtab_unused+*))) \ 360 VMLINUX_SYMBOL(__stop___ksymtab_unused) = .; \ 361 } \ 362 \ 363 /* Kernel symbol table: GPL-only unused symbols */ \ 364 __ksymtab_unused_gpl : AT(ADDR(__ksymtab_unused_gpl) - LOAD_OFFSET) { \ 365 VMLINUX_SYMBOL(__start___ksymtab_unused_gpl) = .; \ 366 KEEP(*(SORT(___ksymtab_unused_gpl+*))) \ 367 VMLINUX_SYMBOL(__stop___ksymtab_unused_gpl) = .; \ 368 } \ 369 \ 370 /* Kernel symbol table: GPL-future-only symbols */ \ 371 __ksymtab_gpl_future : AT(ADDR(__ksymtab_gpl_future) - LOAD_OFFSET) { \ 372 VMLINUX_SYMBOL(__start___ksymtab_gpl_future) = .; \ 373 KEEP(*(SORT(___ksymtab_gpl_future+*))) \ 374 VMLINUX_SYMBOL(__stop___ksymtab_gpl_future) = .; \ 375 } \ 376 \ 377 /* Kernel symbol table: Normal symbols */ \ 378 __kcrctab : AT(ADDR(__kcrctab) - LOAD_OFFSET) { \ 379 VMLINUX_SYMBOL(__start___kcrctab) = .; \ 380 KEEP(*(SORT(___kcrctab+*))) \ 381 VMLINUX_SYMBOL(__stop___kcrctab) = .; \ 382 } \ 383 \ 384 /* Kernel symbol table: GPL-only symbols */ \ 385 __kcrctab_gpl : AT(ADDR(__kcrctab_gpl) - LOAD_OFFSET) { \ 386 VMLINUX_SYMBOL(__start___kcrctab_gpl) = .; \ 387 KEEP(*(SORT(___kcrctab_gpl+*))) \ 388 VMLINUX_SYMBOL(__stop___kcrctab_gpl) = .; \ 389 } \ 390 \ 391 /* Kernel symbol table: Normal unused symbols */ \ 392 __kcrctab_unused : AT(ADDR(__kcrctab_unused) - LOAD_OFFSET) { \ 393 VMLINUX_SYMBOL(__start___kcrctab_unused) = .; \ 394 KEEP(*(SORT(___kcrctab_unused+*))) \ 395 VMLINUX_SYMBOL(__stop___kcrctab_unused) = .; \ 396 } \ 397 \ 398 /* Kernel symbol table: GPL-only unused symbols */ \ 399 __kcrctab_unused_gpl : AT(ADDR(__kcrctab_unused_gpl) - LOAD_OFFSET) { \ 400 VMLINUX_SYMBOL(__start___kcrctab_unused_gpl) = .; \ 401 KEEP(*(SORT(___kcrctab_unused_gpl+*))) \ 402 VMLINUX_SYMBOL(__stop___kcrctab_unused_gpl) = .; \ 403 } \ 404 \ 405 /* Kernel symbol table: GPL-future-only symbols */ \ 406 __kcrctab_gpl_future : AT(ADDR(__kcrctab_gpl_future) - LOAD_OFFSET) { \ 407 VMLINUX_SYMBOL(__start___kcrctab_gpl_future) = .; \ 408 KEEP(*(SORT(___kcrctab_gpl_future+*))) \ 409 VMLINUX_SYMBOL(__stop___kcrctab_gpl_future) = .; \ 410 } \ 411 \ 412 /* Kernel symbol table: strings */ \ 413 __ksymtab_strings : AT(ADDR(__ksymtab_strings) - LOAD_OFFSET) { \ 414 *(__ksymtab_strings) \ 415 } \ 416 \ 417 /* __*init sections */ \ 418 __init_rodata : AT(ADDR(__init_rodata) - LOAD_OFFSET) { \ 419 *(.ref.rodata) \ 420 MEM_KEEP(init.rodata) \ 421 MEM_KEEP(exit.rodata) \ 422 } \ 423 \ 424 /* Built-in module parameters. */ \ 425 __param : AT(ADDR(__param) - LOAD_OFFSET) { \ 426 VMLINUX_SYMBOL(__start___param) = .; \ 427 KEEP(*(__param)) \ 428 VMLINUX_SYMBOL(__stop___param) = .; \ 429 } \ 430 \ 431 /* Built-in module versions. */ \ 432 __modver : AT(ADDR(__modver) - LOAD_OFFSET) { \ 433 VMLINUX_SYMBOL(__start___modver) = .; \ 434 KEEP(*(__modver)) \ 435 VMLINUX_SYMBOL(__stop___modver) = .; \ 436 . = ALIGN((align)); \ 437 VMLINUX_SYMBOL(__end_rodata) = .; \ 438 } \ 439 . = ALIGN((align)); 440 441 /* RODATA & RO_DATA provided for backward compatibility. 442 * All archs are supposed to use RO_DATA() */ 443 #define RODATA RO_DATA_SECTION(4096) 444 #define RO_DATA(align) RO_DATA_SECTION(align) 445 446 #define SECURITY_INIT \ 447 .security_initcall.init : AT(ADDR(.security_initcall.init) - LOAD_OFFSET) { \ 448 VMLINUX_SYMBOL(__security_initcall_start) = .; \ 449 KEEP(*(.security_initcall.init)) \ 450 VMLINUX_SYMBOL(__security_initcall_end) = .; \ 451 } 452 453 /* 454 * .text section. Map to function alignment to avoid address changes 455 * during second ld run in second ld pass when generating System.map 456 * 457 * TEXT_MAIN here will match .text.fixup and .text.unlikely if dead 458 * code elimination is enabled, so these sections should be converted 459 * to use ".." first. 460 */ 461 #define TEXT_TEXT \ 462 ALIGN_FUNCTION(); \ 463 *(.text.hot TEXT_MAIN .text.fixup .text.unlikely) \ 464 *(.text..refcount) \ 465 *(.text..ftrace) \ 466 *(TEXT_CFI_MAIN) \ 467 *(.ref.text) \ 468 MEM_KEEP(init.text) \ 469 MEM_KEEP(exit.text) \ 470 471 472 /* sched.text is aling to function alignment to secure we have same 473 * address even at second ld pass when generating System.map */ 474 #define SCHED_TEXT \ 475 ALIGN_FUNCTION(); \ 476 VMLINUX_SYMBOL(__sched_text_start) = .; \ 477 *(.sched.text) \ 478 VMLINUX_SYMBOL(__sched_text_end) = .; 479 480 /* spinlock.text is aling to function alignment to secure we have same 481 * address even at second ld pass when generating System.map */ 482 #define LOCK_TEXT \ 483 ALIGN_FUNCTION(); \ 484 VMLINUX_SYMBOL(__lock_text_start) = .; \ 485 *(.spinlock.text) \ 486 VMLINUX_SYMBOL(__lock_text_end) = .; 487 488 #define CPUIDLE_TEXT \ 489 ALIGN_FUNCTION(); \ 490 VMLINUX_SYMBOL(__cpuidle_text_start) = .; \ 491 *(.cpuidle.text) \ 492 VMLINUX_SYMBOL(__cpuidle_text_end) = .; 493 494 #define KPROBES_TEXT \ 495 ALIGN_FUNCTION(); \ 496 VMLINUX_SYMBOL(__kprobes_text_start) = .; \ 497 *(.kprobes.text) \ 498 VMLINUX_SYMBOL(__kprobes_text_end) = .; 499 500 #define ENTRY_TEXT \ 501 ALIGN_FUNCTION(); \ 502 VMLINUX_SYMBOL(__entry_text_start) = .; \ 503 *(.entry.text) \ 504 VMLINUX_SYMBOL(__entry_text_end) = .; 505 506 #define IRQENTRY_TEXT \ 507 ALIGN_FUNCTION(); \ 508 VMLINUX_SYMBOL(__irqentry_text_start) = .; \ 509 *(.irqentry.text) \ 510 VMLINUX_SYMBOL(__irqentry_text_end) = .; 511 512 #define SOFTIRQENTRY_TEXT \ 513 ALIGN_FUNCTION(); \ 514 VMLINUX_SYMBOL(__softirqentry_text_start) = .; \ 515 *(.softirqentry.text) \ 516 VMLINUX_SYMBOL(__softirqentry_text_end) = .; 517 518 /* Section used for early init (in .S files) */ 519 #define HEAD_TEXT KEEP(*(.head.text)) 520 521 #define HEAD_TEXT_SECTION \ 522 .head.text : AT(ADDR(.head.text) - LOAD_OFFSET) { \ 523 HEAD_TEXT \ 524 } 525 526 /* 527 * Exception table 528 */ 529 #define EXCEPTION_TABLE(align) \ 530 . = ALIGN(align); \ 531 __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { \ 532 VMLINUX_SYMBOL(__start___ex_table) = .; \ 533 KEEP(*(__ex_table)) \ 534 VMLINUX_SYMBOL(__stop___ex_table) = .; \ 535 } 536 537 /* 538 * Init task 539 */ 540 #define INIT_TASK_DATA_SECTION(align) \ 541 . = ALIGN(align); \ 542 .data..init_task : AT(ADDR(.data..init_task) - LOAD_OFFSET) { \ 543 INIT_TASK_DATA(align) \ 544 } 545 546 #ifdef CONFIG_CONSTRUCTORS 547 #define KERNEL_CTORS() . = ALIGN(8); \ 548 VMLINUX_SYMBOL(__ctors_start) = .; \ 549 KEEP(*(.ctors)) \ 550 KEEP(*(SORT(.init_array.*))) \ 551 KEEP(*(.init_array)) \ 552 VMLINUX_SYMBOL(__ctors_end) = .; 553 #else 554 #define KERNEL_CTORS() 555 #endif 556 557 /* init and exit section handling */ 558 #define INIT_DATA \ 559 KEEP(*(SORT(___kentry+*))) \ 560 *(.init.data) \ 561 MEM_DISCARD(init.data) \ 562 KERNEL_CTORS() \ 563 MCOUNT_REC() \ 564 *(.init.rodata .init.rodata.*) \ 565 FTRACE_EVENTS() \ 566 TRACE_SYSCALLS() \ 567 KPROBE_BLACKLIST() \ 568 MEM_DISCARD(init.rodata) \ 569 CLK_OF_TABLES() \ 570 RESERVEDMEM_OF_TABLES() \ 571 TIMER_OF_TABLES() \ 572 IOMMU_OF_TABLES() \ 573 CPU_METHOD_OF_TABLES() \ 574 CPUIDLE_METHOD_OF_TABLES() \ 575 KERNEL_DTB() \ 576 IRQCHIP_OF_MATCH_TABLE() \ 577 ACPI_PROBE_TABLE(irqchip) \ 578 ACPI_PROBE_TABLE(timer) \ 579 ACPI_PROBE_TABLE(iort) \ 580 EARLYCON_TABLE() 581 582 #define INIT_TEXT \ 583 *(.init.text .init.text.*) \ 584 *(.text.startup) \ 585 MEM_DISCARD(init.text) 586 587 #define EXIT_DATA \ 588 *(.exit.data) \ 589 *(.fini_array) \ 590 *(.dtors) \ 591 MEM_DISCARD(exit.data) \ 592 MEM_DISCARD(exit.rodata) 593 594 #define EXIT_TEXT \ 595 *(.exit.text) \ 596 *(.text.exit) \ 597 MEM_DISCARD(exit.text) 598 599 #define EXIT_CALL \ 600 KEEP(*(.exitcall.exit)) 601 602 /* 603 * bss (Block Started by Symbol) - uninitialized data 604 * zeroed during startup 605 */ 606 #define SBSS(sbss_align) \ 607 . = ALIGN(sbss_align); \ 608 .sbss : AT(ADDR(.sbss) - LOAD_OFFSET) { \ 609 *(.dynsbss) \ 610 *(.sbss) \ 611 *(.scommon) \ 612 } 613 614 /* 615 * Allow archectures to redefine BSS_FIRST_SECTIONS to add extra 616 * sections to the front of bss. 617 */ 618 #ifndef BSS_FIRST_SECTIONS 619 #define BSS_FIRST_SECTIONS 620 #endif 621 622 #define BSS(bss_align) \ 623 . = ALIGN(bss_align); \ 624 .bss : AT(ADDR(.bss) - LOAD_OFFSET) { \ 625 BSS_FIRST_SECTIONS \ 626 *(.bss..page_aligned) \ 627 *(.dynbss) \ 628 *(BSS_MAIN) \ 629 *(COMMON) \ 630 } 631 632 /* 633 * DWARF debug sections. 634 * Symbols in the DWARF debugging sections are relative to 635 * the beginning of the section so we begin them at 0. 636 */ 637 #define DWARF_DEBUG \ 638 /* DWARF 1 */ \ 639 .debug 0 : { *(.debug) } \ 640 .line 0 : { *(.line) } \ 641 /* GNU DWARF 1 extensions */ \ 642 .debug_srcinfo 0 : { *(.debug_srcinfo) } \ 643 .debug_sfnames 0 : { *(.debug_sfnames) } \ 644 /* DWARF 1.1 and DWARF 2 */ \ 645 .debug_aranges 0 : { *(.debug_aranges) } \ 646 .debug_pubnames 0 : { *(.debug_pubnames) } \ 647 /* DWARF 2 */ \ 648 .debug_info 0 : { *(.debug_info \ 649 .gnu.linkonce.wi.*) } \ 650 .debug_abbrev 0 : { *(.debug_abbrev) } \ 651 .debug_line 0 : { *(.debug_line) } \ 652 .debug_frame 0 : { *(.debug_frame) } \ 653 .debug_str 0 : { *(.debug_str) } \ 654 .debug_loc 0 : { *(.debug_loc) } \ 655 .debug_macinfo 0 : { *(.debug_macinfo) } \ 656 .debug_pubtypes 0 : { *(.debug_pubtypes) } \ 657 /* DWARF 3 */ \ 658 .debug_ranges 0 : { *(.debug_ranges) } \ 659 /* SGI/MIPS DWARF 2 extensions */ \ 660 .debug_weaknames 0 : { *(.debug_weaknames) } \ 661 .debug_funcnames 0 : { *(.debug_funcnames) } \ 662 .debug_typenames 0 : { *(.debug_typenames) } \ 663 .debug_varnames 0 : { *(.debug_varnames) } \ 664 /* GNU DWARF 2 extensions */ \ 665 .debug_gnu_pubnames 0 : { *(.debug_gnu_pubnames) } \ 666 .debug_gnu_pubtypes 0 : { *(.debug_gnu_pubtypes) } \ 667 /* DWARF 4 */ \ 668 .debug_types 0 : { *(.debug_types) } \ 669 /* DWARF 5 */ \ 670 .debug_macro 0 : { *(.debug_macro) } \ 671 .debug_addr 0 : { *(.debug_addr) } 672 673 /* Stabs debugging sections. */ 674 #define STABS_DEBUG \ 675 .stab 0 : { *(.stab) } \ 676 .stabstr 0 : { *(.stabstr) } \ 677 .stab.excl 0 : { *(.stab.excl) } \ 678 .stab.exclstr 0 : { *(.stab.exclstr) } \ 679 .stab.index 0 : { *(.stab.index) } \ 680 .stab.indexstr 0 : { *(.stab.indexstr) } \ 681 .comment 0 : { *(.comment) } 682 683 #ifdef CONFIG_GENERIC_BUG 684 #define BUG_TABLE \ 685 . = ALIGN(8); \ 686 __bug_table : AT(ADDR(__bug_table) - LOAD_OFFSET) { \ 687 VMLINUX_SYMBOL(__start___bug_table) = .; \ 688 KEEP(*(__bug_table)) \ 689 VMLINUX_SYMBOL(__stop___bug_table) = .; \ 690 } 691 #else 692 #define BUG_TABLE 693 #endif 694 695 #ifdef CONFIG_UNWINDER_ORC 696 #define ORC_UNWIND_TABLE \ 697 . = ALIGN(4); \ 698 .orc_unwind_ip : AT(ADDR(.orc_unwind_ip) - LOAD_OFFSET) { \ 699 VMLINUX_SYMBOL(__start_orc_unwind_ip) = .; \ 700 KEEP(*(.orc_unwind_ip)) \ 701 VMLINUX_SYMBOL(__stop_orc_unwind_ip) = .; \ 702 } \ 703 . = ALIGN(2); \ 704 .orc_unwind : AT(ADDR(.orc_unwind) - LOAD_OFFSET) { \ 705 VMLINUX_SYMBOL(__start_orc_unwind) = .; \ 706 KEEP(*(.orc_unwind)) \ 707 VMLINUX_SYMBOL(__stop_orc_unwind) = .; \ 708 } \ 709 . = ALIGN(4); \ 710 .orc_lookup : AT(ADDR(.orc_lookup) - LOAD_OFFSET) { \ 711 VMLINUX_SYMBOL(orc_lookup) = .; \ 712 . += (((SIZEOF(.text) + LOOKUP_BLOCK_SIZE - 1) / \ 713 LOOKUP_BLOCK_SIZE) + 1) * 4; \ 714 VMLINUX_SYMBOL(orc_lookup_end) = .; \ 715 } 716 #else 717 #define ORC_UNWIND_TABLE 718 #endif 719 720 #ifdef CONFIG_PM_TRACE 721 #define TRACEDATA \ 722 . = ALIGN(4); \ 723 .tracedata : AT(ADDR(.tracedata) - LOAD_OFFSET) { \ 724 VMLINUX_SYMBOL(__tracedata_start) = .; \ 725 KEEP(*(.tracedata)) \ 726 VMLINUX_SYMBOL(__tracedata_end) = .; \ 727 } 728 #else 729 #define TRACEDATA 730 #endif 731 732 #define NOTES \ 733 .notes : AT(ADDR(.notes) - LOAD_OFFSET) { \ 734 VMLINUX_SYMBOL(__start_notes) = .; \ 735 *(.note.*) \ 736 VMLINUX_SYMBOL(__stop_notes) = .; \ 737 } 738 739 #define INIT_SETUP(initsetup_align) \ 740 . = ALIGN(initsetup_align); \ 741 VMLINUX_SYMBOL(__setup_start) = .; \ 742 KEEP(*(.init.setup)) \ 743 VMLINUX_SYMBOL(__setup_end) = .; 744 745 #define INIT_CALLS_LEVEL(level) \ 746 VMLINUX_SYMBOL(__initcall##level##_start) = .; \ 747 KEEP(*(.initcall##level##.init)) \ 748 KEEP(*(.initcall##level##s.init)) \ 749 750 #define INIT_CALLS \ 751 VMLINUX_SYMBOL(__initcall_start) = .; \ 752 KEEP(*(.initcallearly.init)) \ 753 INIT_CALLS_LEVEL(0) \ 754 INIT_CALLS_LEVEL(1) \ 755 INIT_CALLS_LEVEL(2) \ 756 INIT_CALLS_LEVEL(3) \ 757 INIT_CALLS_LEVEL(4) \ 758 INIT_CALLS_LEVEL(5) \ 759 INIT_CALLS_LEVEL(rootfs) \ 760 INIT_CALLS_LEVEL(6) \ 761 INIT_CALLS_LEVEL(7) \ 762 VMLINUX_SYMBOL(__initcall_end) = .; 763 764 #define CON_INITCALL \ 765 VMLINUX_SYMBOL(__con_initcall_start) = .; \ 766 KEEP(*(.con_initcall.init)) \ 767 VMLINUX_SYMBOL(__con_initcall_end) = .; 768 769 #define SECURITY_INITCALL \ 770 VMLINUX_SYMBOL(__security_initcall_start) = .; \ 771 KEEP(*(.security_initcall.init)) \ 772 VMLINUX_SYMBOL(__security_initcall_end) = .; 773 774 #ifdef CONFIG_BLK_DEV_INITRD 775 #define INIT_RAM_FS \ 776 . = ALIGN(4); \ 777 VMLINUX_SYMBOL(__initramfs_start) = .; \ 778 KEEP(*(.init.ramfs)) \ 779 . = ALIGN(8); \ 780 KEEP(*(.init.ramfs.info)) 781 #else 782 #define INIT_RAM_FS 783 #endif 784 785 /* 786 * Default discarded sections. 787 * 788 * Some archs want to discard exit text/data at runtime rather than 789 * link time due to cross-section references such as alt instructions, 790 * bug table, eh_frame, etc. DISCARDS must be the last of output 791 * section definitions so that such archs put those in earlier section 792 * definitions. 793 */ 794 #define DISCARDS \ 795 /DISCARD/ : { \ 796 EXIT_TEXT \ 797 EXIT_DATA \ 798 EXIT_CALL \ 799 *(.discard) \ 800 *(.discard.*) \ 801 } 802 803 /** 804 * PERCPU_INPUT - the percpu input sections 805 * @cacheline: cacheline size 806 * 807 * The core percpu section names and core symbols which do not rely 808 * directly upon load addresses. 809 * 810 * @cacheline is used to align subsections to avoid false cacheline 811 * sharing between subsections for different purposes. 812 */ 813 #define PERCPU_INPUT(cacheline) \ 814 VMLINUX_SYMBOL(__per_cpu_start) = .; \ 815 *(.data..percpu..first) \ 816 . = ALIGN(PAGE_SIZE); \ 817 *(.data..percpu..page_aligned) \ 818 . = ALIGN(cacheline); \ 819 *(.data..percpu..read_mostly) \ 820 . = ALIGN(cacheline); \ 821 *(.data..percpu) \ 822 *(.data..percpu..shared_aligned) \ 823 VMLINUX_SYMBOL(__per_cpu_end) = .; 824 825 /** 826 * PERCPU_VADDR - define output section for percpu area 827 * @cacheline: cacheline size 828 * @vaddr: explicit base address (optional) 829 * @phdr: destination PHDR (optional) 830 * 831 * Macro which expands to output section for percpu area. 832 * 833 * @cacheline is used to align subsections to avoid false cacheline 834 * sharing between subsections for different purposes. 835 * 836 * If @vaddr is not blank, it specifies explicit base address and all 837 * percpu symbols will be offset from the given address. If blank, 838 * @vaddr always equals @laddr + LOAD_OFFSET. 839 * 840 * @phdr defines the output PHDR to use if not blank. Be warned that 841 * output PHDR is sticky. If @phdr is specified, the next output 842 * section in the linker script will go there too. @phdr should have 843 * a leading colon. 844 * 845 * Note that this macros defines __per_cpu_load as an absolute symbol. 846 * If there is no need to put the percpu section at a predetermined 847 * address, use PERCPU_SECTION. 848 */ 849 #define PERCPU_VADDR(cacheline, vaddr, phdr) \ 850 VMLINUX_SYMBOL(__per_cpu_load) = .; \ 851 .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \ 852 - LOAD_OFFSET) { \ 853 PERCPU_INPUT(cacheline) \ 854 } phdr \ 855 . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu); 856 857 /** 858 * PERCPU_SECTION - define output section for percpu area, simple version 859 * @cacheline: cacheline size 860 * 861 * Align to PAGE_SIZE and outputs output section for percpu area. This 862 * macro doesn't manipulate @vaddr or @phdr and __per_cpu_load and 863 * __per_cpu_start will be identical. 864 * 865 * This macro is equivalent to ALIGN(PAGE_SIZE); PERCPU_VADDR(@cacheline,,) 866 * except that __per_cpu_load is defined as a relative symbol against 867 * .data..percpu which is required for relocatable x86_32 configuration. 868 */ 869 #define PERCPU_SECTION(cacheline) \ 870 . = ALIGN(PAGE_SIZE); \ 871 .data..percpu : AT(ADDR(.data..percpu) - LOAD_OFFSET) { \ 872 VMLINUX_SYMBOL(__per_cpu_load) = .; \ 873 PERCPU_INPUT(cacheline) \ 874 } 875 876 877 /* 878 * Definition of the high level *_SECTION macros 879 * They will fit only a subset of the architectures 880 */ 881 882 883 /* 884 * Writeable data. 885 * All sections are combined in a single .data section. 886 * The sections following CONSTRUCTORS are arranged so their 887 * typical alignment matches. 888 * A cacheline is typical/always less than a PAGE_SIZE so 889 * the sections that has this restriction (or similar) 890 * is located before the ones requiring PAGE_SIZE alignment. 891 * NOSAVE_DATA starts and ends with a PAGE_SIZE alignment which 892 * matches the requirement of PAGE_ALIGNED_DATA. 893 * 894 * use 0 as page_align if page_aligned data is not used */ 895 #define RW_DATA_SECTION(cacheline, pagealigned, inittask) \ 896 . = ALIGN(PAGE_SIZE); \ 897 .data : AT(ADDR(.data) - LOAD_OFFSET) { \ 898 INIT_TASK_DATA(inittask) \ 899 NOSAVE_DATA \ 900 PAGE_ALIGNED_DATA(pagealigned) \ 901 CACHELINE_ALIGNED_DATA(cacheline) \ 902 READ_MOSTLY_DATA(cacheline) \ 903 DATA_DATA \ 904 CONSTRUCTORS \ 905 } \ 906 BUG_TABLE \ 907 908 #define INIT_TEXT_SECTION(inittext_align) \ 909 . = ALIGN(inittext_align); \ 910 .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) { \ 911 VMLINUX_SYMBOL(_sinittext) = .; \ 912 INIT_TEXT \ 913 VMLINUX_SYMBOL(_einittext) = .; \ 914 } 915 916 #define INIT_DATA_SECTION(initsetup_align) \ 917 .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) { \ 918 INIT_DATA \ 919 INIT_SETUP(initsetup_align) \ 920 INIT_CALLS \ 921 CON_INITCALL \ 922 SECURITY_INITCALL \ 923 INIT_RAM_FS \ 924 } 925 926 #define BSS_SECTION(sbss_align, bss_align, stop_align) \ 927 . = ALIGN(sbss_align); \ 928 VMLINUX_SYMBOL(__bss_start) = .; \ 929 SBSS(sbss_align) \ 930 BSS(bss_align) \ 931 . = ALIGN(stop_align); \ 932 VMLINUX_SYMBOL(__bss_stop) = .; 933