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