]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Make lib/dns/tests/tkey_test.c more portable
authorMichał Kępień <michal@isc.org>
Thu, 12 Sep 2019 12:25:57 +0000 (14:25 +0200)
committerMichał Kępień <michal@isc.org>
Thu, 12 Sep 2019 12:25:57 +0000 (14:25 +0200)
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.

config.h.in
configure
configure.ac
lib/dns/tests/tkey_test.c

index e2cf7e911e0ff9dc22d3bcbfa276149aba84f6ab..5f66011d53810dda32eed9203239ef06c27e52cc 100644 (file)
    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
 
index 33f4fd8a3c2283b8a88451d9671954b4f504080c..53251a64b7a66b822a0391858d59554191915d2c 100755 (executable)
--- 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
index 9dacb39aa593b1ddb486dfbf0f658d147ea808d6..bfb4bc50942a9a874826ba0243ff830fb597eac6 100644 (file)
@@ -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)
index 5b0fb033dc820b0eaaa28ceaee9bf51e426ed126..5b91aa0a02e75cf39ebe8cd940bb4b23a0345113 100644 (file)
@@ -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) {