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