Paul Gortmaker | f501693 | 2011-05-23 14:11:39 -0400 | [diff] [blame] | 1 | #ifndef _LINUX_EXPORT_H |
| 2 | #define _LINUX_EXPORT_H |
| 3 | /* |
| 4 | * Export symbols from the kernel to modules. Forked from module.h |
| 5 | * to reduce the amount of pointless cruft we feed to gcc when only |
| 6 | * exporting a simple symbol or two. |
| 7 | * |
Rusty Russell | b92021b | 2013-03-15 15:04:17 +1030 | [diff] [blame] | 8 | * Try not to add #includes here. It slows compilation and makes kernel |
| 9 | * hackers place grumpy comments in header files. |
Paul Gortmaker | f501693 | 2011-05-23 14:11:39 -0400 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | /* Some toolchains use a `_' prefix for all user symbols. */ |
Rusty Russell | b92021b | 2013-03-15 15:04:17 +1030 | [diff] [blame] | 13 | #ifdef CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX |
| 14 | #define __VMLINUX_SYMBOL(x) _##x |
| 15 | #define __VMLINUX_SYMBOL_STR(x) "_" #x |
Paul Gortmaker | f501693 | 2011-05-23 14:11:39 -0400 | [diff] [blame] | 16 | #else |
Rusty Russell | b92021b | 2013-03-15 15:04:17 +1030 | [diff] [blame] | 17 | #define __VMLINUX_SYMBOL(x) x |
| 18 | #define __VMLINUX_SYMBOL_STR(x) #x |
Paul Gortmaker | f501693 | 2011-05-23 14:11:39 -0400 | [diff] [blame] | 19 | #endif |
| 20 | |
Rusty Russell | b92021b | 2013-03-15 15:04:17 +1030 | [diff] [blame] | 21 | /* Indirect, so macros are expanded before pasting. */ |
| 22 | #define VMLINUX_SYMBOL(x) __VMLINUX_SYMBOL(x) |
| 23 | #define VMLINUX_SYMBOL_STR(x) __VMLINUX_SYMBOL_STR(x) |
| 24 | |
| 25 | #ifndef __ASSEMBLY__ |
Paul Gortmaker | f501693 | 2011-05-23 14:11:39 -0400 | [diff] [blame] | 26 | struct kernel_symbol |
| 27 | { |
| 28 | unsigned long value; |
| 29 | const char *name; |
| 30 | }; |
| 31 | |
| 32 | #ifdef MODULE |
| 33 | extern struct module __this_module; |
| 34 | #define THIS_MODULE (&__this_module) |
| 35 | #else |
| 36 | #define THIS_MODULE ((struct module *)0) |
| 37 | #endif |
| 38 | |
| 39 | #ifdef CONFIG_MODULES |
| 40 | |
| 41 | #ifndef __GENKSYMS__ |
| 42 | #ifdef CONFIG_MODVERSIONS |
| 43 | /* Mark the CRC weak since genksyms apparently decides not to |
| 44 | * generate a checksums for some symbols */ |
| 45 | #define __CRC_SYMBOL(sym, sec) \ |
Andi Kleen | e0f244c | 2013-10-23 10:57:58 +1030 | [diff] [blame] | 46 | extern __visible void *__crc_##sym __attribute__((weak)); \ |
Paul Gortmaker | f501693 | 2011-05-23 14:11:39 -0400 | [diff] [blame] | 47 | static const unsigned long __kcrctab_##sym \ |
| 48 | __used \ |
| 49 | __attribute__((section("___kcrctab" sec "+" #sym), unused)) \ |
| 50 | = (unsigned long) &__crc_##sym; |
| 51 | #else |
| 52 | #define __CRC_SYMBOL(sym, sec) |
| 53 | #endif |
| 54 | |
| 55 | /* For every exported symbol, place a struct in the __ksymtab section */ |
| 56 | #define __EXPORT_SYMBOL(sym, sec) \ |
| 57 | extern typeof(sym) sym; \ |
| 58 | __CRC_SYMBOL(sym, sec) \ |
| 59 | static const char __kstrtab_##sym[] \ |
| 60 | __attribute__((section("__ksymtab_strings"), aligned(1))) \ |
Rusty Russell | b92021b | 2013-03-15 15:04:17 +1030 | [diff] [blame] | 61 | = VMLINUX_SYMBOL_STR(sym); \ |
Andi Kleen | e0f244c | 2013-10-23 10:57:58 +1030 | [diff] [blame] | 62 | __visible const struct kernel_symbol __ksymtab_##sym \ |
Paul Gortmaker | f501693 | 2011-05-23 14:11:39 -0400 | [diff] [blame] | 63 | __used \ |
| 64 | __attribute__((section("___ksymtab" sec "+" #sym), unused)) \ |
| 65 | = { (unsigned long)&sym, __kstrtab_##sym } |
| 66 | |
| 67 | #define EXPORT_SYMBOL(sym) \ |
| 68 | __EXPORT_SYMBOL(sym, "") |
| 69 | |
| 70 | #define EXPORT_SYMBOL_GPL(sym) \ |
| 71 | __EXPORT_SYMBOL(sym, "_gpl") |
| 72 | |
| 73 | #define EXPORT_SYMBOL_GPL_FUTURE(sym) \ |
| 74 | __EXPORT_SYMBOL(sym, "_gpl_future") |
| 75 | |
| 76 | #ifdef CONFIG_UNUSED_SYMBOLS |
| 77 | #define EXPORT_UNUSED_SYMBOL(sym) __EXPORT_SYMBOL(sym, "_unused") |
| 78 | #define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl") |
| 79 | #else |
| 80 | #define EXPORT_UNUSED_SYMBOL(sym) |
| 81 | #define EXPORT_UNUSED_SYMBOL_GPL(sym) |
| 82 | #endif |
| 83 | |
| 84 | #endif /* __GENKSYMS__ */ |
| 85 | |
| 86 | #else /* !CONFIG_MODULES... */ |
| 87 | |
| 88 | #define EXPORT_SYMBOL(sym) |
| 89 | #define EXPORT_SYMBOL_GPL(sym) |
| 90 | #define EXPORT_SYMBOL_GPL_FUTURE(sym) |
| 91 | #define EXPORT_UNUSED_SYMBOL(sym) |
| 92 | #define EXPORT_UNUSED_SYMBOL_GPL(sym) |
| 93 | |
| 94 | #endif /* CONFIG_MODULES */ |
Rusty Russell | b92021b | 2013-03-15 15:04:17 +1030 | [diff] [blame] | 95 | #endif /* !__ASSEMBLY__ */ |
Paul Gortmaker | f501693 | 2011-05-23 14:11:39 -0400 | [diff] [blame] | 96 | |
| 97 | #endif /* _LINUX_EXPORT_H */ |