]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Clean up use of function wrapping
authorMichał Kępień <michal@isc.org>
Mon, 28 Sep 2020 07:16:48 +0000 (09:16 +0200)
committerMichał Kępień <michal@isc.org>
Mon, 28 Sep 2020 07:16:48 +0000 (09:16 +0200)
Currently, building BIND using "--without-dlopen" universally breaks
building unit tests which employ the --wrap linker option (because the
replacement functions are put in a shared library and building shared
objects requires "--with-dlopen").  Fix by moving the overridden symbol,
isc_nmhandle_unref(), to lib/ns/tests/nstest.c and dropping
lib/ns/tests/wrap.c altogether.  This makes lib/ns/tests/Makefile.in
simpler and prevents --without-dlopen from messing with the process of
building unit tests.

Remove parts of configure.ac which are made redundant by the above
changes.

Put the replacement definition of isc_nmhandle_unref() inside an #ifdef
block, so that the build does not break for non-libtool builds (see
below).

These changes allow the broadest possible set of build variants to work
while also simplifying the build process:

  - for libtool builds, overriding isc_nmhandle_unref() is done by
    placing that symbol directly in lib/ns/tests/nstest.c and relying on
    the dynamic linker to perform symbol resolution in the expected way
    when the test binary is run,

  - for non-libtool builds, overriding isc_nmhandle_unref() is done
    using the --wrap linker option (the libtool approach cannot be used
    in this case as multiple strong symbols with the same name cannot
    coexist in the same binary),

  - the "--without-dlopen" option no longer affects building unit tests.

configure.ac
lib/ns/tests/Makefile.in
lib/ns/tests/nstest.c
lib/ns/tests/wrap.c [deleted file]
util/copyrights

index 690f763f5495edfb0a7979faaa5b8131f91413c2..f262a57c1961778295945034a2ef377227fc004b 100644 (file)
@@ -2260,23 +2260,6 @@ AX_RESTORE_FLAGS([wrap])
 
 AC_SUBST([LD_WRAP_TESTS])
 
-WRAP_INTERPOSE=
-AC_MSG_CHECKING([for linker support for '-z interpose' option])
-AX_SAVE_FLAGS([interpose])
-LDFLAGS="-Wl,-z,interpose"
-AC_LINK_IFELSE(
-    [AC_LANG_PROGRAM([],[])],
-    [WRAP_INTERPOSE="-Wl,-z,interpose"
-     AC_MSG_RESULT([yes])],
-    [AC_MSG_RESULT([no])])
-AX_RESTORE_FLAGS([interpose])
-
-AC_SUBST([WRAP_INTERPOSE])
-
-WRAP_NAME=''
-AS_CASE([$host],[*-darwin*],[WRAP_NAME='${WRAP_NAME}'])
-AC_SUBST([WRAP_NAME])
-
 #
 # Check for i18n
 #
index 7869c8e9cd1eb0eee1a66861ce5b104569b9ebc1..651b20033c75422a14c64a56eb021698e168ed6e 100644 (file)
@@ -15,11 +15,7 @@ VERSION=@BIND9_VERSION@
 
 @BIND9_MAKE_INCLUDES@
 
-WRAP_INTERPOSE=        @WRAP_INTERPOSE@
 WRAP_OPTIONS = -Wl,--wrap=isc_nmhandle_unref
-WRAP_NAME =    -Wl,-install_name,${top_builddir}/lib/ns/tests/$@
-WRAP_RPATH =   -Wl,-rpath,${top_builddir}/lib/ns/tests
-WRAP_LIB =     -L${top_builddir}/lib/ns/tests -lwrap
 
 CINCLUDES =    -I. -Iinclude ${NS_INCLUDES} ${DNS_INCLUDES} ${ISC_INCLUDES} \
                ${OPENSSL_CFLAGS} \
