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