hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/include/asm-generic/vmlinux.lds.h
....@@ -23,18 +23,18 @@
2323 * _etext = .;
2424 *
2525 * _sdata = .;
26
- * RO_DATA_SECTION(PAGE_SIZE)
27
- * RW_DATA_SECTION(...)
26
+ * RO_DATA(PAGE_SIZE)
27
+ * RW_DATA(...)
2828 * _edata = .;
2929 *
3030 * EXCEPTION_TABLE(...)
31
- * NOTES
3231 *
3332 * BSS_SECTION(0, 0, 0)
3433 * _end = .;
3534 *
3635 * STABS_DEBUG
3736 * DWARF_DEBUG
37
+ * ELF_DETAILS
3838 *
3939 * DISCARDS // must be the last
4040 * }
....@@ -54,6 +54,33 @@
5454 #define LOAD_OFFSET 0
5555 #endif
5656
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
+
5784 /* Align . to a 8 byte boundary equals to maximum function alignment. */
5885 #define ALIGN_FUNCTION() . = ALIGN(8)
5986
....@@ -63,12 +90,14 @@
6390 * .data. We don't want to pull in .data..other sections, which Linux
6491 * has defined. Same for text and bss.
6592 *
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.
95
+ *
6696 * RODATA_MAIN is not used because existing code already defines .rodata.x
6797 * sections to be brought in with rodata.
6898 */
6999 #if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || defined(CONFIG_LTO_CLANG)
70100 #define TEXT_MAIN .text .text.[0-9a-zA-Z_]*
71
-#define TEXT_CFI_MAIN .text.[0-9a-zA-Z_]*.cfi
72101 #define DATA_MAIN .data .data.[0-9a-zA-Z_]* .data..L* .data..compoundliteral*
73102 #define SDATA_MAIN .sdata .sdata.[0-9a-zA-Z_]*
74103 #define RODATA_MAIN .rodata .rodata.[0-9a-zA-Z_]* .rodata..L*
....@@ -76,7 +105,6 @@
76105 #define SBSS_MAIN .sbss .sbss.[0-9a-zA-Z_]*
77106 #else
78107 #define TEXT_MAIN .text
79
-#define TEXT_CFI_MAIN .text.cfi
80108 #define DATA_MAIN .data
81109 #define SDATA_MAIN .sdata
82110 #define RODATA_MAIN .rodata
....@@ -85,11 +113,30 @@
85113 #endif
86114
87115 /*
88
- * Align to a 32 byte boundary equal to the
89
- * alignment gcc 4.5 uses for a struct
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.
90118 */
119
+#if __GNUC__ == 4 && __GNUC_MINOR__ == 9
120
+#define STRUCT_ALIGNMENT 64
121
+#else
91122 #define STRUCT_ALIGNMENT 32
123
+#endif
92124 #define STRUCT_ALIGN() . = ALIGN(STRUCT_ALIGNMENT)
125
+
126
+/*
127
+ * The order of the sched class addresses are important, as they are
128
+ * used to determine the order of the priority of each sched class in
129
+ * relation to each other.
130
+ */
131
+#define SCHED_DATA \
132
+ STRUCT_ALIGN(); \
133
+ __begin_sched_classes = .; \
134
+ *(__idle_sched_class) \
135
+ *(__fair_sched_class) \
136
+ *(__rt_sched_class) \
137
+ *(__dl_sched_class) \
138
+ *(__stop_sched_class) \
139
+ __end_sched_classes = .;
93140
94141 /* The actual configuration determine if the init/exit sections
95142 * are handled as text/data or they can be discarded (which
....@@ -112,12 +159,28 @@
112159 #endif
113160
114161 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
162
+/*
163
+ * The ftrace call sites are logged to a section whose name depends on the
164
+ * compiler option used. A given kernel image will only use one, AKA
165
+ * FTRACE_CALLSITE_SECTION. We capture all of them here to avoid header
166
+ * dependencies for FTRACE_CALLSITE_SECTION's definition.
167
+ *
168
+ * Need to also make ftrace_stub_graph point to ftrace_stub
169
+ * so that the same stub location may have different protocols
170
+ * and not mess up with C verifiers.
171
+ */
115172 #define MCOUNT_REC() . = ALIGN(8); \
116173 __start_mcount_loc = .; \
117174 KEEP(*(__mcount_loc)) \
118
- __stop_mcount_loc = .;
175
+ KEEP(*(__patchable_function_entries)) \
176
+ __stop_mcount_loc = .; \
177
+ ftrace_stub_graph = ftrace_stub;
119178 #else
120
-#define MCOUNT_REC()
179
+# ifdef CONFIG_FUNCTION_TRACER
180
+# define MCOUNT_REC() ftrace_stub_graph = ftrace_stub;
181
+# else
182
+# define MCOUNT_REC()
183
+# endif
121184 #endif
122185
123186 #ifdef CONFIG_TRACE_BRANCH_PROFILING
....@@ -205,6 +268,20 @@
205268 #define EARLYCON_TABLE()
206269 #endif
207270
271
+#ifdef CONFIG_SECURITY
272
+#define LSM_TABLE() . = ALIGN(8); \
273
+ __start_lsm_info = .; \
274
+ KEEP(*(.lsm_info.init)) \
275
+ __end_lsm_info = .;
276
+#define EARLY_LSM_TABLE() . = ALIGN(8); \
277
+ __start_early_lsm_info = .; \
278
+ KEEP(*(.early_lsm_info.init)) \
279
+ __end_early_lsm_info = .;
280
+#else
281
+#define LSM_TABLE()
282
+#define EARLY_LSM_TABLE()
283
+#endif
284
+
208285 #define ___OF_TABLE(cfg, name) _OF_TABLE_##cfg(name)
209286 #define __OF_TABLE(cfg, name) ___OF_TABLE(cfg, name)
210287 #define OF_TABLE(cfg, name) __OF_TABLE(IS_ENABLED(cfg), name)
....@@ -232,6 +309,26 @@
232309 #define ACPI_PROBE_TABLE(name)
233310 #endif
234311
312
+#ifdef CONFIG_THERMAL
313
+#define THERMAL_TABLE(name) \
314
+ . = ALIGN(8); \
315
+ __##name##_thermal_table = .; \
316
+ KEEP(*(__##name##_thermal_table)) \
317
+ __##name##_thermal_table_end = .;
318
+#else
319
+#define THERMAL_TABLE(name)
320
+#endif
321
+
322
+#ifdef CONFIG_DTPM
323
+#define DTPM_TABLE() \
324
+ . = ALIGN(8); \
325
+ __dtpm_table = .; \
326
+ KEEP(*(__dtpm_table)) \
327
+ __dtpm_table_end = .;
328
+#else
329
+#define DTPM_TABLE()
330
+#endif
331
+
235332 #define KERNEL_DTB() \
236333 STRUCT_ALIGN(); \
237334 __dtb_start = .; \
....@@ -244,6 +341,7 @@
244341 #define DATA_DATA \
245342 *(.xiptext) \
246343 *(DATA_MAIN) \
344
+ *(.data..decrypted) \
247345 *(.ref.data) \
248346 *(.data..shared_aligned) /* percpu related */ \
249347 MEM_KEEP(init.data*) \
....@@ -255,14 +353,10 @@
255353 STRUCT_ALIGN(); \
256354 *(__tracepoints) \
257355 /* implement dynamic printk debug */ \
258
- . = ALIGN(8); \
259
- __start___jump_table = .; \
260
- KEEP(*(__jump_table)) \
261
- __stop___jump_table = .; \
262356 . = ALIGN(8); \
263
- __start___verbose = .; \
264
- KEEP(*(__verbose)) \
265
- __stop___verbose = .; \
357
+ __start___dyndbg = .; \
358
+ KEEP(*(__dyndbg)) \
359
+ __stop___dyndbg = .; \
266360 LIKELY_PROFILE() \
267361 BRANCH_PROFILE() \
268362 TRACE_PRINTKS() \
....@@ -303,6 +397,21 @@
303397 . = __start_init_task + THREAD_SIZE; \
304398 __end_init_task = .;
305399
400
+#define JUMP_TABLE_DATA \
401
+ . = ALIGN(8); \
402
+ __start___jump_table = .; \
403
+ KEEP(*(__jump_table)) \
404
+ __stop___jump_table = .;
405
+
406
+#define STATIC_CALL_DATA \
407
+ . = ALIGN(8); \
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 = .;
414
+
306415 /*
307416 * Allow architectures to handle ro_after_init data on their
308417 * own by defining an empty RO_AFTER_INIT_DATA.
....@@ -312,19 +421,21 @@
312421 . = ALIGN(8); \
313422 __start_ro_after_init = .; \
314423 *(.data..ro_after_init) \
424
+ JUMP_TABLE_DATA \
425
+ STATIC_CALL_DATA \
315426 __end_ro_after_init = .;
316427 #endif
317428
318429 /*
319430 * Read only Data
320431 */
321
-#define RO_DATA_SECTION(align) \
432
+#define RO_DATA(align) \
322433 . = ALIGN((align)); \
323434 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
324435 __start_rodata = .; \
325436 *(.rodata) *(.rodata.*) \
437
+ SCHED_DATA \
326438 RO_AFTER_INIT_DATA /* Read only after init */ \
327
- KEEP(*(__vermagic)) /* Kernel version magic */ \
328439 . = ALIGN(8); \
329440 __start___tracepoints_ptrs = .; \
330441 KEEP(*(__tracepoints_ptrs)) /* Tracepoints: pointer array */ \
....@@ -467,22 +578,30 @@
467578 __start___modver = .; \
468579 KEEP(*(__modver)) \
469580 __stop___modver = .; \
470
- . = ALIGN((align)); \
471
- __end_rodata = .; \
472581 } \
473
- . = ALIGN((align));
582
+ \
583
+ RO_EXCEPTION_TABLE \
584
+ NOTES \
585
+ BTF \
586
+ \
587
+ . = ALIGN((align)); \
588
+ __end_rodata = .;
474589
475
-/* RODATA & RO_DATA provided for backward compatibility.
476
- * All archs are supposed to use RO_DATA() */
477
-#define RODATA RO_DATA_SECTION(4096)
478
-#define RO_DATA(align) RO_DATA_SECTION(align)
479590
480
-#define SECURITY_INIT \
481
- .security_initcall.init : AT(ADDR(.security_initcall.init) - LOAD_OFFSET) { \
482
- __security_initcall_start = .; \
483
- KEEP(*(.security_initcall.init)) \
484
- __security_initcall_end = .; \
485
- }
591
+/*
592
+ * .text..L.cfi.jumptable.* contain Control-Flow Integrity (CFI)
593
+ * jump table entries.
594
+ */
595
+#ifdef CONFIG_CFI_CLANG
596
+#define TEXT_CFI_JT \
597
+ . = ALIGN(PMD_SIZE); \
598
+ __cfi_jt_start = .; \
599
+ *(.text..L.cfi.jumptable .text..L.cfi.jumptable.*) \
600
+ . = ALIGN(PMD_SIZE); \
601
+ __cfi_jt_end = .;
602
+#else
603
+#define TEXT_CFI_JT
604
+#endif
486605
487606 /*
488607 * Non-instrumentable text section
....@@ -507,12 +626,11 @@
507626 *(TEXT_MAIN .text.fixup) \
508627 *(.text.unlikely .text.unlikely.*) \
509628 *(.text.unknown .text.unknown.*) \
510
- *(TEXT_CFI_MAIN) \
511629 NOINSTR_TEXT \
512630 *(.text..refcount) \
513
- *(.text..ftrace) \
514631 *(.ref.text) \
515632 *(.text.asan.* .text.tsan.*) \
633
+ TEXT_CFI_JT \
516634 MEM_KEEP(init.text*) \
517635 MEM_KEEP(exit.text*) \
518636
....@@ -563,6 +681,12 @@
563681 *(.softirqentry.text) \
564682 __softirqentry_text_end = .;
565683
684
+#define STATIC_CALL_TEXT \
685
+ ALIGN_FUNCTION(); \
686
+ __static_call_text_start = .; \
687
+ *(.static_call.text) \
688
+ __static_call_text_end = .;
689
+
566690 /* Section used for early init (in .S files) */
567691 #define HEAD_TEXT KEEP(*(.head.text))
568692
....@@ -583,6 +707,24 @@
583707 }
584708
585709 /*
710
+ * .BTF
711
+ */
712
+#ifdef CONFIG_DEBUG_INFO_BTF
713
+#define BTF \
714
+ .BTF : AT(ADDR(.BTF) - LOAD_OFFSET) { \
715
+ __start_BTF = .; \
716
+ KEEP(*(.BTF)) \
717
+ __stop_BTF = .; \
718
+ } \
719
+ . = ALIGN(4); \
720
+ .BTF_ids : AT(ADDR(.BTF_ids) - LOAD_OFFSET) { \
721
+ *(.BTF_ids) \
722
+ }
723
+#else
724
+#define BTF
725
+#endif
726
+
727
+/*
586728 * Init task
587729 */
588730 #define INIT_TASK_DATA_SECTION(align) \
....@@ -594,6 +736,7 @@
594736 #ifdef CONFIG_CONSTRUCTORS
595737 #define KERNEL_CTORS() . = ALIGN(8); \
596738 __ctors_start = .; \
739
+ KEEP(*(SORT(.ctors.*))) \
597740 KEEP(*(.ctors)) \
598741 KEEP(*(SORT(.init_array.*))) \
599742 KEEP(*(.init_array)) \
....@@ -624,7 +767,12 @@
624767 IRQCHIP_OF_MATCH_TABLE() \
625768 ACPI_PROBE_TABLE(irqchip) \
626769 ACPI_PROBE_TABLE(timer) \
627
- EARLYCON_TABLE()
770
+ THERMAL_TABLE(governor) \
771
+ DTPM_TABLE() \
772
+ EARLYCON_TABLE() \
773
+ LSM_TABLE() \
774
+ EARLY_LSM_TABLE() \
775
+ KUNIT_TABLE()
628776
629777 #define INIT_TEXT \
630778 *(.init.text .init.text.*) \
....@@ -679,11 +827,21 @@
679827 }
680828
681829 /*
830
+ * Keep .eh_frame with CFI.
831
+ */
832
+#ifdef CONFIG_CFI_CLANG
833
+#define EH_FRAME .eh_frame : { *(.eh_frame) }
834
+#else
835
+#define EH_FRAME
836
+#endif
837
+
838
+/*
682839 * DWARF debug sections.
683840 * Symbols in the DWARF debugging sections are relative to
684841 * the beginning of the section so we begin them at 0.
685842 */
686843 #define DWARF_DEBUG \
844
+ EH_FRAME \
687845 /* DWARF 1 */ \
688846 .debug 0 : { *(.debug) } \
689847 .line 0 : { *(.line) } \
....@@ -724,15 +882,21 @@
724882 .debug_rnglists 0 : { *(.debug_rnglists) } \
725883 .debug_str_offsets 0 : { *(.debug_str_offsets) }
726884
727
- /* Stabs debugging sections. */
885
+/* Stabs debugging sections. */
728886 #define STABS_DEBUG \
729887 .stab 0 : { *(.stab) } \
730888 .stabstr 0 : { *(.stabstr) } \
731889 .stab.excl 0 : { *(.stab.excl) } \
732890 .stab.exclstr 0 : { *(.stab.exclstr) } \
733891 .stab.index 0 : { *(.stab.index) } \
734
- .stab.indexstr 0 : { *(.stab.indexstr) } \
735
- .comment 0 : { *(.comment) }
892
+ .stab.indexstr 0 : { *(.stab.indexstr) }
893
+
894
+/* Required sections not related to debugging. */
895
+#define ELF_DETAILS \
896
+ .comment 0 : { *(.comment) } \
897
+ .symtab 0 : { *(.symtab) } \
898
+ .strtab 0 : { *(.strtab) } \
899
+ .shstrtab 0 : { *(.shstrtab) }
736900
737901 #ifdef CONFIG_GENERIC_BUG
738902 #define BUG_TABLE \
....@@ -783,12 +947,18 @@
783947 #define TRACEDATA
784948 #endif
785949
950
+/*
951
+ * Discard .note.GNU-stack, which is emitted as PROGBITS by the compiler.
952
+ * Otherwise, the type of .notes section would become PROGBITS instead of NOTES.
953
+ */
786954 #define NOTES \
955
+ /DISCARD/ : { *(.note.GNU-stack) } \
787956 .notes : AT(ADDR(.notes) - LOAD_OFFSET) { \
788957 __start_notes = .; \
789958 KEEP(*(.note.*)) \
790959 __stop_notes = .; \
791
- }
960
+ } NOTES_HEADERS \
961
+ NOTES_HEADERS_RESTORE
792962
793963 #define INIT_SETUP(initsetup_align) \
794964 . = ALIGN(initsetup_align); \
....@@ -821,10 +991,12 @@
821991 KEEP(*(.con_initcall.init)) \
822992 __con_initcall_end = .;
823993
824
-#define SECURITY_INITCALL \
825
- __security_initcall_start = .; \
826
- KEEP(*(.security_initcall.init)) \
827
- __security_initcall_end = .;
994
+/* Alignment must be consistent with (kunit_suite *) in include/kunit/test.h */
995
+#define KUNIT_TABLE() \
996
+ . = ALIGN(8); \
997
+ __kunit_suites_start = .; \
998
+ KEEP(*(.kunit_test_suites)) \
999
+ __kunit_suites_end = .;
8281000
8291001 #ifdef CONFIG_BLK_DEV_INITRD
8301002 #define INIT_RAM_FS \
....@@ -848,7 +1020,6 @@
8481020 #ifdef CONFIG_AMD_MEM_ENCRYPT
8491021 #define PERCPU_DECRYPTED_SECTION \
8501022 . = ALIGN(PAGE_SIZE); \
851
- *(.data..decrypted) \
8521023 *(.data..percpu..decrypted) \
8531024 . = ALIGN(PAGE_SIZE);
8541025 #else
....@@ -865,13 +1036,47 @@
8651036 * section definitions so that such archs put those in earlier section
8661037 * definitions.
8671038 */
868
-#define DISCARDS \
869
- /DISCARD/ : { \
1039
+#ifdef RUNTIME_DISCARD_EXIT
1040
+#define EXIT_DISCARDS
1041
+#else
1042
+#define EXIT_DISCARDS \
8701043 EXIT_TEXT \
871
- EXIT_DATA \
872
- EXIT_CALL \
1044
+ EXIT_DATA
1045
+#endif
1046
+
1047
+/*
1048
+ * Clang's -fprofile-arcs, -fsanitize=kernel-address, and
1049
+ * -fsanitize=thread produce unwanted sections (.eh_frame
1050
+ * and .init_array.*), but CONFIG_CONSTRUCTORS wants to
1051
+ * keep any .init_array.* sections.
1052
+ * https://bugs.llvm.org/show_bug.cgi?id=46478
1053
+ */
1054
+#if defined(CONFIG_GCOV_KERNEL) || defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KCSAN)
1055
+# ifdef CONFIG_CONSTRUCTORS
1056
+# define SANITIZER_DISCARDS \
1057
+ *(.eh_frame)
1058
+# else
1059
+# define SANITIZER_DISCARDS \
1060
+ *(.init_array) *(.init_array.*) \
1061
+ *(.eh_frame)
1062
+# endif
1063
+#else
1064
+# define SANITIZER_DISCARDS
1065
+#endif
1066
+
1067
+#define COMMON_DISCARDS \
1068
+ SANITIZER_DISCARDS \
8731069 *(.discard) \
8741070 *(.discard.*) \
1071
+ *(.modinfo) \
1072
+ /* ld.bfd warns about .gnu.version* even when not emitted */ \
1073
+ *(.gnu.version*) \
1074
+
1075
+#define DISCARDS \
1076
+ /DISCARD/ : { \
1077
+ EXIT_DISCARDS \
1078
+ EXIT_CALL \
1079
+ COMMON_DISCARDS \
8751080 }
8761081
8771082 /**
....@@ -966,7 +1171,7 @@
9661171 * matches the requirement of PAGE_ALIGNED_DATA.
9671172 *
9681173 * use 0 as page_align if page_aligned data is not used */
969
-#define RW_DATA_SECTION(cacheline, pagealigned, inittask) \
1174
+#define RW_DATA(cacheline, pagealigned, inittask) \
9701175 . = ALIGN(PAGE_SIZE); \
9711176 .data : AT(ADDR(.data) - LOAD_OFFSET) { \
9721177 INIT_TASK_DATA(inittask) \
....@@ -993,7 +1198,6 @@
9931198 INIT_SETUP(initsetup_align) \
9941199 INIT_CALLS \
9951200 CON_INITCALL \
996
- SECURITY_INITCALL \
9971201 INIT_RAM_FS \
9981202 }
9991203