@@ -38,10 +34,6 @@ LIBS =               @LIBS@ @CMOCKA_LIBS@
 SO_CFLAGS =    @CFLAGS@ @SO_CFLAGS@
 SO_LDFLAGS =   @LDFLAGS@ @SO_LDFLAGS@
 
-SO_OBJS =      wrap.@O@
-SO_SRCS =      wrap.c
-SO_TARGETS =   libwrap.@SO@
-
 OBJS =         nstest.@O@
 SRCS =         nstest.c \
                listenlist_test.c \
@@ -53,39 +45,35 @@ SUBDIRS =
 TARGETS =      listenlist_test@EXEEXT@ \
                notify_test@EXEEXT@ \
                plugin_test@EXEEXT@ \
-               query_test@EXEEXT@ \
-               @SO_TARGETS@
+               query_test@EXEEXT@
 
 LD_WRAP_TESTS=@LD_WRAP_TESTS@
 
 @BIND9_MAKE_RULES@
 
-libwrap.@SO@: wrap.@O@
-       ${LIBTOOL_MODE_LINK} @SO_LD@ ${SO_LDFLAGS} ${WRAP_INTERPOSE} @WRAP_NAME@ -o $@ wrap.@O@ ${LIBS}
-
-listenlist_test@EXEEXT@: listenlist_test.@O@ nstest.@O@ libwrap.@SO@ ${NSDEPLIBS} ${ISCDEPLIBS} ${DNSDEPLIBS}
+listenlist_test@EXEEXT@: listenlist_test.@O@ nstest.@O@ ${NSDEPLIBS} ${ISCDEPLIBS} ${DNSDEPLIBS}
        if test "${LD_WRAP_TESTS}" = true -a -z "${LIBTOOL}"; then WRAP="${WRAP_OPTIONS}"; fi; \
        ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
-               ${LDFLAGS} $${WRAP} ${WRAP_RPATH} -o $@ listenlist_test.@O@ nstest.@O@ \
-               ${WRAP_LIB} ${NSLIBS} ${DNSLIBS} ${ISCLIBS} ${LIBS}
+               ${LDFLAGS} $${WRAP} -o $@ listenlist_test.@O@ nstest.@O@ \
+               ${NSLIBS} ${DNSLIBS} ${ISCLIBS} ${LIBS}
 
-notify_test@EXEEXT@: notify_test.@O@ nstest.@O@ libwrap.@SO@ ${NSDEPLIBS} ${ISCDEPLIBS} ${DNSDEPLIBS}
+notify_test@EXEEXT@: notify_test.@O@ nstest.@O@ ${NSDEPLIBS} ${ISCDEPLIBS} ${DNSDEPLIBS}
        if test "${LD_WRAP_TESTS}" = true -a -z "${LIBTOOL}"; then WRAP="${WRAP_OPTIONS}"; fi; \
        ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
-               ${LDFLAGS} $${WRAP} ${WRAP_RPATH} -o $@ notify_test.@O@ nstest.@O@ \
-               ${WRAP_LIB} ${NSLIBS} ${DNSLIBS} ${ISCLIBS} ${LIBS}
+               ${LDFLAGS} $${WRAP} -o $@ notify_test.@O@ nstest.@O@ \
+               ${NSLIBS} ${DNSLIBS} ${ISCLIBS} ${LIBS}
 
-plugin_test@EXEEXT@: plugin_test.@O@ nstest.@O@ libwrap.@SO@ ${NSDEPLIBS} ${ISCDEPLIBS} ${DNSDEPLIBS}
+plugin_test@EXEEXT@: plugin_test.@O@ nstest.@O@ ${NSDEPLIBS} ${ISCDEPLIBS} ${DNSDEPLIBS}
        if test "${LD_WRAP_TESTS}" = true -a -z "${LIBTOOL}"; then WRAP="${WRAP_OPTIONS}"; fi; \
        ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
