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