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(PAGE_SIZE) 27 * RW_DATA(...) 28 * _edata = .; 29 * 30 * EXCEPTION_TABLE(...) 31 * 32 * BSS_SECTION(0, 0, 0) 33 * _end = .; 34 * 35 * STABS_DEBUG 36 * DWARF_DEBUG 37 * ELF_DETAILS 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 /* 58 * Only some architectures want to have the .notes segment visible in 59 * a separate PT_NOTE ELF Program Header. When this happens, it needs 60 * to be visible in both the kernel text's PT_LOAD and the PT_NOTE 61 * Program Headers. In this case, though, the PT_LOAD needs to be made 62 * the default again so that all the following sections don't also end 63 * up in the PT_NOTE Program Header. 64 */ 65 #ifdef EMITS_PT_NOTE 66 #define NOTES_HEADERS :text :note 67 #define NOTES_HEADERS_RESTORE __restore_ph : { *(.__restore_ph) } :text 68 #else 69 #define NOTES_HEADERS 70 #define NOTES_HEADERS_RESTORE 71 #endif 72 73 /* 74 * Some architectures have non-executable read-only exception tables. 75 * They can be added to the RO_DATA segment by specifying their desired 76 * alignment. 77 */ 78 #ifdef RO_EXCEPTION_TABLE_ALIGN 79 #define RO_EXCEPTION_TABLE EXCEPTION_TABLE(RO_EXCEPTION_TABLE_ALIGN) 80 #else 81 #define RO_EXCEPTION_TABLE 82 #endif 83 84 /* Align . to a 8 byte boundary equals to maximum function alignment. */ 85 #define ALIGN_FUNCTION() . = ALIGN(8) 86 87 /* 88 * LD_DEAD_CODE_DATA_ELIMINATION option enables -fdata-sections, which 89 * generates .data.identifier sections, which need to be pulled in with 90 * .data. We don't want to pull in .data..other sections, which Linux 91 * has defined. Same for text and bss. 92 * 93 * With LTO_CLANG, the linker also splits sections by default, so we need 94 * these macros to combine the sections during the final link. 95 * 96 * RODATA_MAIN is not used because existing code already defines .rodata.x 97 * sections to be brought in with rodata. 98 */ 99 #if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || defined(CONFIG_LTO_CLANG) 100 #define TEXT_MAIN .text .text.[0-9a-zA-Z_]* 101 #define DATA_MAIN .data .data.[0-9a-zA-Z_]* .data..L* .data..compoundliteral* .data.$__unnamed_* .data.$L* 102 #define SDATA_MAIN .sdata .sdata.[0-9a-zA-Z_]* 103 #define RODATA_MAIN .rodata .rodata.[0-9a-zA-Z_]* .rodata..L* 104 #define BSS_MAIN .bss .bss.[0-9a-zA-Z_]* .bss..compoundliteral* 105 #define SBSS_MAIN .sbss .sbss.[0-9a-zA-Z_]* 106 #else 107 #define TEXT_MAIN .text 108 #define DATA_MAIN .data 109 #define SDATA_MAIN .sdata 110 #define RODATA_MAIN .rodata 111 #define BSS_MAIN .bss 112 #define SBSS_MAIN .sbss 113 #endif 114 115 /* 116 * GCC 4.5 and later have a 32 bytes section alignment for structures. 117 * Except GCC 4.9, that feels the need to align on 64 bytes. 118 */ 119 #define STRUCT_ALIGNMENT 32 120 #define STRUCT_ALIGN() . = ALIGN(STRUCT_ALIGNMENT) 121 122 /* 123 * The order of the sched class addresses are important, as they are 124 * used to determine the order of the priority of each sched class in 125 * relation to each other. 126 */ 127 #define SCHED_DATA \ 128 STRUCT_ALIGN(); \ 129 __sched_class_highest = .; \ 130 *(__stop_sched_class) \ 131 *(__dl_sched_class) \ 132 *(__rt_sched_class) \ 133 *(__fair_sched_class) \ 134 *(__idle_sched_class) \ 135 __sched_class_lowest = .; 136 137 /* The actual configuration determine if the init/exit sections 138 * are handled as text/data or they can be discarded (which 139 * often happens at runtime) 140 */ 141 #ifdef CONFIG_HOTPLUG_CPU 142 #define CPU_KEEP(sec) *(.cpu##sec) 143 #define CPU_DISCARD(sec) 144 #else 145 #define CPU_KEEP(sec) 146 #define CPU_DISCARD(sec) *(.cpu##sec) 147 #endif 148 149 #if defined(CONFIG_MEMORY_HOTPLUG) 150 #define MEM_KEEP(sec) *(.mem##sec) 151 #define MEM_DISCARD(sec) 152 #else 153 #define MEM_KEEP(sec) 154 #define MEM_DISCARD(sec) *(.mem##sec) 155 #endif 156 157 #ifndef CONFIG_HAVE_DYNAMIC_FTRACE_NO_PATCHABLE 158 #define KEEP_PATCHABLE KEEP(*(__patchable_function_entries)) 159 #define PATCHABLE_DISCARDS 160 #else 161 #define KEEP_PATCHABLE 162 #define PATCHABLE_DISCARDS *(__patchable_function_entries) 163 #endif 164 165 #ifdef CONFIG_FTRACE_MCOUNT_RECORD 166 /* 167 * The ftrace call sites are logged to a section whose name depends on the 168 * compiler option used. A given kernel image will only use one, AKA 169 * FTRACE_CALLSITE_SECTION. We capture all of them here to avoid header 170 * dependencies for FTRACE_CALLSITE_SECTION's definition. 171 * 172 * Need to also make ftrace_stub_graph point to ftrace_stub 173 * so that the same stub location may have different protocols 174 * and not mess up with C verifiers. 175 * 176 * ftrace_ops_list_func will be defined as arch_ftrace_ops_list_func 177 * as some archs will have a different prototype for that function 178 * but ftrace_ops_list_func() will have a single prototype. 179 */ 180 #define MCOUNT_REC() . = ALIGN(8); \ 181 __start_mcount_loc = .; \ 182 KEEP(*(__mcount_loc)) \ 183 KEEP_PATCHABLE \ 184 __stop_mcount_loc = .; \ 185 ftrace_stub_graph = ftrace_stub; \ 186 ftrace_ops_list_func = arch_ftrace_ops_list_func; 187 #else 188 # ifdef CONFIG_FUNCTION_TRACER 189 # define MCOUNT_REC() ftrace_stub_graph = ftrace_stub; \ 190 ftrace_ops_list_func = arch_ftrace_ops_list_func; 191 # else 192 # define MCOUNT_REC() 193 # endif 194 #endif 195 196 #ifdef CONFIG_TRACE_BRANCH_PROFILING 197 #define LIKELY_PROFILE() __start_annotated_branch_profile = .; \ 198 KEEP(*(_ftrace_annotated_branch)) \ 199 __stop_annotated_branch_profile = .; 200 #else 201 #define LIKELY_PROFILE() 202 #endif 203 204 #ifdef CONFIG_PROFILE_ALL_BRANCHES 205 #define BRANCH_PROFILE() __start_branch_profile = .; \ 206 KEEP(*(_ftrace_branch)) \ 207 __stop_branch_profile = .; 208 #else 209 #define BRANCH_PROFILE() 210 #endif 211 212 #ifdef CONFIG_KPROBES 213 #define KPROBE_BLACKLIST() . = ALIGN(8); \ 214 __start_kprobe_blacklist = .; \ 215 KEEP(*(_kprobe_blacklist)) \ 216 __stop_kprobe_blacklist = .; 217 #else 218 #define KPROBE_BLACKLIST() 219 #endif 220 221 #ifdef CONFIG_FUNCTION_ERROR_INJECTION 222 #define ERROR_INJECT_WHITELIST() STRUCT_ALIGN(); \ 223 __start_error_injection_whitelist = .; \ 224 KEEP(*(_error_injection_whitelist)) \ 225 __stop_error_injection_whitelist = .; 226 #else 227 #define ERROR_INJECT_WHITELIST() 228 #endif 229 230 #ifdef CONFIG_EVENT_TRACING 231 #define FTRACE_EVENTS() . = ALIGN(8); \ 232 __start_ftrace_events = .; \ 233 KEEP(*(_ftrace_events)) \ 234 __stop_ftrace_events = .; \ 235 __start_ftrace_eval_maps = .; \ 236 KEEP(*(_ftrace_eval_map)) \ 237 __stop_ftrace_eval_maps = .; 238 #else 239 #define FTRACE_EVENTS() 240 #endif 241 242 #ifdef CONFIG_TRACING 243 #define TRACE_PRINTKS() __start___trace_bprintk_fmt = .; \ 244 KEEP(*(__trace_printk_fmt)) /* Trace_printk fmt' pointer */ \ 245 __stop___trace_bprintk_fmt = .; 246 #define TRACEPOINT_STR() __start___tracepoint_str = .; \ 247 KEEP(*(__tracepoint_str)) /* Trace_printk fmt' pointer */ \ 248 __stop___tracepoint_str = .; 249 #else 250 #define TRACE_PRINTKS() 251 #define TRACEPOINT_STR() 252 #endif 253 254 #ifdef CONFIG_FTRACE_SYSCALLS 255 #define TRACE_SYSCALLS() . = ALIGN(8); \ 256 __start_syscalls_metadata = .; \ 257 KEEP(*(__syscalls_metadata)) \ 258 __stop_syscalls_metadata = .; 259 #else 260 #define TRACE_SYSCALLS() 261 #endif 262 263 #ifdef CONFIG_BPF_EVENTS 264 #define BPF_RAW_TP() STRUCT_ALIGN(); \ 265 __start__bpf_raw_tp = .; \ 266 KEEP(*(__bpf_raw_tp_map)) \ 267 __stop__bpf_raw_tp = .; 268 #else 269 #define BPF_RAW_TP() 270 #endif 271 272 #ifdef CONFIG_SERIAL_EARLYCON 273 #define EARLYCON_TABLE() . = ALIGN(8); \ 274 __earlycon_table = .; \ 275 KEEP(*(__earlycon_table)) \ 276 __earlycon_table_end = .; 277 #else 278 #define EARLYCON_TABLE() 279 #endif 280 281 #ifdef CONFIG_SECURITY 282 #define LSM_TABLE() . = ALIGN(8); \ 283 __start_lsm_info = .; \ 284 KEEP(*(.lsm_info.init)) \ 285 __end_lsm_info = .; 286 #define EARLY_LSM_TABLE() . = ALIGN(8); \ 287 __start_early_lsm_info = .; \ 288 KEEP(*(.early_lsm_info.init)) \ 289 __end_early_lsm_info = .; 290 #else 291 #define LSM_TABLE() 292 #define EARLY_LSM_TABLE() 293 #endif 294 295 #define ___OF_TABLE(cfg, name) _OF_TABLE_##cfg(name) 296 #define __OF_TABLE(cfg, name) ___OF_TABLE(cfg, name) 297 #define OF_TABLE(cfg, name) __OF_TABLE(IS_ENABLED(cfg), name) 298 #define _OF_TABLE_0(name) 299 #define _OF_TABLE_1(name) \ 300 . = ALIGN(8); \ 301 __##name##_of_table = .; \ 302 KEEP(*(__##name##_of_table)) \ 303 KEEP(*(__##name##_of_table_end)) 304 305 #define TIMER_OF_TABLES() OF_TABLE(CONFIG_TIMER_OF, timer) 306 #define IRQCHIP_OF_MATCH_TABLE() OF_TABLE(CONFIG_IRQCHIP, irqchip) 307 #define CLK_OF_TABLES() OF_TABLE(CONFIG_COMMON_CLK, clk) 308 #define RESERVEDMEM_OF_TABLES() OF_TABLE(CONFIG_OF_RESERVED_MEM, reservedmem) 309 #define CPU_METHOD_OF_TABLES() OF_TABLE(CONFIG_SMP, cpu_method) 310 #define CPUIDLE_METHOD_OF_TABLES() OF_TABLE(CONFIG_CPU_IDLE, cpuidle_method) 311 312 #ifdef CONFIG_ACPI 313 #define ACPI_PROBE_TABLE(name) \ 314 . = ALIGN(8); \ 315 __##name##_acpi_probe_table = .; \ 316 KEEP(*(__##name##_acpi_probe_table)) \ 317 __##name##_acpi_probe_table_end = .; 318 #else 319 #define ACPI_PROBE_TABLE(name) 320 #endif 321 322 #ifdef CONFIG_THERMAL 323 #define THERMAL_TABLE(name) \ 324 . = ALIGN(8); \ 325 __##name##_thermal_table = .; \ 326 KEEP(*(__##name##_thermal_table)) \ 327 __##name##_thermal_table_end = .; 328 #else 329 #define THERMAL_TABLE(name) 330 #endif 331 332 #define KERNEL_DTB() \ 333 STRUCT_ALIGN(); \ 334 __dtb_start = .; \ 335 KEEP(*(.dtb.init.rodata)) \ 336 __dtb_end = .; 337 338 /* 339 * .data section 340 */ 341 #define DATA_DATA \ 342 *(.xiptext) \ 343 *(DATA_MAIN) \ 344 *(.ref.data) \ 345 *(.data..shared_aligned) /* percpu related */ \ 346 MEM_KEEP(init.data*) \ 347 MEM_KEEP(exit.data*) \ 348 *(.data.unlikely) \ 349 __start_once = .; \ 350 *(.data.once) \ 351 __end_once = .; \ 352 STRUCT_ALIGN(); \ 353 *(__tracepoints) \ 354 /* implement dynamic printk debug */ \ 355 . = ALIGN(8); \ 356 __start___dyndbg_classes = .; \ 357 KEEP(*(__dyndbg_classes)) \ 358 __stop___dyndbg_classes = .; \ 359 __start___dyndbg = .; \ 360 KEEP(*(__dyndbg)) \ 361 __stop___dyndbg = .; \ 362 LIKELY_PROFILE() \ 363 BRANCH_PROFILE() \ 364 TRACE_PRINTKS() \ 365 BPF_RAW_TP() \ 366 TRACEPOINT_STR() 367 368 /* 369 * Data section helpers 370 */ 371 #define NOSAVE_DATA \ 372 . = ALIGN(PAGE_SIZE); \ 373 __nosave_begin = .; \ 374 *(.data..nosave) \ 375 . = ALIGN(PAGE_SIZE); \ 376 __nosave_end = .; 377 378 #define PAGE_ALIGNED_DATA(page_align) \ 379 . = ALIGN(page_align); \ 380 *(.data..page_aligned) \ 381 . = ALIGN(page_align); 382 383 #define READ_MOSTLY_DATA(align) \ 384 . = ALIGN(align); \ 385 *(.data..read_mostly) \ 386 . = ALIGN(align); 387 388 #define CACHELINE_ALIGNED_DATA(align) \ 389 . = ALIGN(align); \ 390 *(.data..cacheline_aligned) 391 392 #define INIT_TASK_DATA(align) \ 393 . = ALIGN(align); \ 394 __start_init_task = .; \ 395 init_thread_union = .; \ 396 init_stack = .; \ 397 KEEP(*(.data..init_task)) \ 398 KEEP(*(.data..init_thread_info)) \ 399 . = __start_init_task + THREAD_SIZE; \ 400 __end_init_task = .; 401 402 #define JUMP_TABLE_DATA \ 403 . = ALIGN(8); \ 404 __start___jump_table = .; \ 405 KEEP(*(__jump_table)) \ 406 __stop___jump_table = .; 407 408 #ifdef CONFIG_HAVE_STATIC_CALL_INLINE 409 #define STATIC_CALL_DATA \ 410 . = ALIGN(8); \ 411 __start_static_call_sites = .; \ 412 KEEP(*(.static_call_sites)) \ 413 __stop_static_call_sites = .; \ 414 __start_static_call_tramp_key = .; \ 415 KEEP(*(.static_call_tramp_key)) \ 416 __stop_static_call_tramp_key = .; 417 #else 418 #define STATIC_CALL_DATA 419 #endif 420 421 /* 422 * Allow architectures to handle ro_after_init data on their 423 * own by defining an empty RO_AFTER_INIT_DATA. 424 */ 425 #ifndef RO_AFTER_INIT_DATA 426 #define RO_AFTER_INIT_DATA \ 427 . = ALIGN(8); \ 428 __start_ro_after_init = .; \ 429 *(.data..ro_after_init) \ 430 JUMP_TABLE_DATA \ 431 STATIC_CALL_DATA \ 432 __end_ro_after_init = .; 433 #endif 434 435 /* 436 * .kcfi_traps contains a list KCFI trap locations. 437 */ 438 #ifndef KCFI_TRAPS 439 #ifdef CONFIG_ARCH_USES_CFI_TRAPS 440 #define KCFI_TRAPS \ 441 __kcfi_traps : AT(ADDR(__kcfi_traps) - LOAD_OFFSET) { \ 442 __start___kcfi_traps = .; \ 443 KEEP(*(.kcfi_traps)) \ 444 __stop___kcfi_traps = .; \ 445 } 446 #else 447 #define KCFI_TRAPS 448 #endif 449 #endif 450 451 /* 452 * Read only Data 453 */ 454 #define RO_DATA(align) \ 455 . = ALIGN((align)); \ 456 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \ 457 __start_rodata = .; \ 458 *(.rodata) *(.rodata.*) \ 459 SCHED_DATA \ 460 RO_AFTER_INIT_DATA /* Read only after init */ \ 461 . = ALIGN(8); \ 462 __start___tracepoints_ptrs = .; \ 463 KEEP(*(__tracepoints_ptrs)) /* Tracepoints: pointer array */ \ 464 __stop___tracepoints_ptrs = .; \ 465 *(__tracepoints_strings)/* Tracepoints: strings */ \ 466 } \ 467 \ 468 .rodata1 : AT(ADDR(.rodata1) - LOAD_OFFSET) { \ 469 *(.rodata1) \ 470 } \ 471 \ 472 /* PCI quirks */ \ 473 .pci_fixup : AT(ADDR(.pci_fixup) - LOAD_OFFSET) { \ 474 __start_pci_fixups_early = .; \ 475 KEEP(*(.pci_fixup_early)) \ 476 __end_pci_fixups_early = .; \ 477 __start_pci_fixups_header = .; \ 478 KEEP(*(.pci_fixup_header)) \ 479 __end_pci_fixups_header = .; \ 480 __start_pci_fixups_final = .; \ 481 KEEP(*(.pci_fixup_final)) \ 482 __end_pci_fixups_final = .; \ 483 __start_pci_fixups_enable = .; \ 484 KEEP(*(.pci_fixup_enable)) \ 485 __end_pci_fixups_enable = .; \ 486 __start_pci_fixups_resume = .; \ 487 KEEP(*(.pci_fixup_resume)) \ 488 __end_pci_fixups_resume = .; \ 489 __start_pci_fixups_resume_early = .; \ 490 KEEP(*(.pci_fixup_resume_early)) \ 491 __end_pci_fixups_resume_early = .; \ 492 __start_pci_fixups_suspend = .; \ 493 KEEP(*(.pci_fixup_suspend)) \ 494 __end_pci_fixups_suspend = .; \ 495 __start_pci_fixups_suspend_late = .; \ 496 KEEP(*(.pci_fixup_suspend_late)) \ 497 __end_pci_fixups_suspend_late = .; \ 498 } \ 499 \ 500 FW_LOADER_BUILT_IN_DATA \ 501 TRACEDATA \ 502 \ 503 PRINTK_INDEX \ 504 \ 505 /* Kernel symbol table: Normal symbols */ \ 506 __ksymtab : AT(ADDR(__ksymtab) - LOAD_OFFSET) { \ 507 __start___ksymtab = .; \ 508 KEEP(*(SORT(___ksymtab+*))) \ 509 __stop___ksymtab = .; \ 510 } \ 511 \ 512 /* Kernel symbol table: GPL-only symbols */ \ 513 __ksymtab_gpl : AT(ADDR(__ksymtab_gpl) - LOAD_OFFSET) { \ 514 __start___ksymtab_gpl = .; \ 515 KEEP(*(SORT(___ksymtab_gpl+*))) \ 516 __stop___ksymtab_gpl = .; \ 517 } \ 518 \ 519 /* Kernel symbol table: Normal symbols */ \ 520 __kcrctab : AT(ADDR(__kcrctab) - LOAD_OFFSET) { \ 521 __start___kcrctab = .; \ 522 KEEP(*(SORT(___kcrctab+*))) \ 523 __stop___kcrctab = .; \ 524 } \ 525 \ 526 /* Kernel symbol table: GPL-only symbols */ \ 527 __kcrctab_gpl : AT(ADDR(__kcrctab_gpl) - LOAD_OFFSET) { \ 528 __start___kcrctab_gpl = .; \ 529 KEEP(*(SORT(___kcrctab_gpl+*))) \ 530 __stop___kcrctab_gpl = .; \ 531 } \ 532 \ 533 /* Kernel symbol table: strings */ \ 534 __ksymtab_strings : AT(ADDR(__ksymtab_strings) - LOAD_OFFSET) { \ 535 *(__ksymtab_strings) \ 536 } \ 537 \ 538 /* __*init sections */ \ 539 __init_rodata : AT(ADDR(__init_rodata) - LOAD_OFFSET) { \ 540 *(.ref.rodata) \ 541 MEM_KEEP(init.rodata) \ 542 MEM_KEEP(exit.rodata) \ 543 } \ 544 \ 545 /* Built-in module parameters. */ \ 546 __param : AT(ADDR(__param) - LOAD_OFFSET) { \ 547 __start___param = .; \ 548 KEEP(*(__param)) \ 549 __stop___param = .; \ 550 } \ 551 \ 552 /* Built-in module versions. */ \ 553 __modver : AT(ADDR(__modver) - LOAD_OFFSET) { \ 554 __start___modver = .; \ 555 KEEP(*(__modver)) \ 556 __stop___modver = .; \ 557 } \ 558 \ 559 KCFI_TRAPS \ 560 \ 561 RO_EXCEPTION_TABLE \ 562 NOTES \ 563 BTF \ 564 \ 565 . = ALIGN((align)); \ 566 __end_rodata = .; 567 568 569 /* 570 * Non-instrumentable text section 571 */ 572 #define NOINSTR_TEXT \ 573 ALIGN_FUNCTION(); \ 574 __noinstr_text_start = .; \ 575 *(.noinstr.text) \ 576 __noinstr_text_end = .; 577 578 /* 579 * .text section. Map to function alignment to avoid address changes 580 * during second ld run in second ld pass when generating System.map 581 * 582 * TEXT_MAIN here will match .text.fixup and .text.unlikely if dead 583 * code elimination is enabled, so these sections should be converted 584 * to use ".." first. 585 */ 586 #define TEXT_TEXT \ 587 ALIGN_FUNCTION(); \ 588 *(.text.hot .text.hot.*) \ 589 *(TEXT_MAIN .text.fixup) \ 590 *(.text.unlikely .text.unlikely.*) \ 591 *(.text.unknown .text.unknown.*) \ 592 NOINSTR_TEXT \ 593 *(.text..refcount) \ 594 *(.ref.text) \ 595 *(.text.asan.* .text.tsan.*) \ 596 MEM_KEEP(init.text*) \ 597 MEM_KEEP(exit.text*) \ 598 599 600 /* sched.text is aling to function alignment to secure we have same 601 * address even at second ld pass when generating System.map */ 602 #define SCHED_TEXT \ 603 ALIGN_FUNCTION(); \ 604 __sched_text_start = .; \ 605 *(.sched.text) \ 606 __sched_text_end = .; 607 608 /* spinlock.text is aling to function alignment to secure we have same 609 * address even at second ld pass when generating System.map */ 610 #define LOCK_TEXT \ 611 ALIGN_FUNCTION(); \ 612 __lock_text_start = .; \ 613 *(.spinlock.text) \ 614 __lock_text_end = .; 615 616 #define CPUIDLE_TEXT \ 617 ALIGN_FUNCTION(); \ 618 __cpuidle_text_start = .; \ 619 *(.cpuidle.text) \ 620 __cpuidle_text_end = .; 621 622 #define KPROBES_TEXT \ 623 ALIGN_FUNCTION(); \ 624 __kprobes_text_start = .; \ 625 *(.kprobes.text) \ 626 __kprobes_text_end = .; 627 628 #define ENTRY_TEXT \ 629 ALIGN_FUNCTION(); \ 630 __entry_text_start = .; \ 631 *(.entry.text) \ 632 __entry_text_end = .; 633 634 #define IRQENTRY_TEXT \ 635 ALIGN_FUNCTION(); \ 636 __irqentry_text_start = .; \ 637 *(.irqentry.text) \ 638 __irqentry_text_end = .; 639 640 #define SOFTIRQENTRY_TEXT \ 641 ALIGN_FUNCTION(); \ 642 __softirqentry_text_start = .; \ 643 *(.softirqentry.text) \ 644 __softirqentry_text_end = .; 645 646 #define STATIC_CALL_TEXT \ 647 ALIGN_FUNCTION(); \ 648 __static_call_text_start = .; \ 649 *(.static_call.text) \ 650 __static_call_text_end = .; 651 652 /* Section used for early init (in .S files) */ 653 #define HEAD_TEXT KEEP(*(.head.text)) 654 655 #define HEAD_TEXT_SECTION \ 656 .head.text : AT(ADDR(.head.text) - LOAD_OFFSET) { \ 657 HEAD_TEXT \ 658 } 659 660 /* 661 * Exception table 662 */ 663 #define EXCEPTION_TABLE(align) \ 664 . = ALIGN(align); \ 665 __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { \ 666 __start___ex_table = .; \ 667 KEEP(*(__ex_table)) \ 668 __stop___ex_table = .; \ 669 } 670 671 /* 672 * .BTF 673 */ 674 #ifdef CONFIG_DEBUG_INFO_BTF 675 #define BTF \ 676 .BTF : AT(ADDR(.BTF) - LOAD_OFFSET) { \ 677 __start_BTF = .; \ 678 KEEP(*(.BTF)) \ 679 __stop_BTF = .; \ 680 } \ 681 . = ALIGN(4); \ 682 .BTF_ids : AT(ADDR(.BTF_ids) - LOAD_OFFSET) { \ 683 *(.BTF_ids) \ 684 } 685 #else 686 #define BTF 687 #endif 688 689 /* 690 * Init task 691 */ 692 #define INIT_TASK_DATA_SECTION(align) \ 693 . = ALIGN(align); \ 694 .data..init_task : AT(ADDR(.data..init_task) - LOAD_OFFSET) { \ 695 INIT_TASK_DATA(align) \ 696 } 697 698 #ifdef CONFIG_CONSTRUCTORS 699 #define KERNEL_CTORS() . = ALIGN(8); \ 700 __ctors_start = .; \ 701 KEEP(*(SORT(.ctors.*))) \ 702 KEEP(*(.ctors)) \ 703 KEEP(*(SORT(.init_array.*))) \ 704 KEEP(*(.init_array)) \ 705 __ctors_end = .; 706 #else 707 #define KERNEL_CTORS() 708 #endif 709 710 /* init and exit section handling */ 711 #define INIT_DATA \ 712 KEEP(*(SORT(___kentry+*))) \ 713 *(.init.data init.data.*) \ 714 MEM_DISCARD(init.data*) \ 715 KERNEL_CTORS() \ 716 MCOUNT_REC() \ 717 *(.init.rodata .init.rodata.*) \ 718 FTRACE_EVENTS() \ 719 TRACE_SYSCALLS() \ 720 KPROBE_BLACKLIST() \ 721 ERROR_INJECT_WHITELIST() \ 722 MEM_DISCARD(init.rodata) \ 723 CLK_OF_TABLES() \ 724 RESERVEDMEM_OF_TABLES() \ 725 TIMER_OF_TABLES() \ 726 CPU_METHOD_OF_TABLES() \ 727 CPUIDLE_METHOD_OF_TABLES() \ 728 KERNEL_DTB() \ 729 IRQCHIP_OF_MATCH_TABLE() \ 730 ACPI_PROBE_TABLE(irqchip) \ 731 ACPI_PROBE_TABLE(timer) \ 732 THERMAL_TABLE(governor) \ 733 EARLYCON_TABLE() \ 734 LSM_TABLE() \ 735 EARLY_LSM_TABLE() \ 736 KUNIT_TABLE() 737 738 #define INIT_TEXT \ 739 *(.init.text .init.text.*) \ 740 *(.text.startup) \ 741 MEM_DISCARD(init.text*) 742 743 #define EXIT_DATA \ 744 *(.exit.data .exit.data.*) \ 745 *(.fini_array .fini_array.*) \ 746 *(.dtors .dtors.*) \ 747 MEM_DISCARD(exit.data*) \ 748 MEM_DISCARD(exit.rodata*) 749 750 #define EXIT_TEXT \ 751 *(.exit.text) \ 752 *(.text.exit) \ 753 MEM_DISCARD(exit.text) 754 755 #define EXIT_CALL \ 756 *(.exitcall.exit) 757 758 /* 759 * bss (Block Started by Symbol) - uninitialized data 760 * zeroed during startup 761 */ 762 #define SBSS(sbss_align) \ 763 . = ALIGN(sbss_align); \ 764 .sbss : AT(ADDR(.sbss) - LOAD_OFFSET) { \ 765 *(.dynsbss) \ 766 *(SBSS_MAIN) \ 767 *(.scommon) \ 768 } 769 770 /* 771 * Allow archectures to redefine BSS_FIRST_SECTIONS to add extra 772 * sections to the front of bss. 773 */ 774 #ifndef BSS_FIRST_SECTIONS 775 #define BSS_FIRST_SECTIONS 776 #endif 777 778 #define BSS(bss_align) \ 779 . = ALIGN(bss_align); \ 780 .bss : AT(ADDR(.bss) - LOAD_OFFSET) { \ 781 BSS_FIRST_SECTIONS \ 782 . = ALIGN(PAGE_SIZE); \ 783 *(.bss..page_aligned) \ 784 . = ALIGN(PAGE_SIZE); \ 785 *(.dynbss) \ 786 *(BSS_MAIN) \ 787 *(COMMON) \ 788 } 789 790 /* 791 * DWARF debug sections. 792 * Symbols in the DWARF debugging sections are relative to 793 * the beginning of the section so we begin them at 0. 794 */ 795 #define DWARF_DEBUG \ 796 /* DWARF 1 */ \ 797 .debug 0 : { *(.debug) } \ 798 .line 0 : { *(.line) } \ 799 /* GNU DWARF 1 extensions */ \ 800 .debug_srcinfo 0 : { *(.debug_srcinfo) } \ 801 .debug_sfnames 0 : { *(.debug_sfnames) } \ 802 /* DWARF 1.1 and DWARF 2 */ \ 803 .debug_aranges 0 : { *(.debug_aranges) } \ 804 .debug_pubnames 0 : { *(.debug_pubnames) } \ 805 /* DWARF 2 */ \ 806 .debug_info 0 : { *(.debug_info \ 807 .gnu.linkonce.wi.*) } \ 808 .debug_abbrev 0 : { *(.debug_abbrev) } \ 809 .debug_line 0 : { *(.debug_line) } \ 810 .debug_frame 0 : { *(.debug_frame) } \ 811 .debug_str 0 : { *(.debug_str) } \ 812 .debug_loc 0 : { *(.debug_loc) } \ 813 .debug_macinfo 0 : { *(.debug_macinfo) } \ 814 .debug_pubtypes 0 : { *(.debug_pubtypes) } \ 815 /* DWARF 3 */ \ 816 .debug_ranges 0 : { *(.debug_ranges) } \ 817 /* SGI/MIPS DWARF 2 extensions */ \ 818 .debug_weaknames 0 : { *(.debug_weaknames) } \ 819 .debug_funcnames 0 : { *(.debug_funcnames) } \ 820 .debug_typenames 0 : { *(.debug_typenames) } \ 821 .debug_varnames 0 : { *(.debug_varnames) } \ 822 /* GNU DWARF 2 extensions */ \ 823 .debug_gnu_pubnames 0 : { *(.debug_gnu_pubnames) } \ 824 .debug_gnu_pubtypes 0 : { *(.debug_gnu_pubtypes) } \ 825 /* DWARF 4 */ \ 826 .debug_types 0 : { *(.debug_types) } \ 827 /* DWARF 5 */ \ 828 .debug_addr 0 : { *(.debug_addr) } \ 829 .debug_line_str 0 : { *(.debug_line_str) } \ 830 .debug_loclists 0 : { *(.debug_loclists) } \ 831 .debug_macro 0 : { *(.debug_macro) } \ 832 .debug_names 0 : { *(.debug_names) } \ 833 .debug_rnglists 0 : { *(.debug_rnglists) } \ 834 .debug_str_offsets 0 : { *(.debug_str_offsets) } 835 836 /* Stabs debugging sections. */ 837 #define STABS_DEBUG \ 838 .stab 0 : { *(.stab) } \ 839 .stabstr 0 : { *(.stabstr) } \ 840 .stab.excl 0 : { *(.stab.excl) } \ 841 .stab.exclstr 0 : { *(.stab.exclstr) } \ 842 .stab.index 0 : { *(.stab.index) } \ 843 .stab.indexstr 0 : { *(.stab.indexstr) } 844 845 /* Required sections not related to debugging. */ 846 #define ELF_DETAILS \ 847 .comment 0 : { *(.comment) } \ 848 .symtab 0 : { *(.symtab) } \ 849 .strtab 0 : { *(.strtab) } \ 850 .shstrtab 0 : { *(.shstrtab) } 851 852 #ifdef CONFIG_GENERIC_BUG 853 #define BUG_TABLE \ 854 . = ALIGN(8); \ 855 __bug_table : AT(ADDR(__bug_table) - LOAD_OFFSET) { \ 856 __start___bug_table = .; \ 857 KEEP(*(__bug_table)) \ 858 __stop___bug_table = .; \ 859 } 860 #else 861 #define BUG_TABLE 862 #endif 863 864 #ifdef CONFIG_UNWINDER_ORC 865 #define ORC_UNWIND_TABLE \ 866 . = ALIGN(4); \ 867 .orc_unwind_ip : AT(ADDR(.orc_unwind_ip) - LOAD_OFFSET) { \ 868 __start_orc_unwind_ip = .; \ 869 KEEP(*(.orc_unwind_ip)) \ 870 __stop_orc_unwind_ip = .; \ 871 } \ 872 . = ALIGN(2); \ 873 .orc_unwind : AT(ADDR(.orc_unwind) - LOAD_OFFSET) { \ 874 __start_orc_unwind = .; \ 875 KEEP(*(.orc_unwind)) \ 876 __stop_orc_unwind = .; \ 877 } \ 878 text_size = _etext - _stext; \ 879 . = ALIGN(4); \ 880 .orc_lookup : AT(ADDR(.orc_lookup) - LOAD_OFFSET) { \ 881 orc_lookup = .; \ 882 . += (((text_size + LOOKUP_BLOCK_SIZE - 1) / \ 883 LOOKUP_BLOCK_SIZE) + 1) * 4; \ 884 orc_lookup_end = .; \ 885 } 886 #else 887 #define ORC_UNWIND_TABLE 888 #endif 889 890 /* Built-in firmware blobs */ 891 #ifdef CONFIG_FW_LOADER 892 #define FW_LOADER_BUILT_IN_DATA \ 893 .builtin_fw : AT(ADDR(.builtin_fw) - LOAD_OFFSET) ALIGN(8) { \ 894 __start_builtin_fw = .; \ 895 KEEP(*(.builtin_fw)) \ 896 __end_builtin_fw = .; \ 897 } 898 #else 899 #define FW_LOADER_BUILT_IN_DATA 900 #endif 901 902 #ifdef CONFIG_PM_TRACE 903 #define TRACEDATA \ 904 . = ALIGN(4); \ 905 .tracedata : AT(ADDR(.tracedata) - LOAD_OFFSET) { \ 906 __tracedata_start = .; \ 907 KEEP(*(.tracedata)) \ 908 __tracedata_end = .; \ 909 } 910 #else 911 #define TRACEDATA 912 #endif 913 914 #ifdef CONFIG_PRINTK_INDEX 915 #define PRINTK_INDEX \ 916 .printk_index : AT(ADDR(.printk_index) - LOAD_OFFSET) { \ 917 __start_printk_index = .; \ 918 *(.printk_index) \ 919 __stop_printk_index = .; \ 920 } 921 #else 922 #define PRINTK_INDEX 923 #endif 924 925 #define NOTES \ 926 .notes : AT(ADDR(.notes) - LOAD_OFFSET) { \ 927 __start_notes = .; \ 928 KEEP(*(.note.*)) \ 929 __stop_notes = .; \ 930 } NOTES_HEADERS \ 931 NOTES_HEADERS_RESTORE 932 933 #define INIT_SETUP(initsetup_align) \ 934 . = ALIGN(initsetup_align); \ 935 __setup_start = .; \ 936 KEEP(*(.init.setup)) \ 937 __setup_end = .; 938 939 #define INIT_CALLS_LEVEL(level) \ 940 __initcall##level##_start = .; \ 941 KEEP(*(.initcall##level##.init)) \ 942 KEEP(*(.initcall##level##s.init)) \ 943 944 #define INIT_CALLS \ 945 __initcall_start = .; \ 946 KEEP(*(.initcallearly.init)) \ 947 INIT_CALLS_LEVEL(0) \ 948 INIT_CALLS_LEVEL(1) \ 949 INIT_CALLS_LEVEL(2) \ 950 INIT_CALLS_LEVEL(3) \ 951 INIT_CALLS_LEVEL(4) \ 952 INIT_CALLS_LEVEL(5) \ 953 INIT_CALLS_LEVEL(rootfs) \ 954 INIT_CALLS_LEVEL(6) \ 955 INIT_CALLS_LEVEL(7) \ 956 __initcall_end = .; 957 958 #define CON_INITCALL \ 959 __con_initcall_start = .; \ 960 KEEP(*(.con_initcall.init)) \ 961 __con_initcall_end = .; 962 963 /* Alignment must be consistent with (kunit_suite *) in include/kunit/test.h */ 964 #define KUNIT_TABLE() \ 965 . = ALIGN(8); \ 966 __kunit_suites_start = .; \ 967 KEEP(*(.kunit_test_suites)) \ 968 __kunit_suites_end = .; 969 970 #ifdef CONFIG_BLK_DEV_INITRD 971 #define INIT_RAM_FS \ 972 . = ALIGN(4); \ 973 __initramfs_start = .; \ 974 KEEP(*(.init.ramfs)) \ 975 . = ALIGN(8); \ 976 KEEP(*(.init.ramfs.info)) 977 #else 978 #define INIT_RAM_FS 979 #endif 980 981 /* 982 * Memory encryption operates on a page basis. Since we need to clear 983 * the memory encryption mask for this section, it needs to be aligned 984 * on a page boundary and be a page-size multiple in length. 985 * 986 * Note: We use a separate section so that only this section gets 987 * decrypted to avoid exposing more than we wish. 988 */ 989 #ifdef CONFIG_AMD_MEM_ENCRYPT 990 #define PERCPU_DECRYPTED_SECTION \ 991 . = ALIGN(PAGE_SIZE); \ 992 *(.data..decrypted) \ 993 *(.data..percpu..decrypted) \ 994 . = ALIGN(PAGE_SIZE); 995 #else 996 #define PERCPU_DECRYPTED_SECTION 997 #endif 998 999 1000 /* 1001 * Default discarded sections. 1002 * 1003 * Some archs want to discard exit text/data at runtime rather than 1004 * link time due to cross-section references such as alt instructions, 1005 * bug table, eh_frame, etc. DISCARDS must be the last of output 1006 * section definitions so that such archs put those in earlier section 1007 * definitions. 1008 */ 1009 #ifdef RUNTIME_DISCARD_EXIT 1010 #define EXIT_DISCARDS 1011 #else 1012 #define EXIT_DISCARDS \ 1013 EXIT_TEXT \ 1014 EXIT_DATA 1015 #endif 1016 1017 /* 1018 * Clang's -fprofile-arcs, -fsanitize=kernel-address, and 1019 * -fsanitize=thread produce unwanted sections (.eh_frame 1020 * and .init_array.*), but CONFIG_CONSTRUCTORS wants to 1021 * keep any .init_array.* sections. 1022 * https://bugs.llvm.org/show_bug.cgi?id=46478 1023 */ 1024 #if defined(CONFIG_GCOV_KERNEL) || defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KCSAN) 1025 # ifdef CONFIG_CONSTRUCTORS 1026 # define SANITIZER_DISCARDS \ 1027 *(.eh_frame) 1028 # else 1029 # define SANITIZER_DISCARDS \ 1030 *(.init_array) *(.init_array.*) \ 1031 *(.eh_frame) 1032 # endif 1033 #else 1034 # define SANITIZER_DISCARDS 1035 #endif 1036 1037 #define COMMON_DISCARDS \ 1038 SANITIZER_DISCARDS \ 1039 PATCHABLE_DISCARDS \ 1040 *(.discard) \ 1041 *(.discard.*) \ 1042 *(.modinfo) \ 1043 /* ld.bfd warns about .gnu.version* even when not emitted */ \ 1044 *(.gnu.version*) \ 1045 1046 #define DISCARDS \ 1047 /DISCARD/ : { \ 1048 EXIT_DISCARDS \ 1049 EXIT_CALL \ 1050 COMMON_DISCARDS \ 1051 } 1052 1053 /** 1054 * PERCPU_INPUT - the percpu input sections 1055 * @cacheline: cacheline size 1056 * 1057 * The core percpu section names and core symbols which do not rely 1058 * directly upon load addresses. 1059 * 1060 * @cacheline is used to align subsections to avoid false cacheline 1061 * sharing between subsections for different purposes. 1062 */ 1063 #define PERCPU_INPUT(cacheline) \ 1064 __per_cpu_start = .; \ 1065 *(.data..percpu..first) \ 1066 . = ALIGN(PAGE_SIZE); \ 1067 *(.data..percpu..page_aligned) \ 1068 . = ALIGN(cacheline); \ 1069 *(.data..percpu..read_mostly) \ 1070 . = ALIGN(cacheline); \ 1071 *(.data..percpu) \ 1072 *(.data..percpu..shared_aligned) \ 1073 PERCPU_DECRYPTED_SECTION \ 1074 __per_cpu_end = .; 1075 1076 /** 1077 * PERCPU_VADDR - define output section for percpu area 1078 * @cacheline: cacheline size 1079 * @vaddr: explicit base address (optional) 1080 * @phdr: destination PHDR (optional) 1081 * 1082 * Macro which expands to output section for percpu area. 1083 * 1084 * @cacheline is used to align subsections to avoid false cacheline 1085 * sharing between subsections for different purposes. 1086 * 1087 * If @vaddr is not blank, it specifies explicit base address and all 1088 * percpu symbols will be offset from the given address. If blank, 1089 * @vaddr always equals @laddr + LOAD_OFFSET. 1090 * 1091 * @phdr defines the output PHDR to use if not blank. Be warned that 1092 * output PHDR is sticky. If @phdr is specified, the next output 1093 * section in the linker script will go there too. @phdr should have 1094 * a leading colon. 1095 * 1096 * Note that this macros defines __per_cpu_load as an absolute symbol. 1097 * If there is no need to put the percpu section at a predetermined 1098 * address, use PERCPU_SECTION. 1099 */ 1100 #define PERCPU_VADDR(cacheline, vaddr, phdr) \ 1101 __per_cpu_load = .; \ 1102 .data..percpu vaddr : AT(__per_cpu_load - LOAD_OFFSET) { \ 1103 PERCPU_INPUT(cacheline) \ 1104 } phdr \ 1105 . = __per_cpu_load + SIZEOF(.data..percpu); 1106 1107 /** 1108 * PERCPU_SECTION - define output section for percpu area, simple version 1109 * @cacheline: cacheline size 1110 * 1111 * Align to PAGE_SIZE and outputs output section for percpu area. This 1112 * macro doesn't manipulate @vaddr or @phdr and __per_cpu_load and 1113 * __per_cpu_start will be identical. 1114 * 1115 * This macro is equivalent to ALIGN(PAGE_SIZE); PERCPU_VADDR(@cacheline,,) 1116 * except that __per_cpu_load is defined as a relative symbol against 1117 * .data..percpu which is required for relocatable x86_32 configuration. 1118 */ 1119 #define PERCPU_SECTION(cacheline) \ 1120 . = ALIGN(PAGE_SIZE); \ 1121 .data..percpu : AT(ADDR(.data..percpu) - LOAD_OFFSET) { \ 1122 __per_cpu_load = .; \ 1123 PERCPU_INPUT(cacheline) \ 1124 } 1125 1126 1127 /* 1128 * Definition of the high level *_SECTION macros 1129 * They will fit only a subset of the architectures 1130 */ 1131 1132 1133 /* 1134 * Writeable data. 1135 * All sections are combined in a single .data section. 1136 * The sections following CONSTRUCTORS are arranged so their 1137 * typical alignment matches. 1138 * A cacheline is typical/always less than a PAGE_SIZE so 1139 * the sections that has this restriction (or similar) 1140 * is located before the ones requiring PAGE_SIZE alignment. 1141 * NOSAVE_DATA starts and ends with a PAGE_SIZE alignment which 1142 * matches the requirement of PAGE_ALIGNED_DATA. 1143 * 1144 * use 0 as page_align if page_aligned data is not used */ 1145 #define RW_DATA(cacheline, pagealigned, inittask) \ 1146 . = ALIGN(PAGE_SIZE); \ 1147 .data : AT(ADDR(.data) - LOAD_OFFSET) { \ 1148 INIT_TASK_DATA(inittask) \ 1149 NOSAVE_DATA \ 1150 PAGE_ALIGNED_DATA(pagealigned) \ 1151 CACHELINE_ALIGNED_DATA(cacheline) \ 1152 READ_MOSTLY_DATA(cacheline) \ 1153 DATA_DATA \ 1154 CONSTRUCTORS \ 1155 } \ 1156 BUG_TABLE \ 1157 1158 #define INIT_TEXT_SECTION(inittext_align) \ 1159 . = ALIGN(inittext_align); \ 1160 .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) { \ 1161 _sinittext = .; \ 1162 INIT_TEXT \ 1163 _einittext = .; \ 1164 } 1165 1166 #define INIT_DATA_SECTION(initsetup_align) \ 1167 .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) { \ 1168 INIT_DATA \ 1169 INIT_SETUP(initsetup_align) \ 1170 INIT_CALLS \ 1171 CON_INITCALL \ 1172 INIT_RAM_FS \ 1173 } 1174 1175 #define BSS_SECTION(sbss_align, bss_align, stop_align) \ 1176 . = ALIGN(sbss_align); \ 1177 __bss_start = .; \ 1178 SBSS(sbss_align) \ 1179 BSS(bss_align) \ 1180 . = ALIGN(stop_align); \ 1181 __bss_stop = .; 1182