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 | |
Rusty Russell | b92021b | 2013-03-15 15:04:17 +1030 | [diff] [blame] | 13 | #ifndef __ASSEMBLY__ |
Paul Gortmaker | f501693 | 2011-05-23 14:11:39 -0400 | [diff] [blame] | 14 | #ifdef MODULE |
| 15 | extern struct module __this_module; |
| 16 | #define THIS_MODULE (&__this_module) |
| 17 | #else |
| 18 | #define THIS_MODULE ((struct module *)0) |
| 19 | #endif |
| 20 | |
| 21 | #ifdef CONFIG_MODULES |
| 22 | |
Nicolas Pitre | f235541 | 2016-01-22 01:32:26 -0500 | [diff] [blame] | 23 | #if defined(__KERNEL__) && !defined(__GENKSYMS__) |
Paul Gortmaker | f501693 | 2011-05-23 14:11:39 -0400 | [diff] [blame] | 24 | #ifdef CONFIG_MODVERSIONS |
| 25 | /* Mark the CRC weak since genksyms apparently decides not to |
| 26 | * generate a checksums for some symbols */ |
Ard Biesheuvel | 71810db | 2017-02-03 09:54:06 +0000 | [diff] [blame] | 27 | #if defined(CONFIG_MODULE_REL_CRCS) |
| 28 | #define __CRC_SYMBOL(sym, sec) \ |
| 29 | asm(" .section \"___kcrctab" sec "+" #sym "\", \"a\" \n" \ |
Masahiro Yamada | 94e58e0 | 2018-05-09 16:23:49 +0900 | [diff] [blame] | 30 | " .weak __crc_" #sym " \n" \ |
| 31 | " .long __crc_" #sym " - . \n" \ |
Ard Biesheuvel | 71810db | 2017-02-03 09:54:06 +0000 | [diff] [blame] | 32 | " .previous \n"); |
Paul Gortmaker | f501693 | 2011-05-23 14:11:39 -0400 | [diff] [blame] | 33 | #else |
Ard Biesheuvel | 71810db | 2017-02-03 09:54:06 +0000 | [diff] [blame] | 34 | #define __CRC_SYMBOL(sym, sec) \ |
| 35 | asm(" .section \"___kcrctab" sec "+" #sym "\", \"a\" \n" \ |
Masahiro Yamada | 94e58e0 | 2018-05-09 16:23:49 +0900 | [diff] [blame] | 36 | " .weak __crc_" #sym " \n" \ |
| 37 | " .long __crc_" #sym " \n" \ |
Ard Biesheuvel | 71810db | 2017-02-03 09:54:06 +0000 | [diff] [blame] | 38 | " .previous \n"); |
| 39 | #endif |
| 40 | #else |
Paul Gortmaker | f501693 | 2011-05-23 14:11:39 -0400 | [diff] [blame] | 41 | #define __CRC_SYMBOL(sym, sec) |
| 42 | #endif |
| 43 | |
Ard Biesheuvel | 7290d58 | 2018-08-21 21:56:09 -0700 | [diff] [blame] | 44 | #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS |
| 45 | #include <linux/compiler.h> |
| 46 | /* |
| 47 | * Emit the ksymtab entry as a pair of relative references: this reduces |
| 48 | * the size by half on 64-bit architectures, and eliminates the need for |
| 49 | * absolute relocations that require runtime processing on relocatable |
| 50 | * kernels. |
| 51 | */ |
| 52 | #define __KSYMTAB_ENTRY(sym, sec) \ |
| 53 | __ADDRESSABLE(sym) \ |
| 54 | asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \ |
| 55 | " .balign 8 \n" \ |
| 56 | "__ksymtab_" #sym ": \n" \ |
| 57 | " .long " #sym "- . \n" \ |
| 58 | " .long __kstrtab_" #sym "- . \n" \ |
| 59 | " .previous \n") |
| 60 | |
| 61 | struct kernel_symbol { |
| 62 | int value_offset; |
| 63 | int name_offset; |
| 64 | }; |
| 65 | #else |
| 66 | #define __KSYMTAB_ENTRY(sym, sec) \ |
| 67 | static const struct kernel_symbol __ksymtab_##sym \ |
| 68 | __attribute__((section("___ksymtab" sec "+" #sym), used)) \ |
| 69 | = { (unsigned long)&sym, __kstrtab_##sym } |
| 70 | |
| 71 | struct kernel_symbol { |
| 72 | unsigned long value; |
| 73 | const char *name; |
| 74 | }; |
| 75 | #endif |
| 76 | |
Paul Gortmaker | f501693 | 2011-05-23 14:11:39 -0400 | [diff] [blame] | 77 | /* For every exported symbol, place a struct in the __ksymtab section */ |
Nicholas Piggin | b67067f | 2016-08-24 22:29:20 +1000 | [diff] [blame] | 78 | #define ___EXPORT_SYMBOL(sym, sec) \ |
| 79 | extern typeof(sym) sym; \ |
| 80 | __CRC_SYMBOL(sym, sec) \ |
| 81 | static const char __kstrtab_##sym[] \ |
Ard Biesheuvel | 7290d58 | 2018-08-21 21:56:09 -0700 | [diff] [blame] | 82 | __attribute__((section("__ksymtab_strings"), used, aligned(1))) \ |
Masahiro Yamada | 94e58e0 | 2018-05-09 16:23:49 +0900 | [diff] [blame] | 83 | = #sym; \ |
Ard Biesheuvel | 7290d58 | 2018-08-21 21:56:09 -0700 | [diff] [blame] | 84 | __KSYMTAB_ENTRY(sym, sec) |
Paul Gortmaker | f501693 | 2011-05-23 14:11:39 -0400 | [diff] [blame] | 85 | |
Ard Biesheuvel | f922c4a | 2018-08-21 21:56:04 -0700 | [diff] [blame] | 86 | #if defined(__DISABLE_EXPORTS) |
| 87 | |
| 88 | /* |
| 89 | * Allow symbol exports to be disabled completely so that C code may |
| 90 | * be reused in other execution contexts such as the UEFI stub or the |
| 91 | * decompressor. |
| 92 | */ |
| 93 | #define __EXPORT_SYMBOL(sym, sec) |
| 94 | |
| 95 | #elif defined(__KSYM_DEPS__) |
Nicolas Pitre | c1a95fd | 2016-01-22 13:41:57 -0500 | [diff] [blame] | 96 | |
| 97 | /* |
| 98 | * For fine grained build dependencies, we want to tell the build system |
| 99 | * about each possible exported symbol even if they're not actually exported. |
| 100 | * We use a string pattern that is unlikely to be valid code that the build |
| 101 | * system filters out from the preprocessor output (see ksym_dep_filter |
| 102 | * in scripts/Kbuild.include). |
| 103 | */ |
| 104 | #define __EXPORT_SYMBOL(sym, sec) === __KSYM_##sym === |
| 105 | |
| 106 | #elif defined(CONFIG_TRIM_UNUSED_KSYMS) |
Nicolas Pitre | f235541 | 2016-01-22 01:32:26 -0500 | [diff] [blame] | 107 | |
Nicolas Pitre | f235541 | 2016-01-22 01:32:26 -0500 | [diff] [blame] | 108 | #include <generated/autoksyms.h> |
| 109 | |
| 110 | #define __EXPORT_SYMBOL(sym, sec) \ |
Masahiro Yamada | 6023d23 | 2016-06-14 14:58:55 +0900 | [diff] [blame] | 111 | __cond_export_sym(sym, sec, __is_defined(__KSYM_##sym)) |
Nicolas Pitre | f235541 | 2016-01-22 01:32:26 -0500 | [diff] [blame] | 112 | #define __cond_export_sym(sym, sec, conf) \ |
| 113 | ___cond_export_sym(sym, sec, conf) |
| 114 | #define ___cond_export_sym(sym, sec, enabled) \ |
| 115 | __cond_export_sym_##enabled(sym, sec) |
| 116 | #define __cond_export_sym_1(sym, sec) ___EXPORT_SYMBOL(sym, sec) |
| 117 | #define __cond_export_sym_0(sym, sec) /* nothing */ |
| 118 | |
| 119 | #else |
| 120 | #define __EXPORT_SYMBOL ___EXPORT_SYMBOL |
| 121 | #endif |
| 122 | |
Paul Gortmaker | f501693 | 2011-05-23 14:11:39 -0400 | [diff] [blame] | 123 | #define EXPORT_SYMBOL(sym) \ |
| 124 | __EXPORT_SYMBOL(sym, "") |
| 125 | |
| 126 | #define EXPORT_SYMBOL_GPL(sym) \ |
| 127 | __EXPORT_SYMBOL(sym, "_gpl") |
| 128 | |
| 129 | #define EXPORT_SYMBOL_GPL_FUTURE(sym) \ |
| 130 | __EXPORT_SYMBOL(sym, "_gpl_future") |
| 131 | |
| 132 | #ifdef CONFIG_UNUSED_SYMBOLS |
| 133 | #define EXPORT_UNUSED_SYMBOL(sym) __EXPORT_SYMBOL(sym, "_unused") |
| 134 | #define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl") |
| 135 | #else |
| 136 | #define EXPORT_UNUSED_SYMBOL(sym) |
| 137 | #define EXPORT_UNUSED_SYMBOL_GPL(sym) |
| 138 | #endif |
| 139 | |
| 140 | #endif /* __GENKSYMS__ */ |
| 141 | |
| 142 | #else /* !CONFIG_MODULES... */ |
| 143 | |
| 144 | #define EXPORT_SYMBOL(sym) |
| 145 | #define EXPORT_SYMBOL_GPL(sym) |
| 146 | #define EXPORT_SYMBOL_GPL_FUTURE(sym) |
| 147 | #define EXPORT_UNUSED_SYMBOL(sym) |
| 148 | #define EXPORT_UNUSED_SYMBOL_GPL(sym) |
| 149 | |
| 150 | #endif /* CONFIG_MODULES */ |
Rusty Russell | b92021b | 2013-03-15 15:04:17 +1030 | [diff] [blame] | 151 | #endif /* !__ASSEMBLY__ */ |
Paul Gortmaker | f501693 | 2011-05-23 14:11:39 -0400 | [diff] [blame] | 152 | |
| 153 | #endif /* _LINUX_EXPORT_H */ |