hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/include/linux/init.h
....@@ -47,11 +47,11 @@
4747
4848 /* These are for everybody (although not all archs will actually
4949 discard it in modules) */
50
-#define __init __section(.init.text) __cold __latent_entropy __noinitretpoline __nocfi
51
-#define __initdata __section(.init.data)
52
-#define __initconst __section(.init.rodata)
53
-#define __exitdata __section(.exit.data)
54
-#define __exit_call __used __section(.exitcall.exit)
50
+#define __init __section(".init.text") __cold __latent_entropy __noinitretpoline __nocfi
51
+#define __initdata __section(".init.data")
52
+#define __initconst __section(".init.rodata")
53
+#define __exitdata __section(".exit.data")
54
+#define __exit_call __used __section(".exitcall.exit")
5555
5656 /*
5757 * modpost check for section mismatches during the kernel build.
....@@ -70,9 +70,9 @@
7070 *
7171 * The markers follow same syntax rules as __init / __initdata.
7272 */
73
-#define __ref __section(.ref.text) noinline
74
-#define __refdata __section(.ref.data)
75
-#define __refconst __section(.ref.rodata)
73
+#define __ref __section(".ref.text") noinline
74
+#define __refdata __section(".ref.data")
75
+#define __refconst __section(".ref.rodata")
7676
7777 #ifdef MODULE
7878 #define __exitused
....@@ -80,16 +80,16 @@
8080 #define __exitused __used
8181 #endif
8282
83
-#define __exit __section(.exit.text) __exitused __cold notrace
83
+#define __exit __section(".exit.text") __exitused __cold notrace
8484
8585 /* Used for MEMORY_HOTPLUG */
86
-#define __meminit __section(.meminit.text) __cold notrace \
86
+#define __meminit __section(".meminit.text") __cold notrace \
8787 __latent_entropy
88
-#define __meminitdata __section(.meminit.data)
89
-#define __meminitconst __section(.meminit.rodata)
90
-#define __memexit __section(.memexit.text) __exitused __cold notrace
91
-#define __memexitdata __section(.memexit.data)
92
-#define __memexitconst __section(.memexit.rodata)
88
+#define __meminitdata __section(".meminit.data")
89
+#define __meminitconst __section(".meminit.rodata")
90
+#define __memexit __section(".memexit.text") __exitused __cold notrace
91
+#define __memexitdata __section(".memexit.data")
92
+#define __memexitconst __section(".memexit.rodata")
9393
9494 /* For assembly routines */
9595 #define __HEAD .section ".head.text","ax"
....@@ -133,10 +133,11 @@
133133 #endif
134134
135135 extern initcall_entry_t __con_initcall_start[], __con_initcall_end[];
136
-extern initcall_entry_t __security_initcall_start[], __security_initcall_end[];
137136
138137 /* Used for contructor calls. */
139138 typedef void (*ctor_fn_t)(void);
139
+
140
+struct file_system_type;
140141
141142 /* Defined in init/main.c */
142143 extern int do_one_initcall(initcall_t fn);
....@@ -147,8 +148,8 @@
147148 /* used by init/main.c */
148149 void setup_arch(char **);
149150 void prepare_namespace(void);
150
-void __init load_default_modules(void);
151
-int __init init_rootfs(void);
151
+void __init init_rootfs(void);
152
+extern struct file_system_type rootfs_fs_type;
152153
153154 #if defined(CONFIG_STRICT_KERNEL_RWX) || defined(CONFIG_STRICT_MODULE_RWX)
154155 extern bool rodata_enabled;
....@@ -183,40 +184,79 @@
183184 * as KEEP() in the linker script.
184185 */
185186
187
+/* Format: <modname>__<counter>_<line>_<fn> */
188
+#define __initcall_id(fn) \
189
+ __PASTE(__KBUILD_MODNAME, \
190
+ __PASTE(__, \
191
+ __PASTE(__COUNTER__, \
192
+ __PASTE(_, \
193
+ __PASTE(__LINE__, \
194
+ __PASTE(_, fn))))))
195
+
196
+/* Format: __<prefix>__<iid><id> */
197
+#define __initcall_name(prefix, __iid, id) \
198
+ __PASTE(__, \
199
+ __PASTE(prefix, \
200
+ __PASTE(__, \
201
+ __PASTE(__iid, id))))
202
+
203
+#ifdef CONFIG_LTO_CLANG
204
+/*
205
+ * With LTO, the compiler doesn't necessarily obey link order for
206
+ * initcalls. In order to preserve the correct order, we add each
207
+ * variable into its own section and generate a linker script (in
208
+ * scripts/link-vmlinux.sh) to specify the order of the sections.
209
+ */
210
+#define __initcall_section(__sec, __iid) \
211
+ #__sec ".init.." #__iid
212
+
213
+/*
214
+ * With LTO, the compiler can rename static functions to avoid
215
+ * global naming collisions. We use a global stub function for
216
+ * initcalls to create a stable symbol name whose address can be
217
+ * taken in inline assembly when PREL32 relocations are used.
218
+ */
219
+#define __initcall_stub(fn, __iid, id) \
220
+ __initcall_name(initstub, __iid, id)
221
+
222
+#define __define_initcall_stub(__stub, fn) \
223
+ int __init __cficanonical __stub(void); \
224
+ int __init __cficanonical __stub(void) \
225
+ { \
226
+ return fn(); \
227
+ } \
228
+ __ADDRESSABLE(__stub)
229
+#else
230
+#define __initcall_section(__sec, __iid) \
231
+ #__sec ".init"
232
+
233
+#define __initcall_stub(fn, __iid, id) fn
234
+
235
+#define __define_initcall_stub(__stub, fn) \
236
+ __ADDRESSABLE(fn)
237
+#endif
238
+
186239 #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
187
-#define ___define_initcall(fn, id, __sec) \
188
- __ADDRESSABLE(fn) \
189
- asm(".section \"" #__sec ".init\", \"a\" \n" \
190
- "__initcall_" #fn #id ": \n" \
191
- ".long " #fn " - . \n" \
240
+#define ____define_initcall(fn, __stub, __name, __sec) \
241
+ __define_initcall_stub(__stub, fn) \
242
+ asm(".section \"" __sec "\", \"a\" \n" \
243
+ __stringify(__name) ": \n" \
244
+ ".long " __stringify(__stub) " - . \n" \
192245 ".previous \n");
193246 #else
194
-#ifdef CONFIG_LTO_CLANG
195
- /*
196
- * With LTO, the compiler doesn't necessarily obey link order for
197
- * initcalls, and the initcall variable needs to be globally unique
198
- * to avoid naming collisions. In order to preserve the correct
199
- * order, we add each variable into its own section and generate a
200
- * linker script (in scripts/link-vmlinux.sh) to ensure the order
201
- * remains correct. We also add a __COUNTER__ prefix to the name,
202
- * so we can retain the order of initcalls within each compilation
203
- * unit, and __LINE__ to make the names more unique.
204
- */
205
- #define ___lto_initcall(c, l, fn, id, __sec) \
206
- static initcall_t __initcall_##c##_##l##_##fn##id __used \
207
- __attribute__((__section__( #__sec \
208
- __stringify(.init..##c##_##l##_##fn)))) = fn;
209
- #define __lto_initcall(c, l, fn, id, __sec) \
210
- ___lto_initcall(c, l, fn, id, __sec)
247
+#define ____define_initcall(fn, __unused, __name, __sec) \
248
+ static initcall_t __name __used \
249
+ __attribute__((__section__(__sec))) = fn;
250
+#endif
211251
212
- #define ___define_initcall(fn, id, __sec) \
213
- __lto_initcall(__COUNTER__, __LINE__, fn, id, __sec)
214
-#else
215
- #define ___define_initcall(fn, id, __sec) \
216
- static initcall_t __initcall_##fn##id __used \
217
- __attribute__((__section__(#__sec ".init"))) = fn;
218
-#endif
219
-#endif
252
+#define __unique_initcall(fn, id, __sec, __iid) \
253
+ ____define_initcall(fn, \
254
+ __initcall_stub(fn, __iid, id), \
255
+ __initcall_name(initcall, __iid, id), \
256
+ __initcall_section(__sec, __iid))
257
+
258
+#define ___define_initcall(fn, id, __sec) \
259
+ __unique_initcall(fn, id, __sec, __initcall_id(fn))
220260
221261 #define __define_initcall(fn, id) ___define_initcall(fn, id, .initcall##id)
222262
....@@ -258,7 +298,6 @@
258298 static exitcall_t __exitcall_##fn __exit_call = fn
259299
260300 #define console_initcall(fn) ___define_initcall(fn, con, .con_initcall)
261
-#define security_initcall(fn) ___define_initcall(fn, security, .security_initcall)
262301
263302 struct obs_kernel_param {
264303 const char *str;
....@@ -276,7 +315,7 @@
276315 static const char __setup_str_##unique_id[] __initconst \
277316 __aligned(1) = str; \
278317 static struct obs_kernel_param __setup_##unique_id \
279
- __used __section(.init.setup) \
318
+ __used __section(".init.setup") \
280319 __attribute__((aligned((sizeof(long))))) \
281320 = { __setup_str_##unique_id, fn, early }
282321
....@@ -320,7 +359,7 @@
320359 #endif
321360
322361 /* Data marked not to be saved by software suspend */
323
-#define __nosavedata __section(.data..nosave)
362
+#define __nosavedata __section(".data..nosave")
324363
325364 #ifdef MODULE
326365 #define __exit_p(x) x