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