-               ${LDFLAGS} $${WRAP} ${WRAP_RPATH} -o $@ plugin_test.@O@ nstest.@O@ \
-               ${WRAP_LIB} ${NSLIBS} ${DNSLIBS} ${ISCLIBS} ${LIBS}
+               ${LDFLAGS} $${WRAP} -o $@ plugin_test.@O@ nstest.@O@ \
+               ${NSLIBS} ${DNSLIBS} ${ISCLIBS} ${LIBS}
 
-query_test@EXEEXT@: query_test.@O@ nstest.@O@ libwrap.@SO@ ${NSDEPLIBS} ${ISCDEPLIBS} ${DNSDEPLIBS}
+query_test@EXEEXT@: query_test.@O@ nstest.@O@ ${NSDEPLIBS} ${ISCDEPLIBS} ${DNSDEPLIBS}
        if test "${LD_WRAP_TESTS}" = true -a -z "${LIBTOOL}"; then WRAP="${WRAP_OPTIONS}"; fi; \
        ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
-               ${LDFLAGS} $${WRAP} ${WRAP_RPATH} -o $@ query_test.@O@ nstest.@O@ \
-               ${WRAP_LIB} ${NSLIBS} ${DNSLIBS} ${ISCLIBS} ${LIBS}
+               ${LDFLAGS} $${WRAP} -o $@ query_test.@O@ nstest.@O@ \
+               ${NSLIBS} ${DNSLIBS} ${ISCLIBS} ${LIBS}
 
 unit::
        sh ${top_builddir}/unit/unittest.sh
index 5b5d2fd0abbbb268d763db68d30d6f3f7437a6e2..17eb44cf43470ef7fa14a8873c094afc40910a34 100644 (file)
@@ -102,6 +102,13 @@ __wrap_isc_nmhandle_unref(isc_nmhandle_t *handle) {
        return;
 }
 
+#ifdef USE_LIBTOOL
+void
+isc_nmhandle_unref(isc_nmhandle_t *handle) {
+       __wrap_isc_nmhandle_unref(handle);
+}
+#endif /* USE_LIBTOOL */
+
 /*
  * Logging categories: this needs to match the list in lib/ns/log.c.
  */
diff --git a/lib/ns/tests/wrap.c b/lib/ns/tests/wrap.c
deleted file mode 100644 (file)
index 57e2e28..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, you can obtain one at https://mozilla.org/MPL/2.0/.
- *
- * See the COPYRIGHT file distributed with this work for additional
- * information regarding copyright ownership.
- */
-
-/*! \file */
-
-#include <inttypes.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <time.h>
-#include <unistd.h>
-
-#include <isc/mem.h>
-#include <isc/netmgr.h>
-#include <isc/util.h>
-
-#include <dns/view.h>
-
-#include <ns/client.h>
-
-/*
- * This overrides calls to isc_nmhandle_unref(), sending them to
- * __wrap_isc_nmhandle_unref(), when libtool is in use and LD_WRAP
- * can't be used.
- */
-
-extern void
-__wrap_isc_nmhandle_unref(isc_nmhandle_t *handle);
-
-void
-isc_nmhandle_unref(isc_nmhandle_t *handle) {
-       __wrap_isc_nmhandle_unref(handle);
-}
index 720b3f2f8aa6f8c06a23828e075485c3c22eb6e5..15a820e986bf287c8dbe0f07774a5e99d8de0617 100644 (file)
 ./lib/ns/tests/plugin_test.c                   C       2019,2020
 ./lib/ns/tests/query_test.c                    C       2017,2018,2019,2020
 ./lib/ns/tests/testdata/notify/notify1.msg     X       2017,2018,2019,2020
-./lib/ns/tests/wrap.c                          C       2019,2020
 ./lib/ns/update.c                              C       2017,2018,2019,2020
 ./lib/ns/version.c                             C       2017,2018,2019,2020
 ./lib/ns/win32/DLLMain.c                       C       2017,2018,2019,2020