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 * This comment block is used by fixdep. Please do not remove.
11 *
12 * When CONFIG_MODVERSIONS is changed from n to y, all source files having
13 * EXPORT_SYMBOL variants must be re-compiled because genksyms is run as a
14 * side effect of the *.o build rule.
15 */
16
17#ifdef CONFIG_64BIT
18#define __EXPORT_SYMBOL_REF(sym)			\
19	.balign 8				ASM_NL	\
20	.quad sym
21#else
22#define __EXPORT_SYMBOL_REF(sym)			\
23	.balign 4				ASM_NL	\
24	.long sym
25#endif
26
27#define ___EXPORT_SYMBOL(sym, license, ns)		\
28	.section ".export_symbol","a"		ASM_NL	\
29	__export_symbol_##sym:			ASM_NL	\
30		.asciz license			ASM_NL	\
31		.asciz ns			ASM_NL	\
32		__EXPORT_SYMBOL_REF(sym)	ASM_NL	\
33	.previous
34
35#if defined(__DISABLE_EXPORTS)
36
37/*
38 * Allow symbol exports to be disabled completely so that C code may
39 * be reused in other execution contexts such as the UEFI stub or the
40 * decompressor.
41 */
42#define __EXPORT_SYMBOL(sym, license, ns)
43
44#elif defined(__GENKSYMS__)
45
46#define __EXPORT_SYMBOL(sym, license, ns)	__GENKSYMS_EXPORT_SYMBOL(sym)
47
48#elif defined(__ASSEMBLY__)
49
50#define __EXPORT_SYMBOL(sym, license, ns) \
51	___EXPORT_SYMBOL(sym, license, ns)
52
53#else
54
55#define __EXPORT_SYMBOL(sym, license, ns)			\
56	extern typeof(sym) sym;					\
57	__ADDRESSABLE(sym)					\
58	asm(__stringify(___EXPORT_SYMBOL(sym, license, ns)))
59
60#endif
61
62#ifdef DEFAULT_SYMBOL_NAMESPACE
63#define _EXPORT_SYMBOL(sym, license)	__EXPORT_SYMBOL(sym, license, __stringify(DEFAULT_SYMBOL_NAMESPACE))
64#else
65#define _EXPORT_SYMBOL(sym, license)	__EXPORT_SYMBOL(sym, license, "")
66#endif
67
68#define EXPORT_SYMBOL(sym)		_EXPORT_SYMBOL(sym, "")
69#define EXPORT_SYMBOL_GPL(sym)		_EXPORT_SYMBOL(sym, "GPL")
70#define EXPORT_SYMBOL_NS(sym, ns)	__EXPORT_SYMBOL(sym, "", __stringify(ns))
71#define EXPORT_SYMBOL_NS_GPL(sym, ns)	__EXPORT_SYMBOL(sym, "GPL", __stringify(ns))
72
73#endif /* _LINUX_EXPORT_H */
74