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 #ifdef CONFIG_MODVERSIONS
22 /* Mark the CRC weak since genksyms apparently decides not to
23 * generate a checksums for some symbols */
24 #if defined(CONFIG_MODULE_REL_CRCS)
25 #define __CRC_SYMBOL(sym, sec) \
26 asm(" .section \"___kcrctab" sec "+" #sym "\", \"a\" \n" \
27 " .weak __crc_" #sym " \n" \
28 " .long __crc_" #sym " - . \n" \
31 #define __CRC_SYMBOL(sym, sec) \
32 asm(" .section \"___kcrctab" sec "+" #sym "\", \"a\" \n" \
33 " .weak __crc_" #sym " \n" \
34 " .long __crc_" #sym " \n" \
38 #define __CRC_SYMBOL(sym, sec)
41 #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
42 #include <linux/compiler.h>
44 * Emit the ksymtab entry as a pair of relative references: this reduces
45 * the size by half on 64-bit architectures, and eliminates the need for
46 * absolute relocations that require runtime processing on relocatable
49 #define __KSYMTAB_ENTRY_NS(sym, sec) \
51 asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \
53 "__ksymtab_" #sym ": \n" \
54 " .long " #sym "- . \n" \
55 " .long __kstrtab_" #sym "- . \n" \
56 " .long __kstrtabns_" #sym "- . \n" \
59 #define __KSYMTAB_ENTRY(sym, sec) \
61 asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \
63 "__ksymtab_" #sym ": \n" \
64 " .long " #sym "- . \n" \
65 " .long __kstrtab_" #sym "- . \n" \
69 struct kernel_symbol {
75 #define __KSYMTAB_ENTRY_NS(sym, sec) \
76 static const struct kernel_symbol __ksymtab_##sym \
77 __attribute__((section("___ksymtab" sec "+" #sym), used)) \
78 __aligned(sizeof(void *)) \
79 = { (unsigned long)&sym, __kstrtab_##sym, __kstrtabns_##sym }
81 #define __KSYMTAB_ENTRY(sym, sec) \
82 static const struct kernel_symbol __ksymtab_##sym \
83 __attribute__((section("___ksymtab" sec "+" #sym), used)) \
84 __aligned(sizeof(void *)) \
85 = { (unsigned long)&sym, __kstrtab_##sym, NULL }
87 struct kernel_symbol {
90 const char *namespace;
96 #define ___EXPORT_SYMBOL(sym,sec) __GENKSYMS_EXPORT_SYMBOL(sym)
97 #define ___EXPORT_SYMBOL_NS(sym,sec,ns) __GENKSYMS_EXPORT_SYMBOL(sym)
101 #define ___export_symbol_common(sym, sec) \
102 extern typeof(sym) sym; \
103 __CRC_SYMBOL(sym, sec); \
104 static const char __kstrtab_##sym[] \
105 __attribute__((section("__ksymtab_strings"), used, aligned(1))) \
108 /* For every exported symbol, place a struct in the __ksymtab section */
109 #define ___EXPORT_SYMBOL_NS(sym, sec, ns) \
110 ___export_symbol_common(sym, sec); \
111 static const char __kstrtabns_##sym[] \
112 __attribute__((section("__ksymtab_strings"), used, aligned(1))) \
114 __KSYMTAB_ENTRY_NS(sym, sec)
116 #define ___EXPORT_SYMBOL(sym, sec) \
117 ___export_symbol_common(sym, sec); \
118 __KSYMTAB_ENTRY(sym, sec)
122 #if !defined(CONFIG_MODULES) || defined(__DISABLE_EXPORTS)
125 * Allow symbol exports to be disabled completely so that C code may
126 * be reused in other execution contexts such as the UEFI stub or the
129 #define __EXPORT_SYMBOL_NS(sym, sec, ns)
130 #define __EXPORT_SYMBOL(sym, sec)
132 #elif defined(CONFIG_TRIM_UNUSED_KSYMS)
134 #include <generated/autoksyms.h>
137 * For fine grained build dependencies, we want to tell the build system
138 * about each possible exported symbol even if they're not actually exported.
139 * We use a symbol pattern __ksym_marker_<symbol> that the build system filters
140 * from the $(NM) output (see scripts/gen_ksymdeps.sh). These symbols are
141 * discarded in the final link stage.
143 #define __ksym_marker(sym) \
144 static int __ksym_marker_##sym[0] __section(".discard.ksym") __used
146 #define __EXPORT_SYMBOL(sym, sec) \
147 __ksym_marker(sym); \
148 __cond_export_sym(sym, sec, __is_defined(__KSYM_##sym))
149 #define __cond_export_sym(sym, sec, conf) \
150 ___cond_export_sym(sym, sec, conf)
151 #define ___cond_export_sym(sym, sec, enabled) \
152 __cond_export_sym_##enabled(sym, sec)
153 #define __cond_export_sym_1(sym, sec) ___EXPORT_SYMBOL(sym, sec)
154 #define __cond_export_sym_0(sym, sec) /* nothing */
156 #define __EXPORT_SYMBOL_NS(sym, sec, ns) \
157 __ksym_marker(sym); \
158 __cond_export_ns_sym(sym, sec, ns, __is_defined(__KSYM_##sym))
159 #define __cond_export_ns_sym(sym, sec, ns, conf) \
160 ___cond_export_ns_sym(sym, sec, ns, conf)
161 #define ___cond_export_ns_sym(sym, sec, ns, enabled) \
162 __cond_export_ns_sym_##enabled(sym, sec, ns)
163 #define __cond_export_ns_sym_1(sym, sec, ns) ___EXPORT_SYMBOL_NS(sym, sec, ns)
164 #define __cond_export_ns_sym_0(sym, sec, ns) /* nothing */
168 #define __EXPORT_SYMBOL_NS(sym,sec,ns) ___EXPORT_SYMBOL_NS(sym,sec,ns)
169 #define __EXPORT_SYMBOL(sym,sec) ___EXPORT_SYMBOL(sym,sec)
171 #endif /* CONFIG_MODULES */
173 #ifdef DEFAULT_SYMBOL_NAMESPACE
174 #undef __EXPORT_SYMBOL
175 #define __EXPORT_SYMBOL(sym, sec) \
176 __EXPORT_SYMBOL_NS(sym, sec, DEFAULT_SYMBOL_NAMESPACE)
179 #define EXPORT_SYMBOL(sym) __EXPORT_SYMBOL(sym, "")
180 #define EXPORT_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_gpl")
181 #define EXPORT_SYMBOL_GPL_FUTURE(sym) __EXPORT_SYMBOL(sym, "_gpl_future")
182 #define EXPORT_SYMBOL_NS(sym, ns) __EXPORT_SYMBOL_NS(sym, "", ns)
183 #define EXPORT_SYMBOL_NS_GPL(sym, ns) __EXPORT_SYMBOL_NS(sym, "_gpl", ns)
185 #ifdef CONFIG_UNUSED_SYMBOLS
186 #define EXPORT_UNUSED_SYMBOL(sym) __EXPORT_SYMBOL(sym, "_unused")
187 #define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl")
189 #define EXPORT_UNUSED_SYMBOL(sym)
190 #define EXPORT_UNUSED_SYMBOL_GPL(sym)
193 #endif /* !__ASSEMBLY__ */
195 #endif /* _LINUX_EXPORT_H */