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