0001-configure-Introduce-enable-symvers-option.patch 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. From 94d71c49eb1682a73465eb162b0a059561168bb2 Mon Sep 17 00:00:00 2001
  2. From: Marcin Niestroj <m.niestroj@grinn-global.com>
  3. Date: Fri, 20 Jul 2018 14:26:44 +0200
  4. Subject: [PATCH] configure: Introduce --enable-symvers option
  5. Only few libc (e.g. glibc) libraries support full symbol version
  6. resolution in runtime. There are lot of standard libraries that do not
  7. support that, such as dietlibc, musl and uclibc. Hence there is no
  8. reason to generate symbol versions when compiling against them.
  9. Additionally libdevmapper.so was broken when compiled against
  10. uclibc. Runtime linker loader caused calling dm_task_get_info_base()
  11. function recursively, leading to segmentation fault.
  12. Introduce --enable-symvers[=STYLE] option, which allows to choose
  13. between gnu and disabled symbol versioning. By default gnu symbol
  14. versioning is used to provide backward compatibility.
  15. __GNUC__ check is replaced now with GNU_SYMVER, which is generated by
  16. configure script. Additionally ld version script is included only in
  17. case of gnu option, which slightly reduces output size.
  18. Providing --disable-symvers to configure script when building against
  19. uclibc library fixes segmentation fault error described above, due to
  20. lack of several versions of the same symbol in libdevmapper.so
  21. library.
  22. Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
  23. ---
  24. configure | 32 ++++++++++++++++++++++++++++++--
  25. configure.ac | 28 +++++++++++++++++++++++++---
  26. include/configure.h.in | 3 +++
  27. lib/misc/lib.h | 10 +++++-----
  28. libdm/datastruct/bitset.c | 5 +----
  29. libdm/ioctl/libdm-iface.c | 2 +-
  30. libdm/libdm-deptree.c | 2 +-
  31. libdm/libdm-stats.c | 2 +-
  32. 8 files changed, 67 insertions(+), 17 deletions(-)
  33. diff --git a/configure b/configure
  34. index 7d945dfa8..94cd6b1ea 100755
  35. --- a/configure
  36. +++ b/configure
  37. @@ -975,6 +975,7 @@ enable_fsadm
  38. enable_blkdeactivate
  39. enable_dmeventd
  40. enable_selinux
  41. +enable_symvers
  42. enable_nls
  43. with_localedir
  44. with_confdir
  45. @@ -1725,6 +1726,9 @@ Optional Features:
  46. --disable-blkdeactivate disable blkdeactivate
  47. --enable-dmeventd enable the device-mapper event daemon
  48. --disable-selinux disable selinux support
  49. + --enable-symvers[=STYLE]
  50. + enables symbol versioning of the shared library
  51. + [default=gnu]
  52. --enable-nls enable Native Language Support
  53. Optional Packages:
  54. @@ -3156,7 +3160,6 @@ if test -z "$CFLAGS"; then :
  55. fi
  56. case "$host_os" in
  57. linux*)
  58. - CLDFLAGS="$CLDFLAGS -Wl,--version-script,.export.sym"
  59. # equivalent to -rdynamic
  60. ELDFLAGS="-Wl,--export-dynamic"
  61. # FIXME Generate list and use --dynamic-list=.dlopen.sym
  62. @@ -3178,7 +3181,6 @@ case "$host_os" in
  63. ;;
  64. darwin*)
  65. CFLAGS="$CFLAGS -no-cpp-precomp -fno-common"
  66. - CLDFLAGS="$CLDFLAGS"
  67. ELDFLAGS=
  68. CLDWHOLEARCHIVE="-all_load"
  69. CLDNOWHOLEARCHIVE=
  70. @@ -14401,6 +14403,32 @@ done
  71. LIBS=$lvm_saved_libs
  72. fi
  73. +################################################################################
  74. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable symbol versioning" >&5
  75. +$as_echo_n "checking whether to enable symbol versioning... " >&6; }
  76. +# Check whether --enable-symvers was given.
  77. +if test "${enable_symvers+set}" = set; then :
  78. + enableval=$enable_symvers;
  79. + case "$enableval" in
  80. + gnu|no) ;;
  81. + *) as_fn_error $? "Unknown argument to enable/disable symvers" "$LINENO" 5 ;;
  82. + esac
  83. +else
  84. + enable_symvers=gnu
  85. +fi
  86. +
  87. +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_symvers" >&5
  88. +$as_echo "$enable_symvers" >&6; }
  89. +
  90. +if test x$GCC = xyes && test x$enable_symvers = xgnu ; then
  91. +
  92. +$as_echo "#define GNU_SYMVER 1" >>confdefs.h
  93. +
  94. + case "$host_os" in
  95. + linux*) CLDFLAGS="$CLDFLAGS -Wl,--version-script,.export.sym" ;;
  96. + esac
  97. +fi
  98. +
  99. ################################################################################
  100. { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable internationalisation" >&5
  101. $as_echo_n "checking whether to enable internationalisation... " >&6; }
  102. diff --git a/configure.ac b/configure.ac
  103. index e427708cd..2e8712f92 100644
  104. --- a/configure.ac
  105. +++ b/configure.ac
  106. @@ -30,13 +30,11 @@ AC_CANONICAL_TARGET([])
  107. AS_IF([test -z "$CFLAGS"], [COPTIMISE_FLAG="-O2"])
  108. case "$host_os" in
  109. linux*)
  110. - CLDFLAGS="$CLDFLAGS -Wl,--version-script,.export.sym"
  111. # equivalent to -rdynamic
  112. ELDFLAGS="-Wl,--export-dynamic"
  113. # FIXME Generate list and use --dynamic-list=.dlopen.sym
  114. CLDWHOLEARCHIVE="-Wl,-whole-archive"
  115. CLDNOWHOLEARCHIVE="-Wl,-no-whole-archive"
  116. - LDDEPS="$LDDEPS .export.sym"
  117. LIB_SUFFIX=so
  118. DEVMAPPER=yes
  119. BUILD_LVMETAD=no
  120. @@ -52,7 +50,6 @@ case "$host_os" in
  121. ;;
  122. darwin*)
  123. CFLAGS="$CFLAGS -no-cpp-precomp -fno-common"
  124. - CLDFLAGS="$CLDFLAGS"
  125. ELDFLAGS=
  126. CLDWHOLEARCHIVE="-all_load"
  127. CLDNOWHOLEARCHIVE=
  128. @@ -1656,6 +1653,31 @@ package as well (which may be called readline-devel or something similar).])
  129. LIBS=$lvm_saved_libs
  130. fi
  131. +################################################################################
  132. +dnl -- Symbol versioning
  133. +AC_MSG_CHECKING(whether to enable symbol versioning)
  134. +AC_ARG_ENABLE(symvers,
  135. + AC_HELP_STRING([--enable-symvers[[[=STYLE]]]],
  136. + [enables symbol versioning of the shared library [default=gnu]]),
  137. + [
  138. + case "$enableval" in
  139. + gnu|no) ;;
  140. + *) AC_MSG_ERROR(Unknown argument to enable/disable symvers) ;;
  141. + esac],
  142. + enable_symvers=gnu)
  143. +AC_MSG_RESULT($enable_symvers)
  144. +
  145. +if test x$GCC = xyes && test x$enable_symvers = xgnu ; then
  146. + AC_DEFINE(GNU_SYMVER, 1,
  147. + [Define to use GNU versioning in the shared library.])
  148. + case "$host_os" in
  149. + linux*)
  150. + CLDFLAGS="$CLDFLAGS -Wl,--version-script,.export.sym"
  151. + LDDEPS="$LDDEPS .export.sym"
  152. + ;;
  153. + esac
  154. +fi
  155. +
  156. ################################################################################
  157. dnl -- Internationalisation stuff
  158. AC_MSG_CHECKING(whether to enable internationalisation)
  159. diff --git a/include/configure.h.in b/include/configure.h.in
  160. index 15fd150ed..7a07a10ef 100644
  161. --- a/include/configure.h.in
  162. +++ b/include/configure.h.in
  163. @@ -147,6 +147,9 @@
  164. /* Path to fsadm binary. */
  165. #undef FSADM_PATH
  166. +/* Define to use GNU versioning in the shared library. */
  167. +#undef GNU_SYMVER
  168. +
  169. /* Define to 1 if you have the `alarm' function. */
  170. #undef HAVE_ALARM
  171. diff --git a/lib/misc/lib.h b/lib/misc/lib.h
  172. index d7fa5c721..7cf98f932 100644
  173. --- a/lib/misc/lib.h
  174. +++ b/lib/misc/lib.h
  175. @@ -41,16 +41,16 @@
  176. * macro DM_EXPORT_SYMBOL to export the function and bind it to the
  177. * specified version string.
  178. *
  179. - * Since versioning is only available when compiling with GCC the entire
  180. - * compatibility version should be enclosed in '#if defined(__GNUC__)',
  181. - * for example:
  182. + * Since versioning is only available when compiling with GCC
  183. + * and GLIBC the entire compatibility version should be enclosed
  184. + * in '#if defined(GNU_SYMVER)', for example:
  185. *
  186. * int dm_foo(int bar)
  187. * {
  188. * return bar;
  189. * }
  190. *
  191. - * #if defined(__GNUC__)
  192. + * #if defined(GNU_SYMVER)
  193. * // Backward compatible dm_foo() version 1.02.104
  194. * int dm_foo_v1_02_104(void);
  195. * int dm_foo_v1_02_104(void)
  196. @@ -67,7 +67,7 @@
  197. * versions of library symbols prior to the introduction of symbol
  198. * versioning: it must never be used for new symbols.
  199. */
  200. -#if defined(__GNUC__)
  201. +#if defined(GNU_SYMVER)
  202. #define DM_EXPORT_SYMBOL(func, ver) \
  203. __asm__(".symver " #func "_v" #ver ", " #func "@DM_" #ver )
  204. #define DM_EXPORT_SYMBOL_BASE(func) \
  205. diff --git a/libdm/datastruct/bitset.c b/libdm/datastruct/bitset.c
  206. index b0826e1eb..2ec3f8f84 100644
  207. --- a/libdm/datastruct/bitset.c
  208. +++ b/libdm/datastruct/bitset.c
  209. @@ -242,7 +242,7 @@ bad:
  210. return NULL;
  211. }
  212. -#if defined(__GNUC__)
  213. +#if defined(GNU_SYMVER)
  214. /*
  215. * Maintain backward compatibility with older versions that did not
  216. * accept a 'min_num_bits' argument to dm_bitset_parse_list().
  217. @@ -253,7 +253,4 @@ dm_bitset_t dm_bitset_parse_list_v1_02_129(const char *str, struct dm_pool *mem)
  218. return dm_bitset_parse_list(str, mem, 0);
  219. }
  220. DM_EXPORT_SYMBOL(dm_bitset_parse_list, 1_02_129);
  221. -
  222. -#else /* if defined(__GNUC__) */
  223. -
  224. #endif
  225. diff --git a/libdm/ioctl/libdm-iface.c b/libdm/ioctl/libdm-iface.c
  226. index 769b69c1b..28e2eadee 100644
  227. --- a/libdm/ioctl/libdm-iface.c
  228. +++ b/libdm/ioctl/libdm-iface.c
  229. @@ -2145,7 +2145,7 @@ void dm_lib_exit(void)
  230. _version_checked = 0;
  231. }
  232. -#if defined(__GNUC__)
  233. +#if defined(GNU_SYMVER)
  234. /*
  235. * Maintain binary backward compatibility.
  236. * Version script mechanism works with 'gcc' compatible compilers only.
  237. diff --git a/libdm/libdm-deptree.c b/libdm/libdm-deptree.c
  238. index ab0545659..00651c0b2 100644
  239. --- a/libdm/libdm-deptree.c
  240. +++ b/libdm/libdm-deptree.c
  241. @@ -3797,7 +3797,7 @@ void dm_tree_node_set_callback(struct dm_tree_node *dnode,
  242. dnode->callback_data = data;
  243. }
  244. -#if defined(__GNUC__)
  245. +#if defined(GNU_SYMVER)
  246. /*
  247. * Backward compatible implementations.
  248. *
  249. diff --git a/libdm/libdm-stats.c b/libdm/libdm-stats.c
  250. index 94ad380e0..76efbbe35 100644
  251. --- a/libdm/libdm-stats.c
  252. +++ b/libdm/libdm-stats.c
  253. @@ -5065,7 +5065,7 @@ int dm_stats_start_filemapd(int fd, uint64_t group_id, const char *path,
  254. * current dm_stats_create_region() version.
  255. */
  256. -#if defined(__GNUC__)
  257. +#if defined(GNU_SYMVER)
  258. int dm_stats_create_region_v1_02_106(struct dm_stats *dms, uint64_t *region_id,
  259. uint64_t start, uint64_t len, int64_t step,
  260. int precise, const char *program_id,
  261. --
  262. 2.18.0