.. | .. |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
---|
1 | 2 | #ifndef _LINUX_EXPORT_H |
---|
2 | 3 | #define _LINUX_EXPORT_H |
---|
3 | 4 | |
---|
.. | .. |
---|
18 | 19 | #define THIS_MODULE ((struct module *)0) |
---|
19 | 20 | #endif |
---|
20 | 21 | |
---|
21 | | -#ifdef CONFIG_MODULES |
---|
22 | | - |
---|
23 | | -#if defined(__KERNEL__) && !defined(__GENKSYMS__) |
---|
24 | 22 | #ifdef CONFIG_MODVERSIONS |
---|
25 | 23 | /* Mark the CRC weak since genksyms apparently decides not to |
---|
26 | 24 | * generate a checksums for some symbols */ |
---|
.. | .. |
---|
29 | 27 | asm(" .section \"___kcrctab" sec "+" #sym "\", \"a\" \n" \ |
---|
30 | 28 | " .weak __crc_" #sym " \n" \ |
---|
31 | 29 | " .long __crc_" #sym " - . \n" \ |
---|
32 | | - " .previous \n"); |
---|
| 30 | + " .previous \n") |
---|
33 | 31 | #else |
---|
34 | 32 | #define __CRC_SYMBOL(sym, sec) \ |
---|
35 | 33 | asm(" .section \"___kcrctab" sec "+" #sym "\", \"a\" \n" \ |
---|
36 | 34 | " .weak __crc_" #sym " \n" \ |
---|
37 | 35 | " .long __crc_" #sym " \n" \ |
---|
38 | | - " .previous \n"); |
---|
| 36 | + " .previous \n") |
---|
39 | 37 | #endif |
---|
40 | 38 | #else |
---|
41 | 39 | #define __CRC_SYMBOL(sym, sec) |
---|
.. | .. |
---|
52 | 50 | #define __KSYMTAB_ENTRY(sym, sec) \ |
---|
53 | 51 | __ADDRESSABLE(sym) \ |
---|
54 | 52 | asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \ |
---|
55 | | - " .balign 8 \n" \ |
---|
| 53 | + " .balign 4 \n" \ |
---|
56 | 54 | "__ksymtab_" #sym ": \n" \ |
---|
57 | 55 | " .long " #sym "- . \n" \ |
---|
58 | 56 | " .long __kstrtab_" #sym "- . \n" \ |
---|
| 57 | + " .long __kstrtabns_" #sym "- . \n" \ |
---|
59 | 58 | " .previous \n") |
---|
60 | 59 | |
---|
61 | 60 | struct kernel_symbol { |
---|
62 | 61 | int value_offset; |
---|
63 | 62 | int name_offset; |
---|
| 63 | + int namespace_offset; |
---|
64 | 64 | }; |
---|
65 | 65 | #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 | + |
---|
66 | 91 | #define __KSYMTAB_ENTRY(sym, sec) \ |
---|
67 | 92 | static const struct kernel_symbol __ksymtab_##sym \ |
---|
68 | 93 | __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 |
---|
70 | 98 | |
---|
71 | 99 | struct kernel_symbol { |
---|
72 | 100 | unsigned long value; |
---|
73 | 101 | const char *name; |
---|
| 102 | + const char *namespace; |
---|
74 | 103 | }; |
---|
75 | 104 | #endif |
---|
76 | 105 | |
---|
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"); \ |
---|
84 | 135 | __KSYMTAB_ENTRY(sym, sec) |
---|
85 | 136 | |
---|
86 | | -#if defined(__DISABLE_EXPORTS) |
---|
| 137 | +#endif |
---|
| 138 | + |
---|
| 139 | +#if !defined(CONFIG_MODULES) || defined(__DISABLE_EXPORTS) |
---|
87 | 140 | |
---|
88 | 141 | /* |
---|
89 | 142 | * Allow symbol exports to be disabled completely so that C code may |
---|
90 | 143 | * be reused in other execution contexts such as the UEFI stub or the |
---|
91 | 144 | * decompressor. |
---|
92 | 145 | */ |
---|
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) |
---|
105 | 147 | |
---|
106 | 148 | #elif defined(CONFIG_TRIM_UNUSED_KSYMS) && !defined(MODULE) |
---|
107 | 149 | |
---|
108 | 150 | #include <generated/autoksyms.h> |
---|
109 | 151 | |
---|
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 |
---|
118 | 161 | |
---|
| 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) |
---|
119 | 173 | #else |
---|
120 | | -#define __EXPORT_SYMBOL ___EXPORT_SYMBOL |
---|
| 174 | +#define __cond_export_sym_0(sym, sec, ns) /* nothing */ |
---|
121 | 175 | #endif |
---|
122 | 176 | |
---|
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") |
---|
135 | 177 | #else |
---|
136 | | -#define EXPORT_UNUSED_SYMBOL(sym) |
---|
137 | | -#define EXPORT_UNUSED_SYMBOL_GPL(sym) |
---|
138 | | -#endif |
---|
139 | 178 | |
---|
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) |
---|
149 | 180 | |
---|
150 | 181 | #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 | + |
---|
151 | 206 | #endif /* !__ASSEMBLY__ */ |
---|
152 | 207 | |
---|
153 | 208 | #endif /* _LINUX_EXPORT_H */ |
---|