Paul Gortmaker | f501693 | 2011-05-23 14:11:39 -0400 | [diff] [blame] | 1 | #ifndef _LINUX_EXPORT_H |
| 2 | #define _LINUX_EXPORT_H |
Nicholas Piggin | b67067f | 2016-08-24 22:29:20 +1000 | [diff] [blame] | 3 | |
Paul Gortmaker | f501693 | 2011-05-23 14:11:39 -0400 | [diff] [blame] | 4 | /* |
| 5 | * Export symbols from the kernel to modules. Forked from module.h |
| 6 | * to reduce the amount of pointless cruft we feed to gcc when only |
| 7 | * exporting a simple symbol or two. |
| 8 | * |
Rusty Russell | b92021b | 2013-03-15 15:04:17 +1030 | [diff] [blame] | 9 | * Try not to add #includes here. It slows compilation and makes kernel |
| 10 | * hackers place grumpy comments in header files. |
Paul Gortmaker | f501693 | 2011-05-23 14:11:39 -0400 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | /* Some toolchains use a `_' prefix for all user symbols. */ |
Rusty Russell | b92021b | 2013-03-15 15:04:17 +1030 | [diff] [blame] | 14 | #ifdef CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX |
| 15 | #define __VMLINUX_SYMBOL(x) _##x |
| 16 | #define __VMLINUX_SYMBOL_STR(x) "_" #x |
Paul Gortmaker | f501693 | 2011-05-23 14:11:39 -0400 | [diff] [blame] | 17 | #else |
Rusty Russell | b92021b | 2013-03-15 15:04:17 +1030 | [diff] [blame] | 18 | #define __VMLINUX_SYMBOL(x) x |
| 19 | #define __VMLINUX_SYMBOL_STR(x) #x |
Paul Gortmaker | f501693 | 2011-05-23 14:11:39 -0400 | [diff] [blame] | 20 | #endif |
| 21 | |
Rusty Russell | b92021b | 2013-03-15 15:04:17 +1030 | [diff] [blame] | 22 | /* Indirect, so macros are expanded before pasting. */ |
| 23 | #define VMLINUX_SYMBOL(x) __VMLINUX_SYMBOL(x) |
| 24 | #define VMLINUX_SYMBOL_STR(x) __VMLINUX_SYMBOL_STR(x) |
| 25 | |
| 26 | #ifndef __ASSEMBLY__ |
Paul Gortmaker | f501693 | 2011-05-23 14:11:39 -0400 | [diff] [blame] | 27 | struct kernel_symbol |
| 28 | { |
| 29 | unsigned long value; |
| 30 | const char *name; |
| 31 | }; |
| 32 | |
| 33 | #ifdef MODULE |
| 34 | extern struct module __this_module; |
| 35 | #define THIS_MODULE (&__this_module) |
| 36 | #else |
| 37 | #define THIS_MODULE ((struct module *)0) |
| 38 | #endif |
| 39 | |
| 40 | #ifdef CONFIG_MODULES |
| 41 | |
Nicolas Pitre | f235541 | 2016-01-22 01:32:26 -0500 | [diff] [blame] | 42 | #if defined(__KERNEL__) && !defined(__GENKSYMS__) |
Paul Gortmaker | f501693 | 2011-05-23 14:11:39 -0400 | [diff] [blame] | 43 | #ifdef CONFIG_MODVERSIONS |
| 44 | /* Mark the CRC weak since genksyms apparently decides not to |
| 45 | * generate a checksums for some symbols */ |
Nicholas Piggin | b67067f | 2016-08-24 22:29:20 +1000 | [diff] [blame] | 46 | #define __CRC_SYMBOL(sym, sec) \ |
| 47 | extern __visible void *__crc_##sym __attribute__((weak)); \ |
| 48 | static const unsigned long __kcrctab_##sym \ |
| 49 | __used \ |
| 50 | __attribute__((section("___kcrctab" sec "+" #sym), used)) \ |
Paul Gortmaker | f501693 | 2011-05-23 14:11:39 -0400 | [diff] [blame] | 51 | = (unsigned long) &__crc_##sym; |
| 52 | #else |
| 53 | #define __CRC_SYMBOL(sym, sec) |
| 54 | #endif |
| 55 | |
| 56 | /* For every exported symbol, place a struct in the __ksymtab section */ |
Nicholas Piggin | b67067f | 2016-08-24 22:29:20 +1000 | [diff] [blame] | 57 | #define ___EXPORT_SYMBOL(sym, sec) \ |
| 58 | extern typeof(sym) sym; \ |
| 59 | __CRC_SYMBOL(sym, sec) \ |
| 60 | static const char __kstrtab_##sym[] \ |
| 61 | __attribute__((section("__ksymtab_strings"), aligned(1))) \ |
| 62 | = VMLINUX_SYMBOL_STR(sym); \ |
| 63 | static const struct kernel_symbol __ksymtab_##sym \ |
| 64 | __used \ |
| 65 | __attribute__((section("___ksymtab" sec "+" #sym), used)) \ |
Paul Gortmaker | f501693 | 2011-05-23 14:11:39 -0400 | [diff] [blame] | 66 | = { (unsigned long)&sym, __kstrtab_##sym } |
| 67 | |
Nicolas Pitre | c1a95fd | 2016-01-22 13:41:57 -0500 | [diff] [blame] | 68 | #if defined(__KSYM_DEPS__) |
| 69 | |
| 70 | /* |
| 71 | * For fine grained build dependencies, we want to tell the build system |
| 72 | * about each possible exported symbol even if they're not actually exported. |
| 73 | * We use a string pattern that is unlikely to be valid code that the build |
| 74 | * system filters out from the preprocessor output (see ksym_dep_filter |
| 75 | * in scripts/Kbuild.include). |
| 76 | */ |
| 77 | #define __EXPORT_SYMBOL(sym, sec) === __KSYM_##sym === |
| 78 | |
| 79 | #elif defined(CONFIG_TRIM_UNUSED_KSYMS) |
Nicolas Pitre | f235541 | 2016-01-22 01:32:26 -0500 | [diff] [blame] | 80 | |
Nicolas Pitre | f235541 | 2016-01-22 01:32:26 -0500 | [diff] [blame] | 81 | #include <generated/autoksyms.h> |
| 82 | |
| 83 | #define __EXPORT_SYMBOL(sym, sec) \ |
Masahiro Yamada | 6023d23 | 2016-06-14 14:58:55 +0900 | [diff] [blame] | 84 | __cond_export_sym(sym, sec, __is_defined(__KSYM_##sym)) |
Nicolas Pitre | f235541 | 2016-01-22 01:32:26 -0500 | [diff] [blame] | 85 | #define __cond_export_sym(sym, sec, conf) \ |
| 86 | ___cond_export_sym(sym, sec, conf) |
| 87 | #define ___cond_export_sym(sym, sec, enabled) \ |
| 88 | __cond_export_sym_##enabled(sym, sec) |
| 89 | #define __cond_export_sym_1(sym, sec) ___EXPORT_SYMBOL(sym, sec) |
| 90 | #define __cond_export_sym_0(sym, sec) /* nothing */ |
| 91 | |
| 92 | #else |
| 93 | #define __EXPORT_SYMBOL ___EXPORT_SYMBOL |
| 94 | #endif |
| 95 | |
Paul Gortmaker | f501693 | 2011-05-23 14:11:39 -0400 | [diff] [blame] | 96 | #define EXPORT_SYMBOL(sym) \ |
| 97 | __EXPORT_SYMBOL(sym, "") |
| 98 | |
| 99 | #define EXPORT_SYMBOL_GPL(sym) \ |
| 100 | __EXPORT_SYMBOL(sym, "_gpl") |
| 101 | |
| 102 | #define EXPORT_SYMBOL_GPL_FUTURE(sym) \ |
| 103 | __EXPORT_SYMBOL(sym, "_gpl_future") |
| 104 | |
| 105 | #ifdef CONFIG_UNUSED_SYMBOLS |
| 106 | #define EXPORT_UNUSED_SYMBOL(sym) __EXPORT_SYMBOL(sym, "_unused") |
| 107 | #define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl") |
| 108 | #else |
| 109 | #define EXPORT_UNUSED_SYMBOL(sym) |
| 110 | #define EXPORT_UNUSED_SYMBOL_GPL(sym) |
| 111 | #endif |
| 112 | |
| 113 | #endif /* __GENKSYMS__ */ |
| 114 | |
| 115 | #else /* !CONFIG_MODULES... */ |
| 116 | |
| 117 | #define EXPORT_SYMBOL(sym) |
| 118 | #define EXPORT_SYMBOL_GPL(sym) |
| 119 | #define EXPORT_SYMBOL_GPL_FUTURE(sym) |
| 120 | #define EXPORT_UNUSED_SYMBOL(sym) |
| 121 | #define EXPORT_UNUSED_SYMBOL_GPL(sym) |
| 122 | |
| 123 | #endif /* CONFIG_MODULES */ |
Rusty Russell | b92021b | 2013-03-15 15:04:17 +1030 | [diff] [blame] | 124 | #endif /* !__ASSEMBLY__ */ |
Paul Gortmaker | f501693 | 2011-05-23 14:11:39 -0400 | [diff] [blame] | 125 | |
| 126 | #endif /* _LINUX_EXPORT_H */ |