Linux 6.16-rc6
[linux-block.git] / include / linux / export.h
CommitLineData
bf49d9dd 1/* SPDX-License-Identifier: GPL-2.0-only */
f5016932
PG
2#ifndef _LINUX_EXPORT_H
3#define _LINUX_EXPORT_H
b67067f1 4
ddb5cdba
MY
5#include <linux/compiler.h>
6#include <linux/linkage.h>
d143b9db
GKH
7#include <linux/stringify.h>
8
7b453719
MY
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
ddb5cdba
MY
17#ifdef CONFIG_64BIT
18#define __EXPORT_SYMBOL_REF(sym) \
19 .balign 8 ASM_NL \
20 .quad sym
7290d580 21#else
ddb5cdba
MY
22#define __EXPORT_SYMBOL_REF(sym) \
23 .balign 4 ASM_NL \
24 .long sym
7290d580
AB
25#endif
26
707f853d
PZ
27/*
28 * LLVM integrated assembler cam merge adjacent string literals (like
29 * C and GNU-as) passed to '.ascii', but not to '.asciz' and chokes on:
30 *
31 * .asciz "MODULE_" "kvm" ;
32 */
33#define ___EXPORT_SYMBOL(sym, license, ns...) \
ddb5cdba
MY
34 .section ".export_symbol","a" ASM_NL \
35 __export_symbol_##sym: ASM_NL \
36 .asciz license ASM_NL \
707f853d 37 .ascii ns "\0" ASM_NL \
ddb5cdba
MY
38 __EXPORT_SYMBOL_REF(sym) ASM_NL \
39 .previous
40
481461f5 41#if defined(__DISABLE_EXPORTS)
f922c4ab
AB
42
43/*
44 * Allow symbol exports to be disabled completely so that C code may
45 * be reused in other execution contexts such as the UEFI stub or the
46 * decompressor.
47 */
8ed7e33a 48#define __EXPORT_SYMBOL(sym, license, ns)
f922c4ab 49
5e9e95cc 50#elif defined(__GENKSYMS__)
bbda5ec6 51
8ed7e33a 52#define __EXPORT_SYMBOL(sym, license, ns) __GENKSYMS_EXPORT_SYMBOL(sym)
c1a95fda 53
5e9e95cc 54#elif defined(__ASSEMBLY__)
ddb5cdba 55
5e9e95cc
MY
56#define __EXPORT_SYMBOL(sym, license, ns) \
57 ___EXPORT_SYMBOL(sym, license, ns)
8651ec01 58
f2355416 59#else
f2355416 60
d7476f24
ST
61#ifdef CONFIG_GENDWARFKSYMS
62/*
63 * With CONFIG_GENDWARFKSYMS, ensure the compiler emits debugging
64 * information for all exported symbols, including those defined in
65 * different TUs, by adding a __gendwarfksyms_ptr_<symbol> pointer
66 * that's discarded during the final link.
67 */
68#define __GENDWARFKSYMS_EXPORT(sym) \
69 static typeof(sym) *__gendwarfksyms_ptr_##sym __used \
70 __section(".discard.gendwarfksyms") = &sym;
71#else
72#define __GENDWARFKSYMS_EXPORT(sym)
73#endif
74
5e9e95cc
MY
75#define __EXPORT_SYMBOL(sym, license, ns) \
76 extern typeof(sym) sym; \
77 __ADDRESSABLE(sym) \
d7476f24 78 __GENDWARFKSYMS_EXPORT(sym) \
5e9e95cc 79 asm(__stringify(___EXPORT_SYMBOL(sym, license, ns)))
f5016932 80
481461f5 81#endif
f5016932 82
8e2adc6a 83#ifdef DEFAULT_SYMBOL_NAMESPACE
ceb8bf2c 84#define _EXPORT_SYMBOL(sym, license) __EXPORT_SYMBOL(sym, license, DEFAULT_SYMBOL_NAMESPACE)
c3a6cf19 85#else
8ed7e33a 86#define _EXPORT_SYMBOL(sym, license) __EXPORT_SYMBOL(sym, license, "")
8e2adc6a
MM
87#endif
88
c3a6cf19 89#define EXPORT_SYMBOL(sym) _EXPORT_SYMBOL(sym, "")
ddb5cdba 90#define EXPORT_SYMBOL_GPL(sym) _EXPORT_SYMBOL(sym, "GPL")
cdd30ebb
PZ
91#define EXPORT_SYMBOL_NS(sym, ns) __EXPORT_SYMBOL(sym, "", ns)
92#define EXPORT_SYMBOL_NS_GPL(sym, ns) __EXPORT_SYMBOL(sym, "GPL", ns)
f5016932 93
707f853d
PZ
94#define EXPORT_SYMBOL_GPL_FOR_MODULES(sym, mods) __EXPORT_SYMBOL(sym, "GPL", "module:" mods)
95
f5016932 96#endif /* _LINUX_EXPORT_H */