Add -Wl,--export-dynamic to standard LDFLAGS if supported

From the ld man page:

  When creating a dynamically linked executable, using the -E option or
  the --export-dynamic option causes the linker to add all symbols to
  the dynamic symbol table.  The dynamic symbol table is the set of
  symbols which are visible from dynamic objects at run time.

This should allow the backtrace(3) to fully resolve the symbols when
creating backtrace on an assertion failure.

(cherry picked from commit b05e20c968)
This commit is contained in:
Ondřej Surý 2022-04-27 16:41:27 +02:00
parent ae8b335c11
commit 7fef5fc46c
2 changed files with 9 additions and 2 deletions

View file

@ -11,7 +11,8 @@ AM_CPPFLAGS = \
-include $(top_builddir)/config.h \
-I$(srcdir)/include
AM_LDFLAGS =
AM_LDFLAGS = \
$(STD_LDFLAGS)
LDADD =
if HOST_MACOS

View file

@ -112,13 +112,15 @@ AS_IF([test "$enable_static" != "no" && test "$enable_developer" != "yes"],
[AC_MSG_ERROR([Static linking is not supported as it disables dlopen() and certain security features (e.g. RELRO, ASLR)])])
#
# Set the default CFLAGS and CPPFLAGS
# Set the default CFLAGS, CPPFLAGS, and LDFLAGS
#
STD_CFLAGS="-Wall -Wextra -Wwrite-strings -Wpointer-arith -Wno-missing-field-initializers -Wformat -Wshadow"
# These should be always errors
STD_CFLAGS="$STD_CFLAGS -Werror=implicit-function-declaration -Werror=missing-prototypes -Werror=format-security -Werror=parentheses -Werror=implicit -Werror=strict-prototypes -Werror=vla"
STD_LDFLAGS=""
# ... except in test code
TEST_CFLAGS="-Wno-vla"
@ -136,6 +138,9 @@ AX_CHECK_COMPILE_FLAG([-Werror -fno-delete-null-pointer-checks],
AX_CHECK_COMPILE_FLAG([-fdiagnostics-show-option],
[STD_CFLAGS="$STD_CFLAGS -fdiagnostics-show-option"])
AX_CHECK_LINK_FLAG([-Wl,--export-dynamic],
[STD_LDFLAGS="$STD_LDFLAGS -Wl,--export-dynamic"])
host_macos=no
AS_CASE([$host],[*-darwin*],[host_macos=yes])
AM_CONDITIONAL([HOST_MACOS], [test "$host_macos" = "yes"])
@ -162,6 +167,7 @@ AS_IF([test "$enable_developer" = "yes"],
AC_SUBST([DEVELOPER_MODE])
AC_SUBST([STD_CFLAGS])
AC_SUBST([STD_CPPFLAGS])
AC_SUBST([STD_LDFLAGS])
AC_SUBST([TEST_CFLAGS])
# [pairwise: --enable-warn-error, --disable-warn-error]