hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/include/linux/export.h
....@@ -1,3 +1,4 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 #ifndef _LINUX_EXPORT_H
23 #define _LINUX_EXPORT_H
34
....@@ -18,9 +19,6 @@
1819 #define THIS_MODULE ((struct module *)0)
1920 #endif
2021
21
-#ifdef CONFIG_MODULES
22
-
23
-#if defined(__KERNEL__) && !defined(__GENKSYMS__)
2422 #ifdef CONFIG_MODVERSIONS
2523 /* Mark the CRC weak since genksyms apparently decides not to
2624 * generate a checksums for some symbols */
....@@ -29,13 +27,13 @@
2927 asm(" .section \"___kcrctab" sec "+" #sym "\", \"a\" \n" \
3028 " .weak __crc_" #sym " \n" \
3129 " .long __crc_" #sym " - . \n" \
32
- " .previous \n");
30
+ " .previous \n")
3331 #else
3432 #define __CRC_SYMBOL(sym, sec) \
3533 asm(" .section \"___kcrctab" sec "+" #sym "\", \"a\" \n" \
3634 " .weak __crc_" #sym " \n" \
3735 " .long __crc_" #sym " \n" \
38
- " .previous \n");
36
+ " .previous \n")
3937 #endif
4038 #else
4139 #define __CRC_SYMBOL(sym, sec)
....@@ -52,102 +50,159 @@
5250 #define __KSYMTAB_ENTRY(sym, sec) \
5351 __ADDRESSABLE(sym) \
5452 asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \
55
- " .balign 8 \n" \
53
+ " .balign 4 \n" \
5654 "__ksymtab_" #sym ": \n" \
5755 " .long " #sym "- . \n" \
5856 " .long __kstrtab_" #sym "- . \n" \
57
+ " .long __kstrtabns_" #sym "- . \n" \
5958 " .previous \n")
6059
6160 struct kernel_symbol {
6261 int value_offset;
6362 int name_offset;
63
+ int namespace_offset;
6464 };
6565 #else
66
+#ifdef CONFIG_CFI_CLANG
67
+#include <linux/compiler.h>
68
+/*
69
+ * With -fno-sanitize-cfi-canonical-jump-tables, the compiler replaces
70
+ * references to functions with jump table addresses. Use inline assembly
71
+ * to emit ksymtab entries that point to the actual function instead.
72
+ */
73
+#define ___KSYMTAB_ENTRY(sym, sec, size) \
74
+ __ADDRESSABLE(sym) \
75
+ asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \
76
+ " .balign " #size " \n" \
77
+ "__ksymtab_" #sym ": \n" \
78
+ " ." #size "byte " #sym " \n" \
79
+ " ." #size "byte __kstrtab_" #sym " \n" \
80
+ " ." #size "byte __kstrtabns_" #sym " \n" \
81
+ " .previous \n")
82
+
83
+#ifdef CONFIG_64BIT
84
+#define __KSYMTAB_ENTRY(sym, sec) ___KSYMTAB_ENTRY(sym, sec, 8)
85
+#else
86
+#define __KSYMTAB_ENTRY(sym, sec) ___KSYMTAB_ENTRY(sym, sec, 4)
87
+#endif
88
+
89
+#else /* !CONFIG_CFI_CLANG */
90
+
6691 #define __KSYMTAB_ENTRY(sym, sec) \
6792 static const struct kernel_symbol __ksymtab_##sym \
6893 __attribute__((section("___ksymtab" sec "+" #sym), used)) \
69
- = { (unsigned long)&sym, __kstrtab_##sym }
94
+ __aligned(sizeof(void *)) \
95
+ = { (unsigned long)&sym, __kstrtab_##sym, __kstrtabns_##sym }
96
+
97
+#endif
7098
7199 struct kernel_symbol {
72100 unsigned long value;
73101 const char *name;
102
+ const char *namespace;
74103 };
75104 #endif
76105
77
-/* For every exported symbol, place a struct in the __ksymtab section */
78
-#define ___EXPORT_SYMBOL(sym, sec) \
79
- extern typeof(sym) sym; \
80
- __CRC_SYMBOL(sym, sec) \
81
- static const char __kstrtab_##sym[] \
82
- __attribute__((section("__ksymtab_strings"), used, aligned(1))) \
83
- = #sym; \
106
+#ifdef __GENKSYMS__
107
+
108
+#define ___EXPORT_SYMBOL(sym, sec, ns) __GENKSYMS_EXPORT_SYMBOL(sym)
109
+
110
+#else
111
+
112
+/*
113
+ * For every exported symbol, do the following:
114
+ *
115
+ * - If applicable, place a CRC entry in the __kcrctab section.
116
+ * - Put the name of the symbol and namespace (empty string "" for none) in
117
+ * __ksymtab_strings.
118
+ * - Place a struct kernel_symbol entry in the __ksymtab section.
119
+ *
120
+ * note on .section use: we specify progbits since usage of the "M" (SHF_MERGE)
121
+ * section flag requires it. Use '%progbits' instead of '@progbits' since the
122
+ * former apparently works on all arches according to the binutils source.
123
+ */
124
+#define ___EXPORT_SYMBOL(sym, sec, ns) \
125
+ extern typeof(sym) sym; \
126
+ extern const char __kstrtab_##sym[]; \
127
+ extern const char __kstrtabns_##sym[]; \
128
+ __CRC_SYMBOL(sym, sec); \
129
+ asm(" .section \"__ksymtab_strings\",\"aMS\",%progbits,1 \n" \
130
+ "__kstrtab_" #sym ": \n" \
131
+ " .asciz \"" #sym "\" \n" \
132
+ "__kstrtabns_" #sym ": \n" \
133
+ " .asciz \"" ns "\" \n" \
134
+ " .previous \n"); \
84135 __KSYMTAB_ENTRY(sym, sec)
85136
86
-#if defined(__DISABLE_EXPORTS)
137
+#endif
138
+
139
+#if !defined(CONFIG_MODULES) || defined(__DISABLE_EXPORTS)
87140
88141 /*
89142 * Allow symbol exports to be disabled completely so that C code may
90143 * be reused in other execution contexts such as the UEFI stub or the
91144 * decompressor.
92145 */
93
-#define __EXPORT_SYMBOL(sym, sec)
94
-
95
-#elif defined(__KSYM_DEPS__)
96
-
97
-/*
98
- * For fine grained build dependencies, we want to tell the build system
99
- * about each possible exported symbol even if they're not actually exported.
100
- * We use a string pattern that is unlikely to be valid code that the build
101
- * system filters out from the preprocessor output (see ksym_dep_filter
102
- * in scripts/Kbuild.include).
103
- */
104
-#define __EXPORT_SYMBOL(sym, sec) === __KSYM_##sym ===
146
+#define __EXPORT_SYMBOL(sym, sec, ns)
105147
106148 #elif defined(CONFIG_TRIM_UNUSED_KSYMS) && !defined(MODULE)
107149
108150 #include <generated/autoksyms.h>
109151
110
-#define __EXPORT_SYMBOL(sym, sec) \
111
- __cond_export_sym(sym, sec, __is_defined(__KSYM_##sym))
112
-#define __cond_export_sym(sym, sec, conf) \
113
- ___cond_export_sym(sym, sec, conf)
114
-#define ___cond_export_sym(sym, sec, enabled) \
115
- __cond_export_sym_##enabled(sym, sec)
116
-#define __cond_export_sym_1(sym, sec) ___EXPORT_SYMBOL(sym, sec)
117
-#define __cond_export_sym_0(sym, sec) /* nothing */
152
+/*
153
+ * For fine grained build dependencies, we want to tell the build system
154
+ * about each possible exported symbol even if they're not actually exported.
155
+ * We use a symbol pattern __ksym_marker_<symbol> that the build system filters
156
+ * from the $(NM) output (see scripts/gen_ksymdeps.sh). These symbols are
157
+ * discarded in the final link stage.
158
+ */
159
+#define __ksym_marker(sym) \
160
+ static int __ksym_marker_##sym[0] __section(".discard.ksym") __used
118161
162
+#define __EXPORT_SYMBOL(sym, sec, ns) \
163
+ __ksym_marker(sym); \
164
+ __cond_export_sym(sym, sec, ns, __is_defined(__KSYM_##sym))
165
+#define __cond_export_sym(sym, sec, ns, conf) \
166
+ ___cond_export_sym(sym, sec, ns, conf)
167
+#define ___cond_export_sym(sym, sec, ns, enabled) \
168
+ __cond_export_sym_##enabled(sym, sec, ns)
169
+#define __cond_export_sym_1(sym, sec, ns) ___EXPORT_SYMBOL(sym, sec, ns)
170
+
171
+#ifdef __GENKSYMS__
172
+#define __cond_export_sym_0(sym, sec, ns) __GENKSYMS_EXPORT_SYMBOL(sym)
119173 #else
120
-#define __EXPORT_SYMBOL ___EXPORT_SYMBOL
174
+#define __cond_export_sym_0(sym, sec, ns) /* nothing */
121175 #endif
122176
123
-#define EXPORT_SYMBOL(sym) \
124
- __EXPORT_SYMBOL(sym, "")
125
-
126
-#define EXPORT_SYMBOL_GPL(sym) \
127
- __EXPORT_SYMBOL(sym, "_gpl")
128
-
129
-#define EXPORT_SYMBOL_GPL_FUTURE(sym) \
130
- __EXPORT_SYMBOL(sym, "_gpl_future")
131
-
132
-#ifdef CONFIG_UNUSED_SYMBOLS
133
-#define EXPORT_UNUSED_SYMBOL(sym) __EXPORT_SYMBOL(sym, "_unused")
134
-#define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl")
135177 #else
136
-#define EXPORT_UNUSED_SYMBOL(sym)
137
-#define EXPORT_UNUSED_SYMBOL_GPL(sym)
138
-#endif
139178
140
-#endif /* __GENKSYMS__ */
141
-
142
-#else /* !CONFIG_MODULES... */
143
-
144
-#define EXPORT_SYMBOL(sym)
145
-#define EXPORT_SYMBOL_GPL(sym)
146
-#define EXPORT_SYMBOL_GPL_FUTURE(sym)
147
-#define EXPORT_UNUSED_SYMBOL(sym)
148
-#define EXPORT_UNUSED_SYMBOL_GPL(sym)
179
+#define __EXPORT_SYMBOL(sym, sec, ns) ___EXPORT_SYMBOL(sym, sec, ns)
149180
150181 #endif /* CONFIG_MODULES */
182
+
183
+#ifdef DEFAULT_SYMBOL_NAMESPACE
184
+#include <linux/stringify.h>
185
+#define _EXPORT_SYMBOL(sym, sec) __EXPORT_SYMBOL(sym, sec, __stringify(DEFAULT_SYMBOL_NAMESPACE))
186
+#else
187
+#define _EXPORT_SYMBOL(sym, sec) __EXPORT_SYMBOL(sym, sec, "")
188
+#endif
189
+
190
+#define EXPORT_SYMBOL(sym) _EXPORT_SYMBOL(sym, "")
191
+#define EXPORT_SYMBOL_GPL(sym) _EXPORT_SYMBOL(sym, "_gpl")
192
+#define EXPORT_SYMBOL_GPL_FUTURE(sym) _EXPORT_SYMBOL(sym, "_gpl_future")
193
+#define _EXPORT_SYMBOL_NS(sym, ns) __EXPORT_SYMBOL(sym, "", #ns)
194
+#define _EXPORT_SYMBOL_NS_GPL(sym, ns) __EXPORT_SYMBOL(sym, "_gpl", #ns)
195
+#define EXPORT_SYMBOL_NS(sym, ns) _EXPORT_SYMBOL_NS(sym, ns)
196
+#define EXPORT_SYMBOL_NS_GPL(sym, ns) _EXPORT_SYMBOL_NS_GPL(sym, ns)
197
+
198
+#ifdef CONFIG_UNUSED_SYMBOLS
199
+#define EXPORT_UNUSED_SYMBOL(sym) _EXPORT_SYMBOL(sym, "_unused")
200
+#define EXPORT_UNUSED_SYMBOL_GPL(sym) _EXPORT_SYMBOL(sym, "_unused_gpl")
201
+#else
202
+#define EXPORT_UNUSED_SYMBOL(sym)
203
+#define EXPORT_UNUSED_SYMBOL_GPL(sym)
204
+#endif
205
+
151206 #endif /* !__ASSEMBLY__ */
152207
153208 #endif /* _LINUX_EXPORT_H */