export.h 2.3 KB

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