Skip to content

Commit c6b15ec

Browse files
committed
Merge #17874: build: make linker checks more robust
03da4c7 build: make linker checks more robust (Cory Fields) Pull request description: Check for a flag to turn linker warnings into errors. When flags are passed to linkers via the compiler driver using a -Wl,-foo flag, linker warnings may be swallowed rather than bubbling up. This is one of [Corys commits](theuni/bitcoin@b9acd3d) that I've modified to also add `-Wl,-fatal_warnings` for darwin. ACKs for top commit: vasild: re-ACK 03da4c7 Tree-SHA512: 212031d619ed88e52aaae30cf3b711681d72c4d670884406403605d1d86c784c84cb07e2e0d6c30926e659db8f14f8dabd5af3de5291637f8080d6dfee358248
2 parents f763283 + 03da4c7 commit c6b15ec

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed

configure.ac

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,30 @@ AC_ARG_ENABLE([werror],
283283
[enable_werror=no])
284284

285285
AC_LANG_PUSH([C++])
286+
287+
dnl Check for a flag to turn compiler warnings into errors. This is helpful for checks which may
288+
dnl appear to succeed because by default they merely emit warnings when they fail.
289+
dnl
290+
dnl Note that this is not necessarily a check to see if -Werror is supported, but rather to see if
291+
dnl a compile with -Werror can succeed. This is important because the compiler may already be
292+
dnl warning about something unrelated, for example about some path issue. If that is the case,
293+
dnl -Werror cannot be used because all of those warnings would be turned into errors.
286294
AX_CHECK_COMPILE_FLAG([-Werror],[CXXFLAG_WERROR="-Werror"],[CXXFLAG_WERROR=""])
287295

296+
dnl Check for a flag to turn linker warnings into errors. When flags are passed to linkers via the
297+
dnl compiler driver using a -Wl,-foo flag, linker warnings may be swallowed rather than bubbling up.
298+
dnl See note above, the same applies here as well.
299+
dnl
300+
dnl LDFLAG_WERROR Should only be used when testing -Wl,*
301+
case $host in
302+
*darwin*)
303+
AX_CHECK_LINK_FLAG([-Wl,-fatal_warnings],[LDFLAG_WERROR="-Wl,-fatal_warnings"],[LDFLAG_WERROR=""])
304+
;;
305+
*)
306+
AX_CHECK_LINK_FLAG([-Wl,--fatal-warnings],[LDFLAG_WERROR="-Wl,--fatal-warnings"],[LDFLAG_WERROR=""])
307+
;;
308+
esac
309+
288310
if test "x$enable_debug" = xyes; then
289311
dnl Clear default -g -O2 flags
290312
if test "x$CXXFLAGS_overridden" = xno; then
@@ -613,7 +635,7 @@ case $host in
613635
esac
614636
fi
615637

616-
AX_CHECK_LINK_FLAG([[-Wl,-headerpad_max_install_names]], [LDFLAGS="$LDFLAGS -Wl,-headerpad_max_install_names"])
638+
AX_CHECK_LINK_FLAG([[-Wl,-headerpad_max_install_names]], [LDFLAGS="$LDFLAGS -Wl,-headerpad_max_install_names"],, [[$LDFLAG_WERROR]])
617639
CPPFLAGS="$CPPFLAGS -DMAC_OSX -DOBJC_OLD_DISPATCH_PROTOTYPES=0"
618640
OBJCXXFLAGS="$CXXFLAGS"
619641
;;
@@ -709,8 +731,8 @@ if test x$use_glibc_compat != xno; then
709731
[ fdelt_type="long int"])
710732
AC_MSG_RESULT($fdelt_type)
711733
AC_DEFINE_UNQUOTED(FDELT_TYPE, $fdelt_type,[parameter and return value type for __fdelt_chk])
712-
AX_CHECK_LINK_FLAG([[-Wl,--wrap=__divmoddi4]], [COMPAT_LDFLAGS="$COMPAT_LDFLAGS -Wl,--wrap=__divmoddi4"])
713-
AX_CHECK_LINK_FLAG([[-Wl,--wrap=log2f]], [COMPAT_LDFLAGS="$COMPAT_LDFLAGS -Wl,--wrap=log2f"])
734+
AX_CHECK_LINK_FLAG([[-Wl,--wrap=__divmoddi4]], [COMPAT_LDFLAGS="$COMPAT_LDFLAGS -Wl,--wrap=__divmoddi4"],, [[$LDFLAG_WERROR]])
735+
AX_CHECK_LINK_FLAG([[-Wl,--wrap=log2f]], [COMPAT_LDFLAGS="$COMPAT_LDFLAGS -Wl,--wrap=log2f"],, [[$LDFLAG_WERROR]])
714736
else
715737
AC_SEARCH_LIBS([clock_gettime],[rt])
716738
fi
@@ -758,11 +780,11 @@ if test x$use_hardening != xno; then
758780
])
759781
fi
760782

761-
AX_CHECK_LINK_FLAG([[-Wl,--dynamicbase]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--dynamicbase"])
762-
AX_CHECK_LINK_FLAG([[-Wl,--nxcompat]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--nxcompat"])
763-
AX_CHECK_LINK_FLAG([[-Wl,--high-entropy-va]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--high-entropy-va"])
764-
AX_CHECK_LINK_FLAG([[-Wl,-z,relro]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"])
765-
AX_CHECK_LINK_FLAG([[-Wl,-z,now]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"])
783+
AX_CHECK_LINK_FLAG([[-Wl,--dynamicbase]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--dynamicbase"],, [[$LDFLAG_WERROR]])
784+
AX_CHECK_LINK_FLAG([[-Wl,--nxcompat]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--nxcompat"],, [[$LDFLAG_WERROR]])
785+
AX_CHECK_LINK_FLAG([[-Wl,--high-entropy-va]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--high-entropy-va"],, [[$LDFLAG_WERROR]])
786+
AX_CHECK_LINK_FLAG([[-Wl,-z,relro]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"],, [[$LDFLAG_WERROR]])
787+
AX_CHECK_LINK_FLAG([[-Wl,-z,now]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"],, [[$LDFLAG_WERROR]])
766788
AX_CHECK_LINK_FLAG([[-fPIE -pie]], [PIE_FLAGS="-fPIE"; HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"],, [[$CXXFLAG_WERROR]])
767789

768790
case $host in
@@ -776,14 +798,14 @@ dnl These flags are specific to ld64, and may cause issues with other linkers.
776798
dnl For example: GNU ld will intepret -dead_strip as -de and then try and use
777799
dnl "ad_strip" as the symbol for the entry point.
778800
if test x$TARGET_OS = xdarwin; then
779-
AX_CHECK_LINK_FLAG([[-Wl,-dead_strip]], [LDFLAGS="$LDFLAGS -Wl,-dead_strip"])
780-
AX_CHECK_LINK_FLAG([[-Wl,-dead_strip_dylibs]], [LDFLAGS="$LDFLAGS -Wl,-dead_strip_dylibs"])
781-
AX_CHECK_LINK_FLAG([[-Wl,-bind_at_load]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-bind_at_load"])
801+
AX_CHECK_LINK_FLAG([[-Wl,-dead_strip]], [LDFLAGS="$LDFLAGS -Wl,-dead_strip"],, [[$LDFLAG_WERROR]])
802+
AX_CHECK_LINK_FLAG([[-Wl,-dead_strip_dylibs]], [LDFLAGS="$LDFLAGS -Wl,-dead_strip_dylibs"],, [[$LDFLAG_WERROR]])
803+
AX_CHECK_LINK_FLAG([[-Wl,-bind_at_load]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-bind_at_load"],, [[$LDFLAG_WERROR]])
782804
fi
783805

784806
if test x$enable_determinism = xyes; then
785807
if test x$TARGET_OS = xwindows; then
786-
AX_CHECK_LINK_FLAG([[-Wl,--no-insert-timestamp]], [LDFLAGS="$LDFLAGS -Wl,--no-insert-timestamp"])
808+
AX_CHECK_LINK_FLAG([[-Wl,--no-insert-timestamp]], [LDFLAGS="$LDFLAGS -Wl,--no-insert-timestamp"],, [[$LDFLAG_WERROR]])
787809
fi
788810
fi
789811

@@ -1215,7 +1237,7 @@ fi
12151237

12161238
if test x$use_reduce_exports = xyes; then
12171239
CXXFLAGS="$CXXFLAGS $RE_CXXFLAGS"
1218-
AX_CHECK_LINK_FLAG([[-Wl,--exclude-libs,ALL]], [RELDFLAGS="-Wl,--exclude-libs,ALL"])
1240+
AX_CHECK_LINK_FLAG([[-Wl,--exclude-libs,ALL]], [RELDFLAGS="-Wl,--exclude-libs,ALL"],, [[$LDFLAG_WERROR]])
12191241
fi
12201242

12211243
if test x$use_tests = xyes; then

0 commit comments

Comments
 (0)