export.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. #ifndef __ASM_GENERIC_EXPORT_H
  3. #define __ASM_GENERIC_EXPORT_H
  4. /*
  5. * This comment block is used by fixdep. Please do not remove.
  6. *
  7. * When CONFIG_MODVERSIONS is changed from n to y, all source files having
  8. * EXPORT_SYMBOL variants must be re-compiled because genksyms is run as a
  9. * side effect of the *.o build rule.
  10. */
  11. #ifndef KSYM_FUNC
  12. #define KSYM_FUNC(x) x
  13. #endif
  14. #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
  15. #define KSYM_ALIGN 4
  16. #elif defined(CONFIG_64BIT)
  17. #define KSYM_ALIGN 8
  18. #else
  19. #define KSYM_ALIGN 4
  20. #endif
  21. .macro __put, val, name
  22. #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
  23. .long \val - ., \name - ., 0
  24. #elif defined(CONFIG_64BIT)
  25. .quad \val, \name, 0
  26. #else
  27. .long \val, \name, 0
  28. #endif
  29. .endm
  30. /*
  31. * note on .section use: we specify progbits since usage of the "M" (SHF_MERGE)
  32. * section flag requires it. Use '%progbits' instead of '@progbits' since the
  33. * former apparently works on all arches according to the binutils source.
  34. */
  35. .macro ___EXPORT_SYMBOL name,val,sec
  36. #if defined(CONFIG_MODULES) && !defined(__DISABLE_EXPORTS)
  37. .section ___ksymtab\sec+\name,"a"
  38. .balign KSYM_ALIGN
  39. __ksymtab_\name:
  40. __put \val, __kstrtab_\name
  41. .previous
  42. .section __ksymtab_strings,"aMS",%progbits,1
  43. __kstrtab_\name:
  44. .asciz "\name"
  45. .previous
  46. #endif
  47. .endm
  48. #if defined(CONFIG_TRIM_UNUSED_KSYMS)
  49. #include <linux/kconfig.h>
  50. #include <generated/autoksyms.h>
  51. .macro __ksym_marker sym
  52. .section ".discard.ksym","a"
  53. __ksym_marker_\sym:
  54. .previous
  55. .endm
  56. #define __EXPORT_SYMBOL(sym, val, sec) \
  57. __ksym_marker sym; \
  58. __cond_export_sym(sym, val, sec, __is_defined(__KSYM_##sym))
  59. #define __cond_export_sym(sym, val, sec, conf) \
  60. ___cond_export_sym(sym, val, sec, conf)
  61. #define ___cond_export_sym(sym, val, sec, enabled) \
  62. __cond_export_sym_##enabled(sym, val, sec)
  63. #define __cond_export_sym_1(sym, val, sec) ___EXPORT_SYMBOL sym, val, sec
  64. #define __cond_export_sym_0(sym, val, sec) /* nothing */
  65. #else
  66. #define __EXPORT_SYMBOL(sym, val, sec) ___EXPORT_SYMBOL sym, val, sec
  67. #endif
  68. #define EXPORT_SYMBOL(name) \
  69. __EXPORT_SYMBOL(name, KSYM_FUNC(name),)
  70. #define EXPORT_SYMBOL_GPL(name) \
  71. __EXPORT_SYMBOL(name, KSYM_FUNC(name), _gpl)
  72. #define EXPORT_DATA_SYMBOL(name) \
  73. __EXPORT_SYMBOL(name, name,)
  74. #define EXPORT_DATA_SYMBOL_GPL(name) \
  75. __EXPORT_SYMBOL(name, name,_gpl)
  76. #endif