xref: /openbmc/linux/include/linux/export.h (revision d2a3b501)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #ifndef _LINUX_EXPORT_H
3 #define _LINUX_EXPORT_H
4 
5 #include <linux/compiler.h>
6 #include <linux/linkage.h>
7 #include <linux/stringify.h>
8 
9 /*
10  * Export symbols from the kernel to modules.  Forked from module.h
11  * to reduce the amount of pointless cruft we feed to gcc when only
12  * exporting a simple symbol or two.
13  *
14  * Try not to add #includes here.  It slows compilation and makes kernel
15  * hackers place grumpy comments in header files.
16  */
17 
18 /*
19  * This comment block is used by fixdep. Please do not remove.
20  *
21  * When CONFIG_MODVERSIONS is changed from n to y, all source files having
22  * EXPORT_SYMBOL variants must be re-compiled because genksyms is run as a
23  * side effect of the *.o build rule.
24  */
25 
26 #ifndef __ASSEMBLY__
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 #endif /* __ASSEMBLY__ */
34 
35 #ifdef CONFIG_64BIT
36 #define __EXPORT_SYMBOL_REF(sym)			\
37 	.balign 8				ASM_NL	\
38 	.quad sym
39 #else
40 #define __EXPORT_SYMBOL_REF(sym)			\
41 	.balign 4				ASM_NL	\
42 	.long sym
43 #endif
44 
45 #define ___EXPORT_SYMBOL(sym, license, ns)		\
46 	.section ".export_symbol","a"		ASM_NL	\
47 	__export_symbol_##sym:			ASM_NL	\
48 		.asciz license			ASM_NL	\
49 		.asciz ns			ASM_NL	\
50 		__EXPORT_SYMBOL_REF(sym)	ASM_NL	\
51 	.previous
52 
53 #if defined(__DISABLE_EXPORTS)
54 
55 /*
56  * Allow symbol exports to be disabled completely so that C code may
57  * be reused in other execution contexts such as the UEFI stub or the
58  * decompressor.
59  */
60 #define __EXPORT_SYMBOL(sym, license, ns)
61 
62 #elif defined(__GENKSYMS__)
63 
64 #define __EXPORT_SYMBOL(sym, license, ns)	__GENKSYMS_EXPORT_SYMBOL(sym)
65 
66 #elif defined(__ASSEMBLY__)
67 
68 #define __EXPORT_SYMBOL(sym, license, ns) \
69 	___EXPORT_SYMBOL(sym, license, ns)
70 
71 #else
72 
73 #define __EXPORT_SYMBOL(sym, license, ns)			\
74 	extern typeof(sym) sym;					\
75 	__ADDRESSABLE(sym)					\
76 	asm(__stringify(___EXPORT_SYMBOL(sym, license, ns)))
77 
78 #endif
79 
80 #ifdef DEFAULT_SYMBOL_NAMESPACE
81 #define _EXPORT_SYMBOL(sym, license)	__EXPORT_SYMBOL(sym, license, __stringify(DEFAULT_SYMBOL_NAMESPACE))
82 #else
83 #define _EXPORT_SYMBOL(sym, license)	__EXPORT_SYMBOL(sym, license, "")
84 #endif
85 
86 #define EXPORT_SYMBOL(sym)		_EXPORT_SYMBOL(sym, "")
87 #define EXPORT_SYMBOL_GPL(sym)		_EXPORT_SYMBOL(sym, "GPL")
88 #define EXPORT_SYMBOL_NS(sym, ns)	__EXPORT_SYMBOL(sym, "", __stringify(ns))
89 #define EXPORT_SYMBOL_NS_GPL(sym, ns)	__EXPORT_SYMBOL(sym, "GPL", __stringify(ns))
90 
91 #endif /* _LINUX_EXPORT_H */
92