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