1 #ifndef _LINUX_EXPORT_H
2 #define _LINUX_EXPORT_H
3
4
5
6
7
8
9
10
11
12
13 #ifndef __ASSEMBLY__
14 #ifdef MODULE
15 extern struct module __this_module;
16 #define THIS_MODULE (&__this_module)
17 #else
18 #define THIS_MODULE ((struct module *)0)
19 #endif
20
21 #ifdef CONFIG_MODVERSIONS
22
23
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" \
29 " .previous \n")
30 #else
31 #define __CRC_SYMBOL(sym, sec) \
32 asm(" .section \"___kcrctab" sec "+" #sym "\", \"a\" \n" \
33 " .weak __crc_" #sym " \n" \
34 " .long __crc_" #sym " \n" \
35 " .previous \n")
36 #endif
37 #else
38 #define __CRC_SYMBOL(sym, sec)
39 #endif
40
41 #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
42 #include <linux/compiler.h>
43
44
45
46
47
48
49 #define __KSYMTAB_ENTRY_NS(sym, sec) \
50 __ADDRESSABLE(sym) \
51 asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \
52 " .balign 4 \n" \
53 "__ksymtab_" #sym ": \n" \
54 " .long " #sym "- . \n" \
55 " .long __kstrtab_" #sym "- . \n" \
56 " .long __kstrtabns_" #sym "- . \n" \
57 " .previous \n")
58
59 #define __KSYMTAB_ENTRY(sym, sec) \
60 __ADDRESSABLE(sym) \
61 asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \
62 " .balign 4 \n" \
63 "__ksymtab_" #sym ": \n" \
64 " .long " #sym "- . \n" \
65 " .long __kstrtab_" #sym "- . \n" \
66 " .long 0 \n" \
67 " .previous \n")
68
69 struct kernel_symbol {
70 int value_offset;
71 int name_offset;
72 int namespace_offset;
73 };
74 #else
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 }
80
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 }
86
87 struct kernel_symbol {
88 unsigned long value;
89 const char *name;
90 const char *namespace;
91 };
92 #endif
93
94 #ifdef __GENKSYMS__
95
96 #define ___EXPORT_SYMBOL(sym,sec) __GENKSYMS_EXPORT_SYMBOL(sym)
97 #define ___EXPORT_SYMBOL_NS(sym,sec,ns) __GENKSYMS_EXPORT_SYMBOL(sym)
98
99 #else
100
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))) \
106 = #sym \
107
108
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))) \
113 = #ns; \
114 __KSYMTAB_ENTRY_NS(sym, sec)
115
116 #define ___EXPORT_SYMBOL(sym, sec) \
117 ___export_symbol_common(sym, sec); \
118 __KSYMTAB_ENTRY(sym, sec)
119
120 #endif
121
122 #if !defined(CONFIG_MODULES) || defined(__DISABLE_EXPORTS)
123
124
125
126
127
128
129 #define __EXPORT_SYMBOL_NS(sym, sec, ns)
130 #define __EXPORT_SYMBOL(sym, sec)
131
132 #elif defined(CONFIG_TRIM_UNUSED_KSYMS)
133
134 #include <generated/autoksyms.h>
135
136
137
138
139
140
141
142
143 #define __ksym_marker(sym) \
144 static int __ksym_marker_##sym[0] __section(".discard.ksym") __used
145
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)
155
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)
165
166 #else
167
168 #define __EXPORT_SYMBOL_NS(sym,sec,ns) ___EXPORT_SYMBOL_NS(sym,sec,ns)
169 #define __EXPORT_SYMBOL(sym,sec) ___EXPORT_SYMBOL(sym,sec)
170
171 #endif
172
173 #ifdef DEFAULT_SYMBOL_NAMESPACE
174 #undef __EXPORT_SYMBOL
175 #define __EXPORT_SYMBOL(sym, sec) \
176 __EXPORT_SYMBOL_NS(sym, sec, DEFAULT_SYMBOL_NAMESPACE)
177 #endif
178
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)
184
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")
188 #else
189 #define EXPORT_UNUSED_SYMBOL(sym)
190 #define EXPORT_UNUSED_SYMBOL_GPL(sym)
191 #endif
192
193 #endif
194
195 #endif