| 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 | /* |
| 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...) \ |
| 34 | .section ".export_symbol","a" ASM_NL \ |
| 35 | __export_symbol_##sym: ASM_NL \ |
| 36 | .asciz license ASM_NL \ |
| 37 | .ascii ns "\0" ASM_NL \ |
| 38 | __EXPORT_SYMBOL_REF(sym) ASM_NL \ |
| 39 | .previous |
| 40 | |
| 41 | #if defined(__DISABLE_EXPORTS) |
| 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 | */ |
| 48 | #define __EXPORT_SYMBOL(sym, license, ns) |
| 49 | |
| 50 | #elif defined(__GENKSYMS__) |
| 51 | |
| 52 | #define __EXPORT_SYMBOL(sym, license, ns) __GENKSYMS_EXPORT_SYMBOL(sym) |
| 53 | |
| 54 | #elif defined(__ASSEMBLY__) |
| 55 | |
| 56 | #define __EXPORT_SYMBOL(sym, license, ns) \ |
| 57 | ___EXPORT_SYMBOL(sym, license, ns) |
| 58 | |
| 59 | #else |
| 60 | |
| 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 | |
| 75 | #define __EXPORT_SYMBOL(sym, license, ns) \ |
| 76 | extern typeof(sym) sym; \ |
| 77 | __ADDRESSABLE(sym) \ |
| 78 | __GENDWARFKSYMS_EXPORT(sym) \ |
| 79 | asm(__stringify(___EXPORT_SYMBOL(sym, license, ns))) |
| 80 | |
| 81 | #endif |
| 82 | |
| 83 | #ifdef DEFAULT_SYMBOL_NAMESPACE |
| 84 | #define _EXPORT_SYMBOL(sym, license) __EXPORT_SYMBOL(sym, license, DEFAULT_SYMBOL_NAMESPACE) |
| 85 | #else |
| 86 | #define _EXPORT_SYMBOL(sym, license) __EXPORT_SYMBOL(sym, license, "") |
| 87 | #endif |
| 88 | |
| 89 | #define EXPORT_SYMBOL(sym) _EXPORT_SYMBOL(sym, "") |
| 90 | #define EXPORT_SYMBOL_GPL(sym) _EXPORT_SYMBOL(sym, "GPL") |
| 91 | #define EXPORT_SYMBOL_NS(sym, ns) __EXPORT_SYMBOL(sym, "", ns) |
| 92 | #define EXPORT_SYMBOL_NS_GPL(sym, ns) __EXPORT_SYMBOL(sym, "GPL", ns) |
| 93 | |
| 94 | #define EXPORT_SYMBOL_GPL_FOR_MODULES(sym, mods) __EXPORT_SYMBOL(sym, "GPL", "module:" mods) |
| 95 | |
| 96 | #endif /* _LINUX_EXPORT_H */ |
| 97 | |