From 7f37668ba2e813f15f2a444a8dfadc7eb3e5acd4 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Fri, 28 Jun 2024 17:32:28 +0100 Subject: [PATCH] autotools: Add `--no-undefined` linker option --- Makefile.am | 2 +- build-aux/m4/bitcoin_secp.m4 | 16 ++++++++++++++++ configure.ac | 3 +++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 322e44eaab..57464fa35b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -98,7 +98,7 @@ endif libsecp256k1_la_SOURCES = src/secp256k1.c libsecp256k1_la_CPPFLAGS = $(SECP_CONFIG_DEFINES) libsecp256k1_la_LIBADD = $(COMMON_LIB) $(PRECOMPUTED_LIB) -libsecp256k1_la_LDFLAGS = -no-undefined -version-info $(LIB_VERSION_CURRENT):$(LIB_VERSION_REVISION):$(LIB_VERSION_AGE) +libsecp256k1_la_LDFLAGS = -no-undefined -version-info $(LIB_VERSION_CURRENT):$(LIB_VERSION_REVISION):$(LIB_VERSION_AGE) $(SECP_LIB_LDFLAGS) noinst_PROGRAMS = if USE_BENCHMARK diff --git a/build-aux/m4/bitcoin_secp.m4 b/build-aux/m4/bitcoin_secp.m4 index 048267fa6e..6036fa04d5 100644 --- a/build-aux/m4/bitcoin_secp.m4 +++ b/build-aux/m4/bitcoin_secp.m4 @@ -77,6 +77,22 @@ AC_DEFUN([SECP_TRY_APPEND_CFLAGS], [ AC_SUBST($2) ]) +dnl SECP_TRY_APPEND_LDFLAGS(flags, VAR) +dnl Append flags to VAR if a linker accepts them. +AC_DEFUN([SECP_TRY_APPEND_LDFLAGS], [ + AC_MSG_CHECKING([if linker supports $1]) + SECP_TRY_APPEND_LDFLAGS_saved_LDFLAGS="$LDFLAGS" + LDFLAGS="$1 $LDFLAGS" + AC_LINK_IFELSE([AC_LANG_PROGRAM()], [flag_works=yes], [flag_works=no]) + AC_MSG_RESULT($flag_works) + LDFLAGS="$SECP_TRY_APPEND_LDFLAGS_saved_LDFLAGS" + if test x"$flag_works" = x"yes"; then + $2="$$2 $1" + fi + unset flag_works + AC_SUBST($2) +]) + dnl SECP_SET_DEFAULT(VAR, default, default-dev-mode) dnl Set VAR to default or default-dev-mode, depending on whether dev mode is enabled AC_DEFUN([SECP_SET_DEFAULT], [ diff --git a/configure.ac b/configure.ac index adae189787..a57b9c84f8 100644 --- a/configure.ac +++ b/configure.ac @@ -131,6 +131,8 @@ AC_DEFUN([SECP_TRY_APPEND_DEFAULT_CFLAGS], [ ]) SECP_TRY_APPEND_DEFAULT_CFLAGS(SECP_CFLAGS) +SECP_TRY_APPEND_LDFLAGS([-Wl,--no-undefined], [SECP_LIB_LDFLAGS]) + ### ### Define config arguments ### @@ -486,6 +488,7 @@ echo " CC = $CC" echo " CPPFLAGS = $CPPFLAGS" echo " SECP_CFLAGS = $SECP_CFLAGS" echo " CFLAGS = $CFLAGS" +echo " SECP_LIB_LDFLAGS = $SECP_LIB_LDFLAGS" echo " LDFLAGS = $LDFLAGS" if test x"$print_msan_notice" = x"yes"; then