2 * Helper macros to support writing architecture specific
5 * A minimal linker scripts has following content:
6 * [This is a sample, architectures may have special requiriements]
16 * INIT_TEXT_SECTION(PAGE_SIZE)
17 * INIT_DATA_SECTION(...)
18 * PERCPU_SECTION(CACHELINE_SIZE)
30 * EXCEPTION_TABLE(...)
32 * BSS_SECTION(0, 0, 0)
39 * DISCARDS // must be the last
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
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
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.
66 #define NOTES_HEADERS :text :note
67 #define NOTES_HEADERS_RESTORE __restore_ph : { *(.__restore_ph) } :text
70 #define NOTES_HEADERS_RESTORE
74 * Some architectures have non-executable read-only exception tables.
75 * They can be added to the RO_DATA segment by specifying their desired
78 #ifdef RO_EXCEPTION_TABLE_ALIGN
79 #define RO_EXCEPTION_TABLE EXCEPTION_TABLE(RO_EXCEPTION_TABLE_ALIGN)
81 #define RO_EXCEPTION_TABLE
84 /* Align . to a 8 byte boundary equals to maximum function alignment. */
85 #define ALIGN_FUNCTION() . = ALIGN(8)
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.
93 * With LTO_CLANG, the linker also splits sections by default, so we need
94 * these macros to combine the sections during the final link.
96 * RODATA_MAIN is not used because existing code already defines .rodata.x
97 * sections to be brought in with rodata.
99 #if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || defined(CONFIG_LTO_CLANG)
100 #define TEXT_MAIN .text .text.[0-9a-zA-Z_]*
101 #define DATA_MAIN .data .data.[0-9a-zA-Z_]* .data..L* .data..compoundliteral* .data.$__unnamed_* .data.$L*
102 #define SDATA_MAIN .sdata .sdata.[0-9a-zA-Z_]*
103 #define RODATA_MAIN .rodata .rodata.[0-9a-zA-Z_]* .rodata..L*
104 #define BSS_MAIN .bss .bss.[0-9a-zA-Z_]* .bss..compoundliteral*
105 #define SBSS_MAIN .sbss .sbss.[0-9a-zA-Z_]*
107 #define TEXT_MAIN .text
108 #define DATA_MAIN .data
109 #define SDATA_MAIN .sdata
110 #define RODATA_MAIN .rodata
111 #define BSS_MAIN .bss
112 #define SBSS_MAIN .sbss
116 * GCC 4.5 and later have a 32 bytes section alignment for structures.
117 * Except GCC 4.9, that feels the need to align on 64 bytes.
119 #define STRUCT_ALIGNMENT 32
120 #define STRUCT_ALIGN() . = ALIGN(STRUCT_ALIGNMENT)
123 * The order of the sched class addresses are important, as they are
124 * used to determine the order of the priority of each sched class in
125 * relation to each other.
129 __sched_class_highest = .; \
130 *(__stop_sched_class) \
131 *(__dl_sched_class) \
132 *(__rt_sched_class) \
133 *(__fair_sched_class) \
134 *(__idle_sched_class) \
135 __sched_class_lowest = .;
137 /* The actual configuration determine if the init/exit sections
138 * are handled as text/data or they can be discarded (which
139 * often happens at runtime)
141 #ifdef CONFIG_HOTPLUG_CPU
142 #define CPU_KEEP(sec) *(.cpu##sec)
143 #define CPU_DISCARD(sec)
145 #define CPU_KEEP(sec)
146 #define CPU_DISCARD(sec) *(.cpu##sec)
149 #if defined(CONFIG_MEMORY_HOTPLUG)
150 #define MEM_KEEP(sec) *(.mem##sec)
151 #define MEM_DISCARD(sec)
153 #define MEM_KEEP(sec)
154 #define MEM_DISCARD(sec) *(.mem##sec)
157 #ifndef CONFIG_HAVE_DYNAMIC_FTRACE_NO_PATCHABLE
158 #define KEEP_PATCHABLE KEEP(*(__patchable_function_entries))
159 #define PATCHABLE_DISCARDS
161 #define KEEP_PATCHABLE
162 #define PATCHABLE_DISCARDS *(__patchable_function_entries)
165 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
167 * The ftrace call sites are logged to a section whose name depends on the
168 * compiler option used. A given kernel image will only use one, AKA
169 * FTRACE_CALLSITE_SECTION. We capture all of them here to avoid header
170 * dependencies for FTRACE_CALLSITE_SECTION's definition.
172 * Need to also make ftrace_stub_graph point to ftrace_stub
173 * so that the same stub location may have different protocols
174 * and not mess up with C verifiers.
176 * ftrace_ops_list_func will be defined as arch_ftrace_ops_list_func
177 * as some archs will have a different prototype for that function
178 * but ftrace_ops_list_func() will have a single prototype.
180 #define MCOUNT_REC() . = ALIGN(8); \
181 __start_mcount_loc = .; \
182 KEEP(*(__mcount_loc)) \
184 __stop_mcount_loc = .; \
185 ftrace_stub_graph = ftrace_stub; \
186 ftrace_ops_list_func = arch_ftrace_ops_list_func;
188 # ifdef CONFIG_FUNCTION_TRACER
189 # define MCOUNT_REC() ftrace_stub_graph = ftrace_stub; \
190 ftrace_ops_list_func = arch_ftrace_ops_list_func;
192 # define MCOUNT_REC()
196 #ifdef CONFIG_TRACE_BRANCH_PROFILING
197 #define LIKELY_PROFILE() __start_annotated_branch_profile = .; \
198 KEEP(*(_ftrace_annotated_branch)) \
199 __stop_annotated_branch_profile = .;
201 #define LIKELY_PROFILE()
204 #ifdef CONFIG_PROFILE_ALL_BRANCHES
205 #define BRANCH_PROFILE() __start_branch_profile = .; \
206 KEEP(*(_ftrace_branch)) \
207 __stop_branch_profile = .;
209 #define BRANCH_PROFILE()
212 #ifdef CONFIG_KPROBES
213 #define KPROBE_BLACKLIST() . = ALIGN(8); \
214 __start_kprobe_blacklist = .; \
215 KEEP(*(_kprobe_blacklist)) \
216 __stop_kprobe_blacklist = .;
218 #define KPROBE_BLACKLIST()
221 #ifdef CONFIG_FUNCTION_ERROR_INJECTION
222 #define ERROR_INJECT_WHITELIST() STRUCT_ALIGN(); \
223 __start_error_injection_whitelist = .; \
224 KEEP(*(_error_injection_whitelist)) \
225 __stop_error_injection_whitelist = .;
227 #define ERROR_INJECT_WHITELIST()
230 #ifdef CONFIG_EVENT_TRACING
231 #define FTRACE_EVENTS() . = ALIGN(8); \
232 __start_ftrace_events = .; \
233 KEEP(*(_ftrace_events)) \
234 __stop_ftrace_events = .; \
235 __start_ftrace_eval_maps = .; \
236 KEEP(*(_ftrace_eval_map)) \
237 __stop_ftrace_eval_maps = .;
239 #define FTRACE_EVENTS()
242 #ifdef CONFIG_TRACING
243 #define TRACE_PRINTKS() __start___trace_bprintk_fmt = .; \
244 KEEP(*(__trace_printk_fmt)) /* Trace_printk fmt' pointer */ \
245 __stop___trace_bprintk_fmt = .;
246 #define TRACEPOINT_STR() __start___tracepoint_str = .; \
247 KEEP(*(__tracepoint_str)) /* Trace_printk fmt' pointer */ \
248 __stop___tracepoint_str = .;
250 #define TRACE_PRINTKS()
251 #define TRACEPOINT_STR()
254 #ifdef CONFIG_FTRACE_SYSCALLS
255 #define TRACE_SYSCALLS() . = ALIGN(8); \
256 __start_syscalls_metadata = .; \
257 KEEP(*(__syscalls_metadata)) \
258 __stop_syscalls_metadata = .;
260 #define TRACE_SYSCALLS()
263 #ifdef CONFIG_BPF_EVENTS
264 #define BPF_RAW_TP() STRUCT_ALIGN(); \
265 __start__bpf_raw_tp = .; \
266 KEEP(*(__bpf_raw_tp_map)) \
267 __stop__bpf_raw_tp = .;
272 #ifdef CONFIG_SERIAL_EARLYCON
273 #define EARLYCON_TABLE() . = ALIGN(8); \
274 __earlycon_table = .; \
275 KEEP(*(__earlycon_table)) \
276 __earlycon_table_end = .;
278 #define EARLYCON_TABLE()
281 #ifdef CONFIG_SECURITY
282 #define LSM_TABLE() . = ALIGN(8); \
283 __start_lsm_info = .; \
284 KEEP(*(.lsm_info.init)) \
286 #define EARLY_LSM_TABLE() . = ALIGN(8); \
287 __start_early_lsm_info = .; \
288 KEEP(*(.early_lsm_info.init)) \
289 __end_early_lsm_info = .;
292 #define EARLY_LSM_TABLE()
295 #define ___OF_TABLE(cfg, name) _OF_TABLE_##cfg(name)
296 #define __OF_TABLE(cfg, name) ___OF_TABLE(cfg, name)
297 #define OF_TABLE(cfg, name) __OF_TABLE(IS_ENABLED(cfg), name)
298 #define _OF_TABLE_0(name)
299 #define _OF_TABLE_1(name) \
301 __##name##_of_table = .; \
302 KEEP(*(__##name##_of_table)) \
303 KEEP(*(__##name##_of_table_end))
305 #define TIMER_OF_TABLES() OF_TABLE(CONFIG_TIMER_OF, timer)
306 #define IRQCHIP_OF_MATCH_TABLE() OF_TABLE(CONFIG_IRQCHIP, irqchip)
307 #define CLK_OF_TABLES() OF_TABLE(CONFIG_COMMON_CLK, clk)
308 #define RESERVEDMEM_OF_TABLES() OF_TABLE(CONFIG_OF_RESERVED_MEM, reservedmem)
309 #define CPU_METHOD_OF_TABLES() OF_TABLE(CONFIG_SMP, cpu_method)
310 #define CPUIDLE_METHOD_OF_TABLES() OF_TABLE(CONFIG_CPU_IDLE, cpuidle_method)
313 #define ACPI_PROBE_TABLE(name) \
315 __##name##_acpi_probe_table = .; \
316 KEEP(*(__##name##_acpi_probe_table)) \
317 __##name##_acpi_probe_table_end = .;
319 #define ACPI_PROBE_TABLE(name)
322 #ifdef CONFIG_THERMAL
323 #define THERMAL_TABLE(name) \
325 __##name##_thermal_table = .; \
326 KEEP(*(__##name##_thermal_table)) \
327 __##name##_thermal_table_end = .;
329 #define THERMAL_TABLE(name)
332 #define KERNEL_DTB() \
335 KEEP(*(.dtb.init.rodata)) \
345 *(.data..shared_aligned) /* percpu related */ \
346 MEM_KEEP(init.data*) \
347 MEM_KEEP(exit.data*) \
354 /* implement dynamic printk debug */ \
356 __start___dyndbg = .; \
358 __stop___dyndbg = .; \
366 * Data section helpers
368 #define NOSAVE_DATA \
369 . = ALIGN(PAGE_SIZE); \
370 __nosave_begin = .; \
372 . = ALIGN(PAGE_SIZE); \
375 #define PAGE_ALIGNED_DATA(page_align) \
376 . = ALIGN(page_align); \
377 *(.data..page_aligned) \
378 . = ALIGN(page_align);
380 #define READ_MOSTLY_DATA(align) \
382 *(.data..read_mostly) \
385 #define CACHELINE_ALIGNED_DATA(align) \
387 *(.data..cacheline_aligned)
389 #define INIT_TASK_DATA(align) \
391 __start_init_task = .; \
392 init_thread_union = .; \
394 KEEP(*(.data..init_task)) \
395 KEEP(*(.data..init_thread_info)) \
396 . = __start_init_task + THREAD_SIZE; \
399 #define JUMP_TABLE_DATA \
401 __start___jump_table = .; \
402 KEEP(*(__jump_table)) \
403 __stop___jump_table = .;
405 #ifdef CONFIG_HAVE_STATIC_CALL_INLINE
406 #define STATIC_CALL_DATA \
408 __start_static_call_sites = .; \
409 KEEP(*(.static_call_sites)) \
410 __stop_static_call_sites = .; \
411 __start_static_call_tramp_key = .; \
412 KEEP(*(.static_call_tramp_key)) \
413 __stop_static_call_tramp_key = .;
415 #define STATIC_CALL_DATA
419 * Allow architectures to handle ro_after_init data on their
420 * own by defining an empty RO_AFTER_INIT_DATA.
422 #ifndef RO_AFTER_INIT_DATA
423 #define RO_AFTER_INIT_DATA \
425 __start_ro_after_init = .; \
426 *(.data..ro_after_init) \
429 __end_ro_after_init = .;
433 * .kcfi_traps contains a list KCFI trap locations.
436 #ifdef CONFIG_ARCH_USES_CFI_TRAPS
438 __kcfi_traps : AT(ADDR(__kcfi_traps) - LOAD_OFFSET) { \
439 __start___kcfi_traps = .; \
440 KEEP(*(.kcfi_traps)) \
441 __stop___kcfi_traps = .; \
451 #define RO_DATA(align) \
452 . = ALIGN((align)); \
453 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
454 __start_rodata = .; \
455 *(.rodata) *(.rodata.*) \
457 RO_AFTER_INIT_DATA /* Read only after init */ \
459 __start___tracepoints_ptrs = .; \
460 KEEP(*(__tracepoints_ptrs)) /* Tracepoints: pointer array */ \
461 __stop___tracepoints_ptrs = .; \
462 *(__tracepoints_strings)/* Tracepoints: strings */ \
465 .rodata1 : AT(ADDR(.rodata1) - LOAD_OFFSET) { \
470 .pci_fixup : AT(ADDR(.pci_fixup) - LOAD_OFFSET) { \
471 __start_pci_fixups_early = .; \
472 KEEP(*(.pci_fixup_early)) \
473 __end_pci_fixups_early = .; \
474 __start_pci_fixups_header = .; \
475 KEEP(*(.pci_fixup_header)) \
476 __end_pci_fixups_header = .; \
477 __start_pci_fixups_final = .; \
478 KEEP(*(.pci_fixup_final)) \
479 __end_pci_fixups_final = .; \
480 __start_pci_fixups_enable = .; \
481 KEEP(*(.pci_fixup_enable)) \
482 __end_pci_fixups_enable = .; \
483 __start_pci_fixups_resume = .; \
484 KEEP(*(.pci_fixup_resume)) \
485 __end_pci_fixups_resume = .; \
486 __start_pci_fixups_resume_early = .; \
487 KEEP(*(.pci_fixup_resume_early)) \
488 __end_pci_fixups_resume_early = .; \
489 __start_pci_fixups_suspend = .; \
490 KEEP(*(.pci_fixup_suspend)) \
491 __end_pci_fixups_suspend = .; \
492 __start_pci_fixups_suspend_late = .; \
493 KEEP(*(.pci_fixup_suspend_late)) \
494 __end_pci_fixups_suspend_late = .; \
497 FW_LOADER_BUILT_IN_DATA \
502 /* Kernel symbol table: Normal symbols */ \
503 __ksymtab : AT(ADDR(__ksymtab) - LOAD_OFFSET) { \
504 __start___ksymtab = .; \
505 KEEP(*(SORT(___ksymtab+*))) \
506 __stop___ksymtab = .; \
509 /* Kernel symbol table: GPL-only symbols */ \
510 __ksymtab_gpl : AT(ADDR(__ksymtab_gpl) - LOAD_OFFSET) { \
511 __start___ksymtab_gpl = .; \
512 KEEP(*(SORT(___ksymtab_gpl+*))) \
513 __stop___ksymtab_gpl = .; \
516 /* Kernel symbol table: Normal symbols */ \
517 __kcrctab : AT(ADDR(__kcrctab) - LOAD_OFFSET) { \
518 __start___kcrctab = .; \
519 KEEP(*(SORT(___kcrctab+*))) \
520 __stop___kcrctab = .; \
523 /* Kernel symbol table: GPL-only symbols */ \
524 __kcrctab_gpl : AT(ADDR(__kcrctab_gpl) - LOAD_OFFSET) { \
525 __start___kcrctab_gpl = .; \
526 KEEP(*(SORT(___kcrctab_gpl+*))) \
527 __stop___kcrctab_gpl = .; \
530 /* Kernel symbol table: strings */ \
531 __ksymtab_strings : AT(ADDR(__ksymtab_strings) - LOAD_OFFSET) { \
532 *(__ksymtab_strings) \
535 /* __*init sections */ \
536 __init_rodata : AT(ADDR(__init_rodata) - LOAD_OFFSET) { \
538 MEM_KEEP(init.rodata) \
539 MEM_KEEP(exit.rodata) \
542 /* Built-in module parameters. */ \
543 __param : AT(ADDR(__param) - LOAD_OFFSET) { \
544 __start___param = .; \
546 __stop___param = .; \
549 /* Built-in module versions. */ \
550 __modver : AT(ADDR(__modver) - LOAD_OFFSET) { \
551 __start___modver = .; \
553 __stop___modver = .; \
562 . = ALIGN((align)); \
567 * Non-instrumentable text section
569 #define NOINSTR_TEXT \
571 __noinstr_text_start = .; \
573 __noinstr_text_end = .;
576 * .text section. Map to function alignment to avoid address changes
577 * during second ld run in second ld pass when generating System.map
579 * TEXT_MAIN here will match .text.fixup and .text.unlikely if dead
580 * code elimination is enabled, so these sections should be converted
585 *(.text.hot .text.hot.*) \
586 *(TEXT_MAIN .text.fixup) \
587 *(.text.unlikely .text.unlikely.*) \
588 *(.text.unknown .text.unknown.*) \
592 *(.text.asan.* .text.tsan.*) \
593 MEM_KEEP(init.text*) \
594 MEM_KEEP(exit.text*) \
597 /* sched.text is aling to function alignment to secure we have same
598 * address even at second ld pass when generating System.map */
601 __sched_text_start = .; \
603 __sched_text_end = .;
605 /* spinlock.text is aling to function alignment to secure we have same
606 * address even at second ld pass when generating System.map */
609 __lock_text_start = .; \
613 #define CPUIDLE_TEXT \
615 __cpuidle_text_start = .; \
617 __cpuidle_text_end = .;
619 #define KPROBES_TEXT \
621 __kprobes_text_start = .; \
623 __kprobes_text_end = .;
627 __entry_text_start = .; \
629 __entry_text_end = .;
631 #define IRQENTRY_TEXT \
633 __irqentry_text_start = .; \
635 __irqentry_text_end = .;
637 #define SOFTIRQENTRY_TEXT \
639 __softirqentry_text_start = .; \
640 *(.softirqentry.text) \
641 __softirqentry_text_end = .;
643 #define STATIC_CALL_TEXT \
645 __static_call_text_start = .; \
646 *(.static_call.text) \
647 __static_call_text_end = .;
649 /* Section used for early init (in .S files) */
650 #define HEAD_TEXT KEEP(*(.head.text))
652 #define HEAD_TEXT_SECTION \
653 .head.text : AT(ADDR(.head.text) - LOAD_OFFSET) { \
660 #define EXCEPTION_TABLE(align) \
662 __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { \
663 __start___ex_table = .; \
664 KEEP(*(__ex_table)) \
665 __stop___ex_table = .; \
671 #ifdef CONFIG_DEBUG_INFO_BTF
673 .BTF : AT(ADDR(.BTF) - LOAD_OFFSET) { \
679 .BTF_ids : AT(ADDR(.BTF_ids) - LOAD_OFFSET) { \
689 #define INIT_TASK_DATA_SECTION(align) \
691 .data..init_task : AT(ADDR(.data..init_task) - LOAD_OFFSET) { \
692 INIT_TASK_DATA(align) \
695 #ifdef CONFIG_CONSTRUCTORS
696 #define KERNEL_CTORS() . = ALIGN(8); \
698 KEEP(*(SORT(.ctors.*))) \
700 KEEP(*(SORT(.init_array.*))) \
701 KEEP(*(.init_array)) \
704 #define KERNEL_CTORS()
707 /* init and exit section handling */
709 KEEP(*(SORT(___kentry+*))) \
710 *(.init.data init.data.*) \
711 MEM_DISCARD(init.data*) \
714 *(.init.rodata .init.rodata.*) \
718 ERROR_INJECT_WHITELIST() \
719 MEM_DISCARD(init.rodata) \
721 RESERVEDMEM_OF_TABLES() \
723 CPU_METHOD_OF_TABLES() \
724 CPUIDLE_METHOD_OF_TABLES() \
726 IRQCHIP_OF_MATCH_TABLE() \
727 ACPI_PROBE_TABLE(irqchip) \
728 ACPI_PROBE_TABLE(timer) \
729 THERMAL_TABLE(governor) \
736 *(.init.text .init.text.*) \
738 MEM_DISCARD(init.text*)
741 *(.exit.data .exit.data.*) \
742 *(.fini_array .fini_array.*) \
744 MEM_DISCARD(exit.data*) \
745 MEM_DISCARD(exit.rodata*)
750 MEM_DISCARD(exit.text)
756 * bss (Block Started by Symbol) - uninitialized data
757 * zeroed during startup
759 #define SBSS(sbss_align) \
760 . = ALIGN(sbss_align); \
761 .sbss : AT(ADDR(.sbss) - LOAD_OFFSET) { \
768 * Allow archectures to redefine BSS_FIRST_SECTIONS to add extra
769 * sections to the front of bss.
771 #ifndef BSS_FIRST_SECTIONS
772 #define BSS_FIRST_SECTIONS
775 #define BSS(bss_align) \
776 . = ALIGN(bss_align); \
777 .bss : AT(ADDR(.bss) - LOAD_OFFSET) { \
779 . = ALIGN(PAGE_SIZE); \
780 *(.bss..page_aligned) \
781 . = ALIGN(PAGE_SIZE); \
788 * DWARF debug sections.
789 * Symbols in the DWARF debugging sections are relative to
790 * the beginning of the section so we begin them at 0.
792 #define DWARF_DEBUG \
794 .debug 0 : { *(.debug) } \
795 .line 0 : { *(.line) } \
796 /* GNU DWARF 1 extensions */ \
797 .debug_srcinfo 0 : { *(.debug_srcinfo) } \
798 .debug_sfnames 0 : { *(.debug_sfnames) } \
799 /* DWARF 1.1 and DWARF 2 */ \
800 .debug_aranges 0 : { *(.debug_aranges) } \
801 .debug_pubnames 0 : { *(.debug_pubnames) } \
803 .debug_info 0 : { *(.debug_info \
804 .gnu.linkonce.wi.*) } \
805 .debug_abbrev 0 : { *(.debug_abbrev) } \
806 .debug_line 0 : { *(.debug_line) } \
807 .debug_frame 0 : { *(.debug_frame) } \
808 .debug_str 0 : { *(.debug_str) } \
809 .debug_loc 0 : { *(.debug_loc) } \
810 .debug_macinfo 0 : { *(.debug_macinfo) } \
811 .debug_pubtypes 0 : { *(.debug_pubtypes) } \
813 .debug_ranges 0 : { *(.debug_ranges) } \
814 /* SGI/MIPS DWARF 2 extensions */ \
815 .debug_weaknames 0 : { *(.debug_weaknames) } \
816 .debug_funcnames 0 : { *(.debug_funcnames) } \
817 .debug_typenames 0 : { *(.debug_typenames) } \
818 .debug_varnames 0 : { *(.debug_varnames) } \
819 /* GNU DWARF 2 extensions */ \
820 .debug_gnu_pubnames 0 : { *(.debug_gnu_pubnames) } \
821 .debug_gnu_pubtypes 0 : { *(.debug_gnu_pubtypes) } \
823 .debug_types 0 : { *(.debug_types) } \
825 .debug_addr 0 : { *(.debug_addr) } \
826 .debug_line_str 0 : { *(.debug_line_str) } \
827 .debug_loclists 0 : { *(.debug_loclists) } \
828 .debug_macro 0 : { *(.debug_macro) } \
829 .debug_names 0 : { *(.debug_names) } \
830 .debug_rnglists 0 : { *(.debug_rnglists) } \
831 .debug_str_offsets 0 : { *(.debug_str_offsets) }
833 /* Stabs debugging sections. */
834 #define STABS_DEBUG \
835 .stab 0 : { *(.stab) } \
836 .stabstr 0 : { *(.stabstr) } \
837 .stab.excl 0 : { *(.stab.excl) } \
838 .stab.exclstr 0 : { *(.stab.exclstr) } \
839 .stab.index 0 : { *(.stab.index) } \
840 .stab.indexstr 0 : { *(.stab.indexstr) }
842 /* Required sections not related to debugging. */
843 #define ELF_DETAILS \
844 .comment 0 : { *(.comment) } \
845 .symtab 0 : { *(.symtab) } \
846 .strtab 0 : { *(.strtab) } \
847 .shstrtab 0 : { *(.shstrtab) }
849 #ifdef CONFIG_GENERIC_BUG
852 __bug_table : AT(ADDR(__bug_table) - LOAD_OFFSET) { \
853 __start___bug_table = .; \
854 KEEP(*(__bug_table)) \
855 __stop___bug_table = .; \
861 #ifdef CONFIG_UNWINDER_ORC
862 #define ORC_UNWIND_TABLE \
864 .orc_unwind_ip : AT(ADDR(.orc_unwind_ip) - LOAD_OFFSET) { \
865 __start_orc_unwind_ip = .; \
866 KEEP(*(.orc_unwind_ip)) \
867 __stop_orc_unwind_ip = .; \
870 .orc_unwind : AT(ADDR(.orc_unwind) - LOAD_OFFSET) { \
871 __start_orc_unwind = .; \
872 KEEP(*(.orc_unwind)) \
873 __stop_orc_unwind = .; \
875 text_size = _etext - _stext; \
877 .orc_lookup : AT(ADDR(.orc_lookup) - LOAD_OFFSET) { \
879 . += (((text_size + LOOKUP_BLOCK_SIZE - 1) / \
880 LOOKUP_BLOCK_SIZE) + 1) * 4; \
881 orc_lookup_end = .; \
884 #define ORC_UNWIND_TABLE
887 /* Built-in firmware blobs */
888 #ifdef CONFIG_FW_LOADER
889 #define FW_LOADER_BUILT_IN_DATA \
890 .builtin_fw : AT(ADDR(.builtin_fw) - LOAD_OFFSET) ALIGN(8) { \
891 __start_builtin_fw = .; \
892 KEEP(*(.builtin_fw)) \
893 __end_builtin_fw = .; \
896 #define FW_LOADER_BUILT_IN_DATA
899 #ifdef CONFIG_PM_TRACE
902 .tracedata : AT(ADDR(.tracedata) - LOAD_OFFSET) { \
903 __tracedata_start = .; \
904 KEEP(*(.tracedata)) \
905 __tracedata_end = .; \
911 #ifdef CONFIG_PRINTK_INDEX
912 #define PRINTK_INDEX \
913 .printk_index : AT(ADDR(.printk_index) - LOAD_OFFSET) { \
914 __start_printk_index = .; \
916 __stop_printk_index = .; \
923 .notes : AT(ADDR(.notes) - LOAD_OFFSET) { \
928 NOTES_HEADERS_RESTORE
930 #define INIT_SETUP(initsetup_align) \
931 . = ALIGN(initsetup_align); \
933 KEEP(*(.init.setup)) \
936 #define INIT_CALLS_LEVEL(level) \
937 __initcall##level##_start = .; \
938 KEEP(*(.initcall##level##.init)) \
939 KEEP(*(.initcall##level##s.init)) \
942 __initcall_start = .; \
943 KEEP(*(.initcallearly.init)) \
944 INIT_CALLS_LEVEL(0) \
945 INIT_CALLS_LEVEL(1) \
946 INIT_CALLS_LEVEL(2) \
947 INIT_CALLS_LEVEL(3) \
948 INIT_CALLS_LEVEL(4) \
949 INIT_CALLS_LEVEL(5) \
950 INIT_CALLS_LEVEL(rootfs) \
951 INIT_CALLS_LEVEL(6) \
952 INIT_CALLS_LEVEL(7) \
955 #define CON_INITCALL \
956 __con_initcall_start = .; \
957 KEEP(*(.con_initcall.init)) \
958 __con_initcall_end = .;
960 /* Alignment must be consistent with (kunit_suite *) in include/kunit/test.h */
961 #define KUNIT_TABLE() \
963 __kunit_suites_start = .; \
964 KEEP(*(.kunit_test_suites)) \
965 __kunit_suites_end = .;
967 #ifdef CONFIG_BLK_DEV_INITRD
968 #define INIT_RAM_FS \
970 __initramfs_start = .; \
971 KEEP(*(.init.ramfs)) \
973 KEEP(*(.init.ramfs.info))
979 * Memory encryption operates on a page basis. Since we need to clear
980 * the memory encryption mask for this section, it needs to be aligned
981 * on a page boundary and be a page-size multiple in length.
983 * Note: We use a separate section so that only this section gets
984 * decrypted to avoid exposing more than we wish.
986 #ifdef CONFIG_AMD_MEM_ENCRYPT
987 #define PERCPU_DECRYPTED_SECTION \
988 . = ALIGN(PAGE_SIZE); \
989 *(.data..decrypted) \
990 *(.data..percpu..decrypted) \
991 . = ALIGN(PAGE_SIZE);
993 #define PERCPU_DECRYPTED_SECTION
998 * Default discarded sections.
1000 * Some archs want to discard exit text/data at runtime rather than
1001 * link time due to cross-section references such as alt instructions,
1002 * bug table, eh_frame, etc. DISCARDS must be the last of output
1003 * section definitions so that such archs put those in earlier section
1006 #ifdef RUNTIME_DISCARD_EXIT
1007 #define EXIT_DISCARDS
1009 #define EXIT_DISCARDS \
1015 * Clang's -fprofile-arcs, -fsanitize=kernel-address, and
1016 * -fsanitize=thread produce unwanted sections (.eh_frame
1017 * and .init_array.*), but CONFIG_CONSTRUCTORS wants to
1018 * keep any .init_array.* sections.
1019 * https://bugs.llvm.org/show_bug.cgi?id=46478
1021 #if defined(CONFIG_GCOV_KERNEL) || defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KCSAN)
1022 # ifdef CONFIG_CONSTRUCTORS
1023 # define SANITIZER_DISCARDS \
1026 # define SANITIZER_DISCARDS \
1027 *(.init_array) *(.init_array.*) \
1031 # define SANITIZER_DISCARDS
1034 #define COMMON_DISCARDS \
1035 SANITIZER_DISCARDS \
1036 PATCHABLE_DISCARDS \
1040 /* ld.bfd warns about .gnu.version* even when not emitted */ \
1051 * PERCPU_INPUT - the percpu input sections
1052 * @cacheline: cacheline size
1054 * The core percpu section names and core symbols which do not rely
1055 * directly upon load addresses.
1057 * @cacheline is used to align subsections to avoid false cacheline
1058 * sharing between subsections for different purposes.
1060 #define PERCPU_INPUT(cacheline) \
1061 __per_cpu_start = .; \
1062 *(.data..percpu..first) \
1063 . = ALIGN(PAGE_SIZE); \
1064 *(.data..percpu..page_aligned) \
1065 . = ALIGN(cacheline); \
1066 *(.data..percpu..read_mostly) \
1067 . = ALIGN(cacheline); \
1069 *(.data..percpu..shared_aligned) \
1070 PERCPU_DECRYPTED_SECTION \
1074 * PERCPU_VADDR - define output section for percpu area
1075 * @cacheline: cacheline size
1076 * @vaddr: explicit base address (optional)
1077 * @phdr: destination PHDR (optional)
1079 * Macro which expands to output section for percpu area.
1081 * @cacheline is used to align subsections to avoid false cacheline
1082 * sharing between subsections for different purposes.
1084 * If @vaddr is not blank, it specifies explicit base address and all
1085 * percpu symbols will be offset from the given address. If blank,
1086 * @vaddr always equals @laddr + LOAD_OFFSET.
1088 * @phdr defines the output PHDR to use if not blank. Be warned that
1089 * output PHDR is sticky. If @phdr is specified, the next output
1090 * section in the linker script will go there too. @phdr should have
1093 * Note that this macros defines __per_cpu_load as an absolute symbol.
1094 * If there is no need to put the percpu section at a predetermined
1095 * address, use PERCPU_SECTION.
1097 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
1098 __per_cpu_load = .; \
1099 .data..percpu vaddr : AT(__per_cpu_load - LOAD_OFFSET) { \
1100 PERCPU_INPUT(cacheline) \
1102 . = __per_cpu_load + SIZEOF(.data..percpu);
1105 * PERCPU_SECTION - define output section for percpu area, simple version
1106 * @cacheline: cacheline size
1108 * Align to PAGE_SIZE and outputs output section for percpu area. This
1109 * macro doesn't manipulate @vaddr or @phdr and __per_cpu_load and
1110 * __per_cpu_start will be identical.
1112 * This macro is equivalent to ALIGN(PAGE_SIZE); PERCPU_VADDR(@cacheline,,)
1113 * except that __per_cpu_load is defined as a relative symbol against
1114 * .data..percpu which is required for relocatable x86_32 configuration.
1116 #define PERCPU_SECTION(cacheline) \
1117 . = ALIGN(PAGE_SIZE); \
1118 .data..percpu : AT(ADDR(.data..percpu) - LOAD_OFFSET) { \
1119 __per_cpu_load = .; \
1120 PERCPU_INPUT(cacheline) \
1125 * Definition of the high level *_SECTION macros
1126 * They will fit only a subset of the architectures
1132 * All sections are combined in a single .data section.
1133 * The sections following CONSTRUCTORS are arranged so their
1134 * typical alignment matches.
1135 * A cacheline is typical/always less than a PAGE_SIZE so
1136 * the sections that has this restriction (or similar)
1137 * is located before the ones requiring PAGE_SIZE alignment.
1138 * NOSAVE_DATA starts and ends with a PAGE_SIZE alignment which
1139 * matches the requirement of PAGE_ALIGNED_DATA.
1141 * use 0 as page_align if page_aligned data is not used */
1142 #define RW_DATA(cacheline, pagealigned, inittask) \
1143 . = ALIGN(PAGE_SIZE); \
1144 .data : AT(ADDR(.data) - LOAD_OFFSET) { \
1145 INIT_TASK_DATA(inittask) \
1147 PAGE_ALIGNED_DATA(pagealigned) \
1148 CACHELINE_ALIGNED_DATA(cacheline) \
1149 READ_MOSTLY_DATA(cacheline) \
1155 #define INIT_TEXT_SECTION(inittext_align) \
1156 . = ALIGN(inittext_align); \
1157 .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) { \
1163 #define INIT_DATA_SECTION(initsetup_align) \
1164 .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) { \
1166 INIT_SETUP(initsetup_align) \
1172 #define BSS_SECTION(sbss_align, bss_align, stop_align) \
1173 . = ALIGN(sbss_align); \
1177 . = ALIGN(stop_align); \