From b60d7345edae90560721c20d705ab32563abccb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Mon, 28 Sep 2020 09:09:21 +0200 Subject: [PATCH] Fix function overrides in unit tests on macOS Since Mac OS X 10.1, Mach-O object files are by default built with a so-called two-level namespace which prevents symbol lookups in BIND unit tests that attempt to override the implementations of certain library functions from working as intended. This feature can be disabled by passing the "-flat_namespace" flag to the linker. Fix unit tests affected by this issue on macOS by adding "-flat_namespace" to LDFLAGS used for building all object files on that operating system (it is not enough to only set that flag for the unit test executables). --- Makefile.top | 7 +++++++ configure.ac | 4 ++++ fuzz/Makefile.am | 2 +- lib/bind9/Makefile.am | 1 + lib/dns/Makefile.am | 1 + lib/irs/Makefile.am | 1 + lib/isc/Makefile.am | 1 + lib/isccc/Makefile.am | 1 + lib/isccfg/Makefile.am | 1 + lib/ns/Makefile.am | 1 + 10 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Makefile.top b/Makefile.top index 727f08bf49..66aaecf7bd 100644 --- a/Makefile.top +++ b/Makefile.top @@ -11,6 +11,13 @@ AM_CPPFLAGS = \ -include $(top_builddir)/config.h \ -I$(srcdir)/include +AM_LDFLAGS = + +if HOST_MACOS +AM_LDFLAGS += \ + -Wl,-flat_namespace +endif HOST_MACOS + if HAVE_GSSAPI AM_CPPFLAGS += \ $(GSSAPI_CFLAGS) diff --git a/configure.ac b/configure.ac index 441e150447..97286bcd98 100644 --- a/configure.ac +++ b/configure.ac @@ -150,6 +150,10 @@ AX_CHECK_COMPILE_FLAG([-Werror -fno-delete-null-pointer-checks], AX_CHECK_COMPILE_FLAG([-fdiagnostics-show-option], [STD_CFLAGS="$STD_CFLAGS -fdiagnostics-show-option"]) +host_macos=no +AS_CASE([$host],[*-darwin*],[host_macos=yes]) +AM_CONDITIONAL([HOST_MACOS], [test "$host_macos" = "yes"]) + # # Change defaults for developers if not explicity set. # Needs to be before the option is tested. diff --git a/fuzz/Makefile.am b/fuzz/Makefile.am index 4ba24e4029..bf5aa3eeb2 100644 --- a/fuzz/Makefile.am +++ b/fuzz/Makefile.am @@ -5,7 +5,7 @@ AM_CPPFLAGS += \ $(LIBDNS_CFLAGS) \ -DFUZZDIR=\"$(abs_srcdir)\" -AM_LDFLAGS = \ +AM_LDFLAGS += \ $(FUZZ_LDFLAGS) LDADD = \ diff --git a/lib/bind9/Makefile.am b/lib/bind9/Makefile.am index 3501cef49c..6b7edf8c9a 100644 --- a/lib/bind9/Makefile.am +++ b/lib/bind9/Makefile.am @@ -27,6 +27,7 @@ libbind9_la_LIBADD = \ $(LIBISCCFG_LIBS) libbind9_la_LDFLAGS = \ + $(AM_LDFLAGS) \ $(libbind9_VERSION_INFO) EXTRA_DIST = api diff --git a/lib/dns/Makefile.am b/lib/dns/Makefile.am index 78a2752c90..73e6bc2f73 100644 --- a/lib/dns/Makefile.am +++ b/lib/dns/Makefile.am @@ -287,6 +287,7 @@ libdns_la_CPPFLAGS = \ $(LIBLTDL_CFLAGS) libdns_la_LDFLAGS = \ + $(AM_LDFLAGS) \ $(libdns_VERSION_INFO) libdns_la_LIBADD = \ diff --git a/lib/irs/Makefile.am b/lib/irs/Makefile.am index 75d514cbcb..f7b82b47bc 100644 --- a/lib/irs/Makefile.am +++ b/lib/irs/Makefile.am @@ -23,6 +23,7 @@ libirs_la_LIBADD = \ $(LIBISCCFG_LIBS) libirs_la_LDFLAGS = \ + $(AM_LDFLAGS) \ $(libirs_VERSION_INFO) diff --git a/lib/isc/Makefile.am b/lib/isc/Makefile.am index cde0947bde..2c84285b16 100644 --- a/lib/isc/Makefile.am +++ b/lib/isc/Makefile.am @@ -227,6 +227,7 @@ libisc_la_CPPFLAGS = \ $(ZLIB_CFLAGS) libisc_la_LDFLAGS = \ + $(AM_LDFLAGS) \ $(libisc_VERSION_INFO) libisc_la_LIBADD = \ diff --git a/lib/isccc/Makefile.am b/lib/isccc/Makefile.am index 477cc525fb..aca06f777f 100644 --- a/lib/isccc/Makefile.am +++ b/lib/isccc/Makefile.am @@ -35,6 +35,7 @@ libisccc_la_LIBADD = \ $(LIBISC_LIBS) libisccc_la_LDFLAGS = \ + $(AM_LDFLAGS) \ $(libisccc_VERSION_INFO) if HAVE_CMOCKA diff --git a/lib/isccfg/Makefile.am b/lib/isccfg/Makefile.am index ef0cd16fc8..eb4b7d53d9 100644 --- a/lib/isccfg/Makefile.am +++ b/lib/isccfg/Makefile.am @@ -32,6 +32,7 @@ libisccfg_la_LIBADD = \ $(LIBDNS_LIBS) libisccfg_la_LDFLAGS = \ + $(AM_LDFLAGS) \ $(libisccfg_VERSION_INFO) if HAVE_CMOCKA diff --git a/lib/ns/Makefile.am b/lib/ns/Makefile.am index b2f81ccf08..7f79af4292 100644 --- a/lib/ns/Makefile.am +++ b/lib/ns/Makefile.am @@ -51,6 +51,7 @@ libns_la_LIBADD = \ $(LIBDNS_LIBS) libns_la_LDFLAGS = \ + $(AM_LDFLAGS) \ $(libns_VERSION_INFO) if HAVE_CMOCKA