]> asedeno.scripts.mit.edu Git - linux.git/blob - include/linux/export.h
mm/memcontrol: use vmstat names for printing statistics
[linux.git] / include / linux / export.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #ifndef _LINUX_EXPORT_H
3 #define _LINUX_EXPORT_H
4
5 /*
6  * Export symbols from the kernel to modules.  Forked from module.h
7  * to reduce the amount of pointless cruft we feed to gcc when only
8  * exporting a simple symbol or two.
9  *
10  * Try not to add #includes here.  It slows compilation and makes kernel
11  * hackers place grumpy comments in header files.
12  */
13
14 #ifndef __ASSEMBLY__
15 #ifdef MODULE
16 extern struct module __this_module;
17 #define THIS_MODULE (&__this_module)
18 #else
19 #define THIS_MODULE ((struct module *)0)
20 #endif
21
22 #ifdef CONFIG_MODVERSIONS
23 /* Mark the CRC weak since genksyms apparently decides not to
24  * generate a checksums for some symbols */
25 #if defined(CONFIG_MODULE_REL_CRCS)
26 #define __CRC_SYMBOL(sym, sec)                                          \
27         asm("   .section \"___kcrctab" sec "+" #sym "\", \"a\"  \n"     \
28             "   .weak   __crc_" #sym "                          \n"     \
29             "   .long   __crc_" #sym " - .                      \n"     \
30             "   .previous                                       \n")
31 #else
32 #define __CRC_SYMBOL(sym, sec)                                          \
33         asm("   .section \"___kcrctab" sec "+" #sym "\", \"a\"  \n"     \
34             "   .weak   __crc_" #sym "                          \n"     \
35             "   .long   __crc_" #sym "                          \n"     \
36             "   .previous                                       \n")
37 #endif
38 #else
39 #define __CRC_SYMBOL(sym, sec)
40 #endif
41
42 #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
43 #include <linux/compiler.h>
44 /*
45  * Emit the ksymtab entry as a pair of relative references: this reduces
46  * the size by half on 64-bit architectures, and eliminates the need for
47  * absolute relocations that require runtime processing on relocatable
48  * kernels.
49  */
50 #define __KSYMTAB_ENTRY_NS(sym, sec)                                    \
51         __ADDRESSABLE(sym)                                              \
52         asm("   .section \"___ksymtab" sec "+" #sym "\", \"a\"  \n"     \
53             "   .balign 4                                       \n"     \
54             "__ksymtab_" #sym ":                                \n"     \
55             "   .long   " #sym "- .                             \n"     \
56             "   .long   __kstrtab_" #sym "- .                   \n"     \
57             "   .long   __kstrtabns_" #sym "- .                 \n"     \
58             "   .previous                                       \n")
59
60 #define __KSYMTAB_ENTRY(sym, sec)                                       \
61         __ADDRESSABLE(sym)                                              \
62         asm("   .section \"___ksymtab" sec "+" #sym "\", \"a\"  \n"     \
63             "   .balign 4                                       \n"     \
64             "__ksymtab_" #sym ":                                \n"     \
65             "   .long   " #sym "- .                             \n"     \
66             "   .long   __kstrtab_" #sym "- .                   \n"     \
67             "   .long   0                                       \n"     \
68             "   .previous                                       \n")
69
70 struct kernel_symbol {
71         int value_offset;
72         int name_offset;
73         int namespace_offset;
74 };
75 #else
76 #define __KSYMTAB_ENTRY_NS(sym, sec)                                    \
77         static const struct kernel_symbol __ksymtab_##sym               \
78         __attribute__((section("___ksymtab" sec "+" #sym), used))       \
79         __aligned(sizeof(void *))                                       \
80         = { (unsigned long)&sym, __kstrtab_##sym, __kstrtabns_##sym }
81
82 #define __KSYMTAB_ENTRY(sym, sec)                                       \
83         static const struct kernel_symbol __ksymtab_##sym               \
84         __attribute__((section("___ksymtab" sec "+" #sym), used))       \
85         __aligned(sizeof(void *))                                       \
86         = { (unsigned long)&sym, __kstrtab_##sym, NULL }
87
88 struct kernel_symbol {
89         unsigned long value;
90         const char *name;
91         const char *namespace;
92 };
93 #endif
94
95 #ifdef __GENKSYMS__
96
97 #define ___EXPORT_SYMBOL(sym,sec)       __GENKSYMS_EXPORT_SYMBOL(sym)
98 #define ___EXPORT_SYMBOL_NS(sym,sec,ns) __GENKSYMS_EXPORT_SYMBOL(sym)
99
100 #else
101
102 #define ___export_symbol_common(sym, sec)                               \
103         extern typeof(sym) sym;                                         \
104         __CRC_SYMBOL(sym, sec);                                         \
105         static const char __kstrtab_##sym[]                             \
106         __attribute__((section("__ksymtab_strings"), used, aligned(1))) \
107         = #sym                                                          \
108
109 /* For every exported symbol, place a struct in the __ksymtab section */
110 #define ___EXPORT_SYMBOL_NS(sym, sec, ns)                               \
111         ___export_symbol_common(sym, sec);                              \
112         static const char __kstrtabns_##sym[]                           \
113         __attribute__((section("__ksymtab_strings"), used, aligned(1))) \
114         = #ns;                                                          \
115         __KSYMTAB_ENTRY_NS(sym, sec)
116
117 #define ___EXPORT_SYMBOL(sym, sec)                                      \
118         ___export_symbol_common(sym, sec);                              \
119         __KSYMTAB_ENTRY(sym, sec)
120
121 #endif
122
123 #if !defined(CONFIG_MODULES) || defined(__DISABLE_EXPORTS)
124
125 /*
126  * Allow symbol exports to be disabled completely so that C code may
127  * be reused in other execution contexts such as the UEFI stub or the
128  * decompressor.
129  */
130 #define __EXPORT_SYMBOL_NS(sym, sec, ns)
131 #define __EXPORT_SYMBOL(sym, sec)
132
133 #elif defined(CONFIG_TRIM_UNUSED_KSYMS)
134
135 #include <generated/autoksyms.h>
136
137 /*
138  * For fine grained build dependencies, we want to tell the build system
139  * about each possible exported symbol even if they're not actually exported.
140  * We use a symbol pattern __ksym_marker_<symbol> that the build system filters
141  * from the $(NM) output (see scripts/gen_ksymdeps.sh). These symbols are
142  * discarded in the final link stage.
143  */
144 #define __ksym_marker(sym)      \
145         static int __ksym_marker_##sym[0] __section(".discard.ksym") __used
146
147 #define __EXPORT_SYMBOL(sym, sec)                               \
148         __ksym_marker(sym);                                     \
149         __cond_export_sym(sym, sec, __is_defined(__KSYM_##sym))
150 #define __cond_export_sym(sym, sec, conf)                       \
151         ___cond_export_sym(sym, sec, conf)
152 #define ___cond_export_sym(sym, sec, enabled)                   \
153         __cond_export_sym_##enabled(sym, sec)
154 #define __cond_export_sym_1(sym, sec) ___EXPORT_SYMBOL(sym, sec)
155 #define __cond_export_sym_0(sym, sec) /* nothing */
156
157 #define __EXPORT_SYMBOL_NS(sym, sec, ns)                                \
158         __ksym_marker(sym);                                             \
159         __cond_export_ns_sym(sym, sec, ns, __is_defined(__KSYM_##sym))
160 #define __cond_export_ns_sym(sym, sec, ns, conf)                        \
161         ___cond_export_ns_sym(sym, sec, ns, conf)
162 #define ___cond_export_ns_sym(sym, sec, ns, enabled)                    \
163         __cond_export_ns_sym_##enabled(sym, sec, ns)
164 #define __cond_export_ns_sym_1(sym, sec, ns) ___EXPORT_SYMBOL_NS(sym, sec, ns)
165 #define __cond_export_ns_sym_0(sym, sec, ns) /* nothing */
166
167 #else
168
169 #define __EXPORT_SYMBOL_NS(sym,sec,ns)  ___EXPORT_SYMBOL_NS(sym,sec,ns)
170 #define __EXPORT_SYMBOL(sym,sec)        ___EXPORT_SYMBOL(sym,sec)
171
172 #endif /* CONFIG_MODULES */
173
174 #ifdef DEFAULT_SYMBOL_NAMESPACE
175 #undef __EXPORT_SYMBOL
176 #define __EXPORT_SYMBOL(sym, sec)                               \
177         __EXPORT_SYMBOL_NS(sym, sec, DEFAULT_SYMBOL_NAMESPACE)
178 #endif
179
180 #define EXPORT_SYMBOL(sym)              __EXPORT_SYMBOL(sym, "")
181 #define EXPORT_SYMBOL_GPL(sym)          __EXPORT_SYMBOL(sym, "_gpl")
182 #define EXPORT_SYMBOL_GPL_FUTURE(sym)   __EXPORT_SYMBOL(sym, "_gpl_future")
183 #define EXPORT_SYMBOL_NS(sym, ns)       __EXPORT_SYMBOL_NS(sym, "", ns)
184 #define EXPORT_SYMBOL_NS_GPL(sym, ns)   __EXPORT_SYMBOL_NS(sym, "_gpl", ns)
185
186 #ifdef CONFIG_UNUSED_SYMBOLS
187 #define EXPORT_UNUSED_SYMBOL(sym)       __EXPORT_SYMBOL(sym, "_unused")
188 #define EXPORT_UNUSED_SYMBOL_GPL(sym)   __EXPORT_SYMBOL(sym, "_unused_gpl")
189 #else
190 #define EXPORT_UNUSED_SYMBOL(sym)
191 #define EXPORT_UNUSED_SYMBOL_GPL(sym)
192 #endif
193
194 #endif /* !__ASSEMBLY__ */
195
196 #endif /* _LINUX_EXPORT_H */