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