From: Michał Kępień Date: Thu, 12 Sep 2019 12:25:57 +0000 (+0200) Subject: Make lib/dns/tests/tkey_test.c more portable X-Git-Tag: v9.15.5~33^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=119f3e0c2e5a9f1a09ac577745a0e0fdaad6a62a;p=thirdparty%2Fbind9.git Make lib/dns/tests/tkey_test.c more portable Weak symbols are handled differently by different dynamic linkers. With glibc, lib/dns/tests/tkey_test works as expected no matter whether --with-libtool is used or not: __attribute__((weak)) prevents a static build from failing and it just so happens that the desired symbols are picked at runtime for dynamic builds. However, with BSD libc, the libdns functions called from lib/dns/tests/tkey_test.c use the "real" memory allocation functions from libisc, thus breaking that unit test. (Note: similar behavior can be reproduced with glibc by setting the LD_DYNAMIC_WEAK environment variable.) The simplest way to make lib/dns/tests/tkey_test work reliably is to drop all uses of __attribute__((weak)) in it - this way, the memory functions inside lib/dns/tests/tkey_test.c will always be used instead of the "real" libisc ones for dynamic builds. However, this would not work with static builds as it would result in multiple strong symbols with the same name being present in a single binary. Work around the problem by only compiling in the overriding definitions of memory functions when building using --with-libtool. For static builds, keep relying on the --wrap linker option for replacing calls to the functions we are interested in. --- diff --git a/config.h.in b/config.h.in index e2cf7e911e0..5f66011d538 100644 --- a/config.h.in +++ b/config.h.in @@ -544,6 +544,9 @@ non-blocking. */ #undef USE_FIONBIO_IOCTL +/* Define if libtool is used for compilation */ +#undef USE_LIBTOOL + /* define if OpenSSL is used for Public-Key Cryptography */ #undef USE_OPENSSL diff --git a/configure b/configure index 33f4fd8a3c2..53251a64b7a 100755 --- a/configure +++ b/configure @@ -15827,6 +15827,9 @@ $as_echo "yes" >&6; } LIBTOOL_MODE_LINK='--mode=link' LIBTOOL_MODE_UNINSTALL='--mode=uninstall' INSTALL_LIBRARY='${INSTALL_PROGRAM}' + +$as_echo "#define USE_LIBTOOL 1" >>confdefs.h + ;; *) { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 diff --git a/configure.ac b/configure.ac index 9dacb39aa59..bfb4bc50942 100644 --- a/configure.ac +++ b/configure.ac @@ -669,6 +669,7 @@ case $use_libtool in LIBTOOL_MODE_LINK='--mode=link' LIBTOOL_MODE_UNINSTALL='--mode=uninstall' INSTALL_LIBRARY='${INSTALL_PROGRAM}' + AC_DEFINE([USE_LIBTOOL],[1],[Define if libtool is used for compilation]) ;; *) AC_MSG_RESULT(no) diff --git a/lib/dns/tests/tkey_test.c b/lib/dns/tests/tkey_test.c index 5b0fb033dc8..5b91aa0a02e 100644 --- a/lib/dns/tests/tkey_test.c +++ b/lib/dns/tests/tkey_test.c @@ -84,14 +84,14 @@ __wrap_isc__mem_putanddetach(isc_mem_t **ctxp, void *ptr, size_t size) { __wrap_isc_mem_detach(ctxp); } - +#ifdef USE_LIBTOOL #if ISC_MEM_TRACKLINES #define FLARG , const char *file, unsigned int line #else #define FLARG #endif -__attribute__((weak)) void * +void * isc__mem_get(isc_mem_t *mctx, size_t size FLARG) { UNUSED(file); @@ -99,7 +99,7 @@ isc__mem_get(isc_mem_t *mctx, size_t size FLARG) return (__wrap_isc__mem_get(mctx, size)); } -__attribute__((weak)) void +void isc__mem_put(isc_mem_t *ctx0, void *ptr, size_t size FLARG) { UNUSED(file); @@ -107,22 +107,23 @@ isc__mem_put(isc_mem_t *ctx0, void *ptr, size_t size FLARG) __wrap_isc__mem_put(ctx0, ptr, size); } -__attribute__((weak)) void +void isc_mem_attach(isc_mem_t *source0, isc_mem_t **targetp) { __wrap_isc_mem_attach(source0, targetp); } -__attribute__((weak)) void +void isc_mem_detach(isc_mem_t **ctxp) { __wrap_isc_mem_detach(ctxp); } -__attribute__((weak)) void +void isc__mem_putanddetach(isc_mem_t **ctxp, void *ptr, size_t size FLARG){ UNUSED(file); UNUSED(line); __wrap_isc__mem_putanddetach(ctxp, ptr, size); } +#endif /* USE_LIBTOOL */ static int _setup(void **state) {