1 #ifndef _LINUX_EXPORT_H
2 #define _LINUX_EXPORT_H
5 * Export symbols from the kernel to modules. Forked from module.h
6 * to reduce the amount of pointless cruft we feed to gcc when only
7 * exporting a simple symbol or two.
9 * Try not to add #includes here. It slows compilation and makes kernel
10 * hackers place grumpy comments in header files.
15 extern struct module __this_module;
16 #define THIS_MODULE (&__this_module)
18 #define THIS_MODULE ((struct module *)0)
21 #define NS_SEPARATOR "."
23 #ifdef CONFIG_MODVERSIONS
24 /* Mark the CRC weak since genksyms apparently decides not to
25 * generate a checksums for some symbols */
26 #if defined(CONFIG_MODULE_REL_CRCS)
27 #define __CRC_SYMBOL(sym, sec) \
28 asm(" .section \"___kcrctab" sec "+" #sym "\", \"a\" \n" \
29 " .weak __crc_" #sym " \n" \
30 " .long __crc_" #sym " - . \n" \
33 #define __CRC_SYMBOL(sym, sec) \
34 asm(" .section \"___kcrctab" sec "+" #sym "\", \"a\" \n" \
35 " .weak __crc_" #sym " \n" \
36 " .long __crc_" #sym " \n" \
40 #define __CRC_SYMBOL(sym, sec)
43 #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
44 #include <linux/compiler.h>
46 * Emit the ksymtab entry as a pair of relative references: this reduces
47 * the size by half on 64-bit architectures, and eliminates the need for
48 * absolute relocations that require runtime processing on relocatable
51 #define __KSYMTAB_ENTRY_NS(sym, sec, ns) \
53 asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \
55 "__ksymtab_" #ns NS_SEPARATOR #sym ": \n" \
56 " .long " #sym "- . \n" \
57 " .long __kstrtab_" #sym "- . \n" \
58 " .long __kstrtabns_" #sym "- . \n" \
61 #define __KSYMTAB_ENTRY(sym, sec) \
63 asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \
65 "__ksymtab_" #sym ": \n" \
66 " .long " #sym "- . \n" \
67 " .long __kstrtab_" #sym "- . \n" \
71 struct kernel_symbol {
77 #define __KSYMTAB_ENTRY_NS(sym, sec, ns) \
78 static const struct kernel_symbol __ksymtab_##sym##__##ns \
79 asm("__ksymtab_" #ns NS_SEPARATOR #sym) \
80 __attribute__((section("___ksymtab" sec "+" #sym), used)) \
81 __aligned(sizeof(void *)) \
82 = { (unsigned long)&sym, __kstrtab_##sym, __kstrtabns_##sym }
84 #define __KSYMTAB_ENTRY(sym, sec) \
85 static const struct kernel_symbol __ksymtab_##sym \
86 asm("__ksymtab_" #sym) \
87 __attribute__((section("___ksymtab" sec "+" #sym), used)) \
88 __aligned(sizeof(void *)) \
89 = { (unsigned long)&sym, __kstrtab_##sym, NULL }
91 struct kernel_symbol {
94 const char *namespace;
100 #define ___EXPORT_SYMBOL(sym,sec) __GENKSYMS_EXPORT_SYMBOL(sym)
101 #define ___EXPORT_SYMBOL_NS(sym,sec,ns) __GENKSYMS_EXPORT_SYMBOL(sym)
105 #define ___export_symbol_common(sym, sec) \
106 extern typeof(sym) sym; \
107 __CRC_SYMBOL(sym, sec); \
108 static const char __kstrtab_##sym[] \
109 __attribute__((section("__ksymtab_strings"), used, aligned(1))) \
112 /* For every exported symbol, place a struct in the __ksymtab section */
113 #define ___EXPORT_SYMBOL_NS(sym, sec, ns) \
114 ___export_symbol_common(sym, sec); \
115 static const char __kstrtabns_##sym[] \
116 __attribute__((section("__ksymtab_strings"), used, aligned(1))) \
118 __KSYMTAB_ENTRY_NS(sym, sec, ns)
120 #define ___EXPORT_SYMBOL(sym, sec) \
121 ___export_symbol_common(sym, sec); \
122 __KSYMTAB_ENTRY(sym, sec)
126 #if !defined(CONFIG_MODULES) || defined(__DISABLE_EXPORTS)
129 * Allow symbol exports to be disabled completely so that C code may
130 * be reused in other execution contexts such as the UEFI stub or the
133 #define __EXPORT_SYMBOL_NS(sym, sec, ns)
134 #define __EXPORT_SYMBOL(sym, sec)
136 #elif defined(CONFIG_TRIM_UNUSED_KSYMS)
138 #include <generated/autoksyms.h>
141 * For fine grained build dependencies, we want to tell the build system
142 * about each possible exported symbol even if they're not actually exported.
143 * We use a symbol pattern __ksym_marker_<symbol> that the build system filters
144 * from the $(NM) output (see scripts/gen_ksymdeps.sh). These symbols are
145 * discarded in the final link stage.
147 #define __ksym_marker(sym) \
148 static int __ksym_marker_##sym[0] __section(".discard.ksym") __used
150 #define __EXPORT_SYMBOL(sym, sec) \
151 __ksym_marker(sym); \
152 __cond_export_sym(sym, sec, __is_defined(__KSYM_##sym))
153 #define __cond_export_sym(sym, sec, conf) \
154 ___cond_export_sym(sym, sec, conf)
155 #define ___cond_export_sym(sym, sec, enabled) \
156 __cond_export_sym_##enabled(sym, sec)
157 #define __cond_export_sym_1(sym, sec) ___EXPORT_SYMBOL(sym, sec)
158 #define __cond_export_sym_0(sym, sec) /* nothing */
160 #define __EXPORT_SYMBOL_NS(sym, sec, ns) \
161 __ksym_marker(sym); \
162 __cond_export_ns_sym(sym, sec, ns, __is_defined(__KSYM_##sym))
163 #define __cond_export_ns_sym(sym, sec, ns, conf) \
164 ___cond_export_ns_sym(sym, sec, ns, conf)
165 #define ___cond_export_ns_sym(sym, sec, ns, enabled) \
166 __cond_export_ns_sym_##enabled(sym, sec, ns)
167 #define __cond_export_ns_sym_1(sym, sec, ns) ___EXPORT_SYMBOL_NS(sym, sec, ns)
168 #define __cond_export_ns_sym_0(sym, sec, ns) /* nothing */
172 #define __EXPORT_SYMBOL_NS(sym,sec,ns) ___EXPORT_SYMBOL_NS(sym,sec,ns)
173 #define __EXPORT_SYMBOL(sym,sec) ___EXPORT_SYMBOL(sym,sec)
175 #endif /* CONFIG_MODULES */
177 #ifdef DEFAULT_SYMBOL_NAMESPACE
178 #undef __EXPORT_SYMBOL
179 #define __EXPORT_SYMBOL(sym, sec) \
180 __EXPORT_SYMBOL_NS(sym, sec, DEFAULT_SYMBOL_NAMESPACE)
183 #define EXPORT_SYMBOL(sym) __EXPORT_SYMBOL(sym, "")
184 #define EXPORT_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_gpl")
185 #define EXPORT_SYMBOL_GPL_FUTURE(sym) __EXPORT_SYMBOL(sym, "_gpl_future")
186 #define EXPORT_SYMBOL_NS(sym, ns) __EXPORT_SYMBOL_NS(sym, "", ns)
187 #define EXPORT_SYMBOL_NS_GPL(sym, ns) __EXPORT_SYMBOL_NS(sym, "_gpl", ns)
189 #ifdef CONFIG_UNUSED_SYMBOLS
190 #define EXPORT_UNUSED_SYMBOL(sym) __EXPORT_SYMBOL(sym, "_unused")
191 #define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl")
193 #define EXPORT_UNUSED_SYMBOL(sym)
194 #define EXPORT_UNUSED_SYMBOL_GPL(sym)
197 #endif /* !__ASSEMBLY__ */
199 #endif /* _LINUX_EXPORT_H */