0001-configure-support-builds-without-versioning.patch 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. From 7a45d4d688d4966664ca94619b2ad0fc8d333d77 Mon Sep 17 00:00:00 2001
  2. From: Zdenek Kabelac <zkabelac@redhat.com>
  3. Date: Mon, 29 Mar 2021 21:46:12 +0200
  4. Subject: [PATCH] configure: support builds without versioning
  5. Not all libc (like musl, uclibc dietlibc) libraries support full symbol
  6. version resolution in runtime like glibc.
  7. Add support to not generate symbol versions when compiling against them.
  8. Additionally libdevmapper.so was broken when compiled against
  9. uclibc. Runtime linker loader caused calling dm_task_get_info_base()
  10. function recursively, leading to segmentation fault.
  11. Introduce --with-symvers=STYLE option, which allows to choose
  12. between gnu and disabled symbol versioning. By default gnu symbol
  13. versioning is used.
  14. __GNUC__ check is replaced now with GNU_SYMVER.
  15. Additionally ld version script is included only in
  16. case of gnu option, which slightly reduces output size.
  17. Providing --without-symvers to configure script when building against
  18. uclibc library fixes segmentation fault error described above, due to
  19. lack of several versions of the same symbol in libdevmapper.so
  20. library.
  21. Based on:
  22. https://patchwork.kernel.org/project/dm-devel/patch/20180831144817.31207-1-m.niestroj@grinn-global.com/
  23. Suggested-by: Marcin Niestroj <m.niestroj@grinn-global.com>
  24. ---
  25. configure | 35 ++++++++++++++++++++++++++++++++---
  26. configure.ac | 26 +++++++++++++++++++++++---
  27. include/configure.h.in | 3 +++
  28. lib/misc/lib.h | 4 ++--
  29. libdm/datastruct/bitset.c | 4 +---
  30. libdm/ioctl/libdm-iface.c | 2 +-
  31. libdm/libdm-deptree.c | 2 +-
  32. libdm/libdm-stats.c | 2 +-
  33. 8 files changed, 64 insertions(+), 14 deletions(-)
  34. diff --git a/configure b/configure
  35. index bb8d502209d60..eeb8397a27d0b 100755
  36. --- a/configure
  37. +++ b/configure
  38. @@ -942,6 +942,7 @@ enable_cmirrord
  39. with_cmirrord_pidfile
  40. enable_debug
  41. with_optimisation
  42. +with_symvers
  43. enable_profiling
  44. enable_valgrind_pool
  45. enable_devmapper
  46. @@ -1792,6 +1793,8 @@ Optional Packages:
  47. --with-cmirrord-pidfile=PATH
  48. cmirrord pidfile [PID_DIR/cmirrord.pid]
  49. --with-optimisation=OPT C optimisation flag [OPT=-O2]
  50. + --with-symvers=STYLE use symbol versioning of the shared library
  51. + [default=gnu]
  52. --with-lvmlockd-pidfile=PATH
  53. lvmlockd pidfile [PID_DIR/lvmlockd.pid]
  54. --with-lvmetad-pidfile=PATH
  55. @@ -3168,13 +3171,11 @@ if test -z "$CFLAGS"; then :
  56. fi
  57. case "$host_os" in
  58. linux*)
  59. - CLDFLAGS="$CLDFLAGS -Wl,--version-script,.export.sym"
  60. # equivalent to -rdynamic
  61. ELDFLAGS="-Wl,--export-dynamic"
  62. # FIXME Generate list and use --dynamic-list=.dlopen.sym
  63. CLDWHOLEARCHIVE="-Wl,-whole-archive"
  64. CLDNOWHOLEARCHIVE="-Wl,-no-whole-archive"
  65. - LDDEPS="$LDDEPS .export.sym"
  66. LIB_SUFFIX=so
  67. DEVMAPPER=yes
  68. BUILD_LVMETAD=no
  69. @@ -3190,7 +3191,6 @@ case "$host_os" in
  70. ;;
  71. darwin*)
  72. CFLAGS="$CFLAGS -no-cpp-precomp -fno-common"
  73. - CLDFLAGS="$CLDFLAGS"
  74. ELDFLAGS=
  75. CLDWHOLEARCHIVE="-all_load"
  76. CLDNOWHOLEARCHIVE=
  77. @@ -11182,6 +11182,35 @@ fi
  78. { $as_echo "$as_me:${as_lineno-$LINENO}: result: $COPTIMISE_FLAG" >&5
  79. $as_echo "$COPTIMISE_FLAG" >&6; }
  80. +################################################################################
  81. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to use symbol versioning" >&5
  82. +$as_echo_n "checking whether to use symbol versioning... " >&6; }
  83. +
  84. +# Check whether --with-symvers was given.
  85. +if test "${with_symvers+set}" = set; then :
  86. + withval=$with_symvers; case "$withval" in
  87. + gnu|no) symvers=$withval ;;
  88. + *) as_fn_error $? "Unknown argument to with-symvers" "$LINENO" 5 ;;
  89. + esac
  90. +else
  91. + symvers=gnu
  92. +fi
  93. +
  94. +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $symvers" >&5
  95. +$as_echo "$symvers" >&6; }
  96. +
  97. +if test "$GCC" = "yes" && test "$symvers" = "gnu" ; then
  98. +
  99. +$as_echo "#define GNU_SYMVER 1" >>confdefs.h
  100. +
  101. + case "$host_os" in
  102. + linux*)
  103. + CLDFLAGS="${CLDFLAGS-"$LDFLAGS"} -Wl,--version-script,.export.sym"
  104. + LDDEPS="$LDDEPS .export.sym"
  105. + ;;
  106. + esac
  107. +fi
  108. +
  109. ################################################################################
  110. { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to gather gcov profiling data" >&5
  111. $as_echo_n "checking whether to gather gcov profiling data... " >&6; }
  112. diff --git a/configure.ac b/configure.ac
  113. index f040a5a713d7f..a2697d15c9150 100644
  114. --- a/configure.ac
  115. +++ b/configure.ac
  116. @@ -30,13 +30,11 @@ AC_CANONICAL_TARGET([])
  117. AS_IF([test -z "$CFLAGS"], [COPTIMISE_FLAG="-O2"])
  118. case "$host_os" in
  119. linux*)
  120. - CLDFLAGS="$CLDFLAGS -Wl,--version-script,.export.sym"
  121. # equivalent to -rdynamic
  122. ELDFLAGS="-Wl,--export-dynamic"
  123. # FIXME Generate list and use --dynamic-list=.dlopen.sym
  124. CLDWHOLEARCHIVE="-Wl,-whole-archive"
  125. CLDNOWHOLEARCHIVE="-Wl,-no-whole-archive"
  126. - LDDEPS="$LDDEPS .export.sym"
  127. LIB_SUFFIX=so
  128. DEVMAPPER=yes
  129. BUILD_LVMETAD=no
  130. @@ -52,7 +50,6 @@ case "$host_os" in
  131. ;;
  132. darwin*)
  133. CFLAGS="$CFLAGS -no-cpp-precomp -fno-common"
  134. - CLDFLAGS="$CLDFLAGS"
  135. ELDFLAGS=
  136. CLDWHOLEARCHIVE="-all_load"
  137. CLDNOWHOLEARCHIVE=
  138. @@ -981,6 +978,29 @@ AC_ARG_WITH(optimisation,
  139. COPTIMISE_FLAG=$withval)
  140. AC_MSG_RESULT($COPTIMISE_FLAG)
  141. +################################################################################
  142. +dnl -- Symbol versioning
  143. +AC_MSG_CHECKING(whether to use symbol versioning)
  144. +AC_ARG_WITH(symvers,
  145. + AC_HELP_STRING([--with-symvers=STYLE],
  146. + [use symbol versioning of the shared library [default=gnu]]),
  147. + [ case "$withval" in
  148. + gnu|no) symvers=$withval ;;
  149. + *) AC_MSG_ERROR(Unknown argument to with-symvers) ;;
  150. + esac], symvers=gnu)
  151. +AC_MSG_RESULT($symvers)
  152. +
  153. +if test "$GCC" = "yes" && test "$symvers" = "gnu" ; then
  154. + AC_DEFINE(GNU_SYMVER, 1,
  155. + [Define to use GNU versioning in the shared library.])
  156. + case "$host_os" in
  157. + linux*)
  158. + CLDFLAGS="${CLDFLAGS-"$LDFLAGS"} -Wl,--version-script,.export.sym"
  159. + LDDEPS="$LDDEPS .export.sym"
  160. + ;;
  161. + esac
  162. +fi
  163. +
  164. ################################################################################
  165. dnl -- Enable profiling
  166. AC_MSG_CHECKING(whether to gather gcov profiling data)
  167. diff --git a/include/configure.h.in b/include/configure.h.in
  168. index 49663e484e0b2..af0fa31e063a3 100644
  169. --- a/include/configure.h.in
  170. +++ b/include/configure.h.in
  171. @@ -150,6 +150,9 @@
  172. /* Path to fsadm binary. */
  173. #undef FSADM_PATH
  174. +/* Define to use GNU versioning in the shared library. */
  175. +#undef GNU_SYMVER
  176. +
  177. /* Define to 1 if you have the `alarm' function. */
  178. #undef HAVE_ALARM
  179. diff --git a/lib/misc/lib.h b/lib/misc/lib.h
  180. index d7fa5c721c118..3cd7a76ae3486 100644
  181. --- a/lib/misc/lib.h
  182. +++ b/lib/misc/lib.h
  183. @@ -42,7 +42,7 @@
  184. * specified version string.
  185. *
  186. * Since versioning is only available when compiling with GCC the entire
  187. - * compatibility version should be enclosed in '#if defined(__GNUC__)',
  188. + * compatibility version should be enclosed in '#if defined(GNU_SYMVER)',
  189. * for example:
  190. *
  191. * int dm_foo(int bar)
  192. @@ -67,7 +67,7 @@
  193. * versions of library symbols prior to the introduction of symbol
  194. * versioning: it must never be used for new symbols.
  195. */
  196. -#if defined(__GNUC__)
  197. +#if defined(GNU_SYMVER)
  198. #define DM_EXPORT_SYMBOL(func, ver) \
  199. __asm__(".symver " #func "_v" #ver ", " #func "@DM_" #ver )
  200. #define DM_EXPORT_SYMBOL_BASE(func) \
  201. diff --git a/libdm/datastruct/bitset.c b/libdm/datastruct/bitset.c
  202. index b0826e1eb54ec..642587e5472b1 100644
  203. --- a/libdm/datastruct/bitset.c
  204. +++ b/libdm/datastruct/bitset.c
  205. @@ -242,7 +242,7 @@ bad:
  206. return NULL;
  207. }
  208. -#if defined(__GNUC__)
  209. +#if defined(GNU_SYMVER)
  210. /*
  211. * Maintain backward compatibility with older versions that did not
  212. * accept a 'min_num_bits' argument to dm_bitset_parse_list().
  213. @@ -254,6 +254,4 @@ dm_bitset_t dm_bitset_parse_list_v1_02_129(const char *str, struct dm_pool *mem)
  214. }
  215. DM_EXPORT_SYMBOL(dm_bitset_parse_list, 1_02_129);
  216. -#else /* if defined(__GNUC__) */
  217. -
  218. #endif
  219. diff --git a/libdm/ioctl/libdm-iface.c b/libdm/ioctl/libdm-iface.c
  220. index 14186e680d97d..4be7ab34a704f 100644
  221. --- a/libdm/ioctl/libdm-iface.c
  222. +++ b/libdm/ioctl/libdm-iface.c
  223. @@ -2176,7 +2176,7 @@ void dm_lib_exit(void)
  224. _version_checked = 0;
  225. }
  226. -#if defined(__GNUC__)
  227. +#if defined(GNU_SYMVER)
  228. /*
  229. * Maintain binary backward compatibility.
  230. * Version script mechanism works with 'gcc' compatible compilers only.
  231. diff --git a/libdm/libdm-deptree.c b/libdm/libdm-deptree.c
  232. index ba1ed1991a0cf..802db076e27f1 100644
  233. --- a/libdm/libdm-deptree.c
  234. +++ b/libdm/libdm-deptree.c
  235. @@ -3849,7 +3849,7 @@ void dm_tree_node_set_callback(struct dm_tree_node *dnode,
  236. dnode->callback_data = data;
  237. }
  238. -#if defined(__GNUC__)
  239. +#if defined(GNU_SYMVER)
  240. /*
  241. * Backward compatible implementations.
  242. *
  243. diff --git a/libdm/libdm-stats.c b/libdm/libdm-stats.c
  244. index a3697c74dfde8..9f09f1c2f082e 100644
  245. --- a/libdm/libdm-stats.c
  246. +++ b/libdm/libdm-stats.c
  247. @@ -5069,7 +5069,7 @@ int dm_stats_start_filemapd(int fd, uint64_t group_id, const char *path,
  248. * current dm_stats_create_region() version.
  249. */
  250. -#if defined(__GNUC__)
  251. +#if defined(GNU_SYMVER)
  252. int dm_stats_create_region_v1_02_106(struct dm_stats *dms, uint64_t *region_id,
  253. uint64_t start, uint64_t len, int64_t step,
  254. int precise, const char *program_id,
  255. --
  256. 2.33.1