Commit | Line | Data |
---|---|---|
f5016932 PG |
1 | #ifndef _LINUX_EXPORT_H |
2 | #define _LINUX_EXPORT_H | |
b67067f1 | 3 | |
f5016932 PG |
4 | /* |
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. | |
8 | * | |
b92021b0 RR |
9 | * Try not to add #includes here. It slows compilation and makes kernel |
10 | * hackers place grumpy comments in header files. | |
f5016932 PG |
11 | */ |
12 | ||
b92021b0 RR |
13 | #define __VMLINUX_SYMBOL(x) x |
14 | #define __VMLINUX_SYMBOL_STR(x) #x | |
f5016932 | 15 | |
b92021b0 RR |
16 | /* Indirect, so macros are expanded before pasting. */ |
17 | #define VMLINUX_SYMBOL(x) __VMLINUX_SYMBOL(x) | |
18 | #define VMLINUX_SYMBOL_STR(x) __VMLINUX_SYMBOL_STR(x) | |
19 | ||
20 | #ifndef __ASSEMBLY__ | |
f5016932 PG |
21 | struct kernel_symbol |
22 | { | |
23 | unsigned long value; | |
24 | const char *name; | |
25 | }; | |
26 | ||
27 | #ifdef MODULE | |
28 | extern struct module __this_module; | |
29 | #define THIS_MODULE (&__this_module) | |
30 | #else | |
31 | #define THIS_MODULE ((struct module *)0) | |
32 | #endif | |
33 | ||
34 | #ifdef CONFIG_MODULES | |
35 | ||
f2355416 | 36 | #if defined(__KERNEL__) && !defined(__GENKSYMS__) |
f5016932 PG |
37 | #ifdef CONFIG_MODVERSIONS |
38 | /* Mark the CRC weak since genksyms apparently decides not to | |
39 | * generate a checksums for some symbols */ | |
71810db2 AB |
40 | #if defined(CONFIG_MODULE_REL_CRCS) |
41 | #define __CRC_SYMBOL(sym, sec) \ | |
42 | asm(" .section \"___kcrctab" sec "+" #sym "\", \"a\" \n" \ | |
94e58e0a MY |
43 | " .weak __crc_" #sym " \n" \ |
44 | " .long __crc_" #sym " - . \n" \ | |
71810db2 | 45 | " .previous \n"); |
f5016932 | 46 | #else |
71810db2 AB |
47 | #define __CRC_SYMBOL(sym, sec) \ |
48 | asm(" .section \"___kcrctab" sec "+" #sym "\", \"a\" \n" \ | |
94e58e0a MY |
49 | " .weak __crc_" #sym " \n" \ |
50 | " .long __crc_" #sym " \n" \ | |
71810db2 AB |
51 | " .previous \n"); |
52 | #endif | |
53 | #else | |
f5016932 PG |
54 | #define __CRC_SYMBOL(sym, sec) |
55 | #endif | |
56 | ||
57 | /* For every exported symbol, place a struct in the __ksymtab section */ | |
b67067f1 NP |
58 | #define ___EXPORT_SYMBOL(sym, sec) \ |
59 | extern typeof(sym) sym; \ | |
60 | __CRC_SYMBOL(sym, sec) \ | |
61 | static const char __kstrtab_##sym[] \ | |
62 | __attribute__((section("__ksymtab_strings"), aligned(1))) \ | |
94e58e0a | 63 | = #sym; \ |
b67067f1 NP |
64 | static const struct kernel_symbol __ksymtab_##sym \ |
65 | __used \ | |
66 | __attribute__((section("___ksymtab" sec "+" #sym), used)) \ | |
f5016932 PG |
67 | = { (unsigned long)&sym, __kstrtab_##sym } |
68 | ||
c1a95fda NP |
69 | #if defined(__KSYM_DEPS__) |
70 | ||
71 | /* | |
72 | * For fine grained build dependencies, we want to tell the build system | |
73 | * about each possible exported symbol even if they're not actually exported. | |
74 | * We use a string pattern that is unlikely to be valid code that the build | |
75 | * system filters out from the preprocessor output (see ksym_dep_filter | |
76 | * in scripts/Kbuild.include). | |
77 | */ | |
78 | #define __EXPORT_SYMBOL(sym, sec) === __KSYM_##sym === | |
79 | ||
80 | #elif defined(CONFIG_TRIM_UNUSED_KSYMS) | |
f2355416 | 81 | |
f2355416 NP |
82 | #include <generated/autoksyms.h> |
83 | ||
84 | #define __EXPORT_SYMBOL(sym, sec) \ | |
6023d236 | 85 | __cond_export_sym(sym, sec, __is_defined(__KSYM_##sym)) |
f2355416 NP |
86 | #define __cond_export_sym(sym, sec, conf) \ |
87 | ___cond_export_sym(sym, sec, conf) | |
88 | #define ___cond_export_sym(sym, sec, enabled) \ | |
89 | __cond_export_sym_##enabled(sym, sec) | |
90 | #define __cond_export_sym_1(sym, sec) ___EXPORT_SYMBOL(sym, sec) | |
91 | #define __cond_export_sym_0(sym, sec) /* nothing */ | |
92 | ||
93 | #else | |
94 | #define __EXPORT_SYMBOL ___EXPORT_SYMBOL | |
95 | #endif | |
96 | ||
f5016932 PG |
97 | #define EXPORT_SYMBOL(sym) \ |
98 | __EXPORT_SYMBOL(sym, "") | |
99 | ||
100 | #define EXPORT_SYMBOL_GPL(sym) \ | |
101 | __EXPORT_SYMBOL(sym, "_gpl") | |
102 | ||
103 | #define EXPORT_SYMBOL_GPL_FUTURE(sym) \ | |
104 | __EXPORT_SYMBOL(sym, "_gpl_future") | |
105 | ||
106 | #ifdef CONFIG_UNUSED_SYMBOLS | |
107 | #define EXPORT_UNUSED_SYMBOL(sym) __EXPORT_SYMBOL(sym, "_unused") | |
108 | #define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl") | |
109 | #else | |
110 | #define EXPORT_UNUSED_SYMBOL(sym) | |
111 | #define EXPORT_UNUSED_SYMBOL_GPL(sym) | |
112 | #endif | |
113 | ||
114 | #endif /* __GENKSYMS__ */ | |
115 | ||
116 | #else /* !CONFIG_MODULES... */ | |
117 | ||
118 | #define EXPORT_SYMBOL(sym) | |
119 | #define EXPORT_SYMBOL_GPL(sym) | |
120 | #define EXPORT_SYMBOL_GPL_FUTURE(sym) | |
121 | #define EXPORT_UNUSED_SYMBOL(sym) | |
122 | #define EXPORT_UNUSED_SYMBOL_GPL(sym) | |
123 | ||
124 | #endif /* CONFIG_MODULES */ | |
b92021b0 | 125 | #endif /* !__ASSEMBLY__ */ |
f5016932 PG |
126 | |
127 | #endif /* _LINUX_EXPORT_H */ |