export.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. *
  8. * Try not to add #includes here. It slows compilation and makes kernel
  9. * hackers place grumpy comments in header files.
  10. */
  11. #ifndef __ASSEMBLY__
  12. #ifdef MODULE
  13. extern struct module __this_module;
  14. #define THIS_MODULE (&__this_module)
  15. #else
  16. #define THIS_MODULE ((struct module *)0)
  17. #endif
  18. #ifdef CONFIG_MODULES
  19. #if defined(__KERNEL__) && !defined(__GENKSYMS__)
  20. #ifdef CONFIG_MODVERSIONS
  21. /* Mark the CRC weak since genksyms apparently decides not to
  22. * generate a checksums for some symbols */
  23. #if defined(CONFIG_MODULE_REL_CRCS)
  24. #define __CRC_SYMBOL(sym, sec) \
  25. asm(" .section \"___kcrctab" sec "+" #sym "\", \"a\" \n" \
  26. " .weak __crc_" #sym " \n" \
  27. " .long __crc_" #sym " - . \n" \
  28. " .previous \n");
  29. #else
  30. #define __CRC_SYMBOL(sym, sec) \
  31. asm(" .section \"___kcrctab" sec "+" #sym "\", \"a\" \n" \
  32. " .weak __crc_" #sym " \n" \
  33. " .long __crc_" #sym " \n" \
  34. " .previous \n");
  35. #endif
  36. #else
  37. #define __CRC_SYMBOL(sym, sec)
  38. #endif
  39. #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
  40. #include <linux/compiler.h>
  41. /*
  42. * Emit the ksymtab entry as a pair of relative references: this reduces
  43. * the size by half on 64-bit architectures, and eliminates the need for
  44. * absolute relocations that require runtime processing on relocatable
  45. * kernels.
  46. */
  47. #define __KSYMTAB_ENTRY(sym, sec) \
  48. __ADDRESSABLE(sym) \
  49. asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \
  50. " .balign 8 \n" \
  51. "__ksymtab_" #sym ": \n" \
  52. " .long " #sym "- . \n" \
  53. " .long __kstrtab_" #sym "- . \n" \
  54. " .previous \n")
  55. struct kernel_symbol {
  56. int value_offset;
  57. int name_offset;
  58. };
  59. #else
  60. #define __KSYMTAB_ENTRY(sym, sec) \
  61. static const struct kernel_symbol __ksymtab_##sym \
  62. __attribute__((section("___ksymtab" sec "+" #sym), used)) \
  63. = { (unsigned long)&sym, __kstrtab_##sym }
  64. struct kernel_symbol {
  65. unsigned long value;
  66. const char *name;
  67. };
  68. #endif
  69. /* For every exported symbol, place a struct in the __ksymtab section */
  70. #define ___EXPORT_SYMBOL(sym, sec) \
  71. extern typeof(sym) sym; \
  72. __CRC_SYMBOL(sym, sec) \
  73. static const char __kstrtab_##sym[] \
  74. __attribute__((section("__ksymtab_strings"), used, aligned(1))) \
  75. = #sym; \
  76. __KSYMTAB_ENTRY(sym, sec)
  77. #if defined(__DISABLE_EXPORTS)
  78. /*
  79. * Allow symbol exports to be disabled completely so that C code may
  80. * be reused in other execution contexts such as the UEFI stub or the
  81. * decompressor.
  82. */
  83. #define __EXPORT_SYMBOL(sym, sec)
  84. #elif defined(__KSYM_DEPS__)
  85. /*
  86. * For fine grained build dependencies, we want to tell the build system
  87. * about each possible exported symbol even if they're not actually exported.
  88. * We use a string pattern that is unlikely to be valid code that the build
  89. * system filters out from the preprocessor output (see ksym_dep_filter
  90. * in scripts/Kbuild.include).
  91. */
  92. #define __EXPORT_SYMBOL(sym, sec) === __KSYM_##sym ===
  93. #elif defined(CONFIG_TRIM_UNUSED_KSYMS)
  94. #include <generated/autoksyms.h>
  95. #define __EXPORT_SYMBOL(sym, sec) \
  96. __cond_export_sym(sym, sec, __is_defined(__KSYM_##sym))
  97. #define __cond_export_sym(sym, sec, conf) \
  98. ___cond_export_sym(sym, sec, conf)
  99. #define ___cond_export_sym(sym, sec, enabled) \
  100. __cond_export_sym_##enabled(sym, sec)
  101. #define __cond_export_sym_1(sym, sec) ___EXPORT_SYMBOL(sym, sec)
  102. #define __cond_export_sym_0(sym, sec) /* nothing */
  103. #else
  104. #define __EXPORT_SYMBOL ___EXPORT_SYMBOL
  105. #endif
  106. #define EXPORT_SYMBOL(sym) \
  107. __EXPORT_SYMBOL(sym, "")
  108. #define EXPORT_SYMBOL_GPL(sym) \
  109. __EXPORT_SYMBOL(sym, "_gpl")
  110. #define EXPORT_SYMBOL_GPL_FUTURE(sym) \
  111. __EXPORT_SYMBOL(sym, "_gpl_future")
  112. #ifdef CONFIG_UNUSED_SYMBOLS
  113. #define EXPORT_UNUSED_SYMBOL(sym) __EXPORT_SYMBOL(sym, "_unused")
  114. #define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl")
  115. #else
  116. #define EXPORT_UNUSED_SYMBOL(sym)
  117. #define EXPORT_UNUSED_SYMBOL_GPL(sym)
  118. #endif
  119. #endif /* __GENKSYMS__ */
  120. #else /* !CONFIG_MODULES... */
  121. #define EXPORT_SYMBOL(sym)
  122. #define EXPORT_SYMBOL_GPL(sym)
  123. #define EXPORT_SYMBOL_GPL_FUTURE(sym)
  124. #define EXPORT_UNUSED_SYMBOL(sym)
  125. #define EXPORT_UNUSED_SYMBOL_GPL(sym)
  126. #endif /* CONFIG_MODULES */
  127. #endif /* !__ASSEMBLY__ */
  128. #endif /* _LINUX_EXPORT_H */