Commit 3d6b6ead64d0c822790fb017c1ad97676af5c3b9

Guillem Jover 2019-11-16T00:04:18

build: Detect support for --version-script in ld

diff --git a/configure.ac b/configure.ac
index 6e9496d..e8d4c5f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -27,6 +27,25 @@ AC_SYS_LARGEFILE
 
 LT_INIT
 
+AC_CACHE_CHECK([if ld supports --version-script flag],
+  [libbsd_cv_version_script], [
+    echo "{ global: symbol; local: *; };" >conftest.map
+    save_LDFLAGS=$LDFLAGS
+    LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map"
+    AC_LINK_IFELSE([
+      AC_LANG_PROGRAM([], [])
+    ], [
+      libbsd_cv_version_script=yes
+    ], [
+      libbsd_cv_version_script=no
+    ])
+    LDFLAGS="$save_LDFLAGS"
+    rm -f conftest.map
+  ]
+)
+AM_CONDITIONAL([HAVE_LINKER_VERSION_SCRIPT],
+  [test "x$libbsd_cv_version_script" = "xyes"])
+
 # Checks for programs.
 AC_PROG_CC
 AC_PROG_INSTALL
diff --git a/src/Makefile.am b/src/Makefile.am
index 8384b92..c4229cf 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -65,8 +65,11 @@ libbsd_la_LIBADD = \
 	$(ARC4RANDOM_ATFORK_LIBS) \
 	$(nil)
 libbsd_la_LDFLAGS = \
-	-Wl,--version-script=$(srcdir)/libbsd.map \
 	-version-number $(LIBBSD_ABI)
+if HAVE_LINKER_VERSION_SCRIPT
+libbsd_la_LDFLAGS += \
+	-Wl,--version-script=$(srcdir)/libbsd.map
+endif
 libbsd_la_SOURCES = \
 	arc4random.c \
 	arc4random.h \