export.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. struct kernel_symbol
  13. {
  14. unsigned long value;
  15. const char *name;
  16. };
  17. #ifdef MODULE
  18. extern struct module __this_module;
  19. #define THIS_MODULE (&__this_module)
  20. #else
  21. #define THIS_MODULE ((struct module *)0)
  22. #endif
  23. #ifdef CONFIG_MODULES
  24. #if defined(__KERNEL__) && !defined(__GENKSYMS__)
  25. #ifdef CONFIG_MODVERSIONS
  26. /* Mark the CRC weak since genksyms apparently decides not to
  27. * generate a checksums for some symbols */
  28. #if defined(CONFIG_MODULE_REL_CRCS)
  29. #define __CRC_SYMBOL(sym, sec) \
  30. asm(" .section \"___kcrctab" sec "+" #sym "\", \"a\" \n" \
  31. " .weak __crc_" #sym " \n" \
  32. " .long __crc_" #sym " - . \n" \
  33. " .previous \n");
  34. #else
  35. #define __CRC_SYMBOL(sym, sec) \
  36. asm(" .section \"___kcrctab" sec "+" #sym "\", \"a\" \n" \
  37. " .weak __crc_" #sym " \n" \
  38. " .long __crc_" #sym " \n" \
  39. " .previous \n");
  40. #endif
  41. #else
  42. #define __CRC_SYMBOL(sym, sec)
  43. #endif
  44. /* For every exported symbol, place a struct in the __ksymtab section */
  45. #define ___EXPORT_SYMBOL(sym, sec) \
  46. extern typeof(sym) sym; \
  47. __CRC_SYMBOL(sym, sec) \
  48. static const char __kstrtab_##sym[] \
  49. __attribute__((section("__ksymtab_strings"), aligned(1))) \
  50. = #sym; \
  51. static const struct kernel_symbol __ksymtab_##sym \
  52. __used \
  53. __attribute__((section("___ksymtab" sec "+" #sym), used)) \
  54. = { (unsigned long)&sym, __kstrtab_##sym }
  55. #if defined(__KSYM_DEPS__)
  56. /*
  57. * For fine grained build dependencies, we want to tell the build system
  58. * about each possible exported symbol even if they're not actually exported.
  59. * We use a string pattern that is unlikely to be valid code that the build
  60. * system filters out from the preprocessor output (see ksym_dep_filter
  61. * in scripts/Kbuild.include).
  62. */
  63. #define __EXPORT_SYMBOL(sym, sec) === __KSYM_##sym ===
  64. #elif defined(CONFIG_TRIM_UNUSED_KSYMS)
  65. #include <generated/autoksyms.h>
  66. #define __EXPORT_SYMBOL(sym, sec) \
  67. __cond_export_sym(sym, sec, __is_defined(__KSYM_##sym))
  68. #define __cond_export_sym(sym, sec, conf) \
  69. ___cond_export_sym(sym, sec, conf)
  70. #define ___cond_export_sym(sym, sec, enabled) \
  71. __cond_export_sym_##enabled(sym, sec)
  72. #define __cond_export_sym_1(sym, sec) ___EXPORT_SYMBOL(sym, sec)
  73. #define __cond_export_sym_0(sym, sec) /* nothing */
  74. #else
  75. #define __EXPORT_SYMBOL ___EXPORT_SYMBOL
  76. #endif
  77. #define EXPORT_SYMBOL(sym) \
  78. __EXPORT_SYMBOL(sym, "")
  79. #define EXPORT_SYMBOL_GPL(sym) \
  80. __EXPORT_SYMBOL(sym, "_gpl")
  81. #define EXPORT_SYMBOL_GPL_FUTURE(sym) \
  82. __EXPORT_SYMBOL(sym, "_gpl_future")
  83. #ifdef CONFIG_UNUSED_SYMBOLS
  84. #define EXPORT_UNUSED_SYMBOL(sym) __EXPORT_SYMBOL(sym, "_unused")
  85. #define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl")
  86. #else
  87. #define EXPORT_UNUSED_SYMBOL(sym)
  88. #define EXPORT_UNUSED_SYMBOL_GPL(sym)
  89. #endif
  90. #endif /* __GENKSYMS__ */
  91. #else /* !CONFIG_MODULES... */
  92. #define EXPORT_SYMBOL(sym)
  93. #define EXPORT_SYMBOL_GPL(sym)
  94. #define EXPORT_SYMBOL_GPL_FUTURE(sym)
  95. #define EXPORT_UNUSED_SYMBOL(sym)
  96. #define EXPORT_UNUSED_SYMBOL_GPL(sym)
  97. #endif /* CONFIG_MODULES */
  98. #endif /* !__ASSEMBLY__ */
  99. #endif /* _LINUX_EXPORT_H */