Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 #ifndef _LINUX_EXPORT_H
0003 #define _LINUX_EXPORT_H
0004 
0005 #include <linux/stringify.h>
0006 
0007 /*
0008  * Export symbols from the kernel to modules.  Forked from module.h
0009  * to reduce the amount of pointless cruft we feed to gcc when only
0010  * exporting a simple symbol or two.
0011  *
0012  * Try not to add #includes here.  It slows compilation and makes kernel
0013  * hackers place grumpy comments in header files.
0014  */
0015 
0016 /*
0017  * This comment block is used by fixdep. Please do not remove.
0018  *
0019  * When CONFIG_MODVERSIONS is changed from n to y, all source files having
0020  * EXPORT_SYMBOL variants must be re-compiled because genksyms is run as a
0021  * side effect of the *.o build rule.
0022  */
0023 
0024 #ifndef __ASSEMBLY__
0025 #ifdef MODULE
0026 extern struct module __this_module;
0027 #define THIS_MODULE (&__this_module)
0028 #else
0029 #define THIS_MODULE ((struct module *)0)
0030 #endif
0031 
0032 #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
0033 #include <linux/compiler.h>
0034 /*
0035  * Emit the ksymtab entry as a pair of relative references: this reduces
0036  * the size by half on 64-bit architectures, and eliminates the need for
0037  * absolute relocations that require runtime processing on relocatable
0038  * kernels.
0039  */
0040 #define __KSYMTAB_ENTRY(sym, sec)                   \
0041     __ADDRESSABLE(sym)                      \
0042     asm("   .section \"___ksymtab" sec "+" #sym "\", \"a\"  \n" \
0043         "   .balign 4                   \n" \
0044         "__ksymtab_" #sym ":                \n" \
0045         "   .long   " #sym "- .             \n" \
0046         "   .long   __kstrtab_" #sym "- .           \n" \
0047         "   .long   __kstrtabns_" #sym "- .         \n" \
0048         "   .previous                   \n")
0049 
0050 struct kernel_symbol {
0051     int value_offset;
0052     int name_offset;
0053     int namespace_offset;
0054 };
0055 #else
0056 #define __KSYMTAB_ENTRY(sym, sec)                   \
0057     static const struct kernel_symbol __ksymtab_##sym       \
0058     __attribute__((section("___ksymtab" sec "+" #sym), used))   \
0059     __aligned(sizeof(void *))                   \
0060     = { (unsigned long)&sym, __kstrtab_##sym, __kstrtabns_##sym }
0061 
0062 struct kernel_symbol {
0063     unsigned long value;
0064     const char *name;
0065     const char *namespace;
0066 };
0067 #endif
0068 
0069 #ifdef __GENKSYMS__
0070 
0071 #define ___EXPORT_SYMBOL(sym, sec, ns)  __GENKSYMS_EXPORT_SYMBOL(sym)
0072 
0073 #else
0074 
0075 /*
0076  * For every exported symbol, do the following:
0077  *
0078  * - Put the name of the symbol and namespace (empty string "" for none) in
0079  *   __ksymtab_strings.
0080  * - Place a struct kernel_symbol entry in the __ksymtab section.
0081  *
0082  * note on .section use: we specify progbits since usage of the "M" (SHF_MERGE)
0083  * section flag requires it. Use '%progbits' instead of '@progbits' since the
0084  * former apparently works on all arches according to the binutils source.
0085  */
0086 #define ___EXPORT_SYMBOL(sym, sec, ns)                      \
0087     extern typeof(sym) sym;                         \
0088     extern const char __kstrtab_##sym[];                    \
0089     extern const char __kstrtabns_##sym[];                  \
0090     asm("   .section \"__ksymtab_strings\",\"aMS\",%progbits,1  \n" \
0091         "__kstrtab_" #sym ":                    \n" \
0092         "   .asciz  \"" #sym "\"                    \n" \
0093         "__kstrtabns_" #sym ":                  \n" \
0094         "   .asciz  \"" ns "\"                  \n" \
0095         "   .previous                       \n");   \
0096     __KSYMTAB_ENTRY(sym, sec)
0097 
0098 #endif
0099 
0100 #if !defined(CONFIG_MODULES) || defined(__DISABLE_EXPORTS)
0101 
0102 /*
0103  * Allow symbol exports to be disabled completely so that C code may
0104  * be reused in other execution contexts such as the UEFI stub or the
0105  * decompressor.
0106  */
0107 #define __EXPORT_SYMBOL(sym, sec, ns)
0108 
0109 #elif defined(CONFIG_TRIM_UNUSED_KSYMS)
0110 
0111 #include <generated/autoksyms.h>
0112 
0113 /*
0114  * For fine grained build dependencies, we want to tell the build system
0115  * about each possible exported symbol even if they're not actually exported.
0116  * We use a symbol pattern __ksym_marker_<symbol> that the build system filters
0117  * from the $(NM) output (see scripts/gen_ksymdeps.sh). These symbols are
0118  * discarded in the final link stage.
0119  */
0120 #define __ksym_marker(sym)  \
0121     static int __ksym_marker_##sym[0] __section(".discard.ksym") __used
0122 
0123 #define __EXPORT_SYMBOL(sym, sec, ns)                   \
0124     __ksym_marker(sym);                     \
0125     __cond_export_sym(sym, sec, ns, __is_defined(__KSYM_##sym))
0126 #define __cond_export_sym(sym, sec, ns, conf)               \
0127     ___cond_export_sym(sym, sec, ns, conf)
0128 #define ___cond_export_sym(sym, sec, ns, enabled)           \
0129     __cond_export_sym_##enabled(sym, sec, ns)
0130 #define __cond_export_sym_1(sym, sec, ns) ___EXPORT_SYMBOL(sym, sec, ns)
0131 
0132 #ifdef __GENKSYMS__
0133 #define __cond_export_sym_0(sym, sec, ns) __GENKSYMS_EXPORT_SYMBOL(sym)
0134 #else
0135 #define __cond_export_sym_0(sym, sec, ns) /* nothing */
0136 #endif
0137 
0138 #else
0139 
0140 #define __EXPORT_SYMBOL(sym, sec, ns)   ___EXPORT_SYMBOL(sym, sec, ns)
0141 
0142 #endif /* CONFIG_MODULES */
0143 
0144 #ifdef DEFAULT_SYMBOL_NAMESPACE
0145 #define _EXPORT_SYMBOL(sym, sec)    __EXPORT_SYMBOL(sym, sec, __stringify(DEFAULT_SYMBOL_NAMESPACE))
0146 #else
0147 #define _EXPORT_SYMBOL(sym, sec)    __EXPORT_SYMBOL(sym, sec, "")
0148 #endif
0149 
0150 #define EXPORT_SYMBOL(sym)      _EXPORT_SYMBOL(sym, "")
0151 #define EXPORT_SYMBOL_GPL(sym)      _EXPORT_SYMBOL(sym, "_gpl")
0152 #define EXPORT_SYMBOL_NS(sym, ns)   __EXPORT_SYMBOL(sym, "", __stringify(ns))
0153 #define EXPORT_SYMBOL_NS_GPL(sym, ns)   __EXPORT_SYMBOL(sym, "_gpl", __stringify(ns))
0154 
0155 #endif /* !__ASSEMBLY__ */
0156 
0157 #endif /* _LINUX_EXPORT_H */