From 377be0ea7a1d0ec3572a7f9a5f9ed42adeaa4503 Mon Sep 17 00:00:00 2001 From: Lasse Collin Date: Wed, 21 May 2025 16:07:01 +0300 Subject: [PATCH] Build: With symbol versioning, try to pass --undefined-version to linker Fixes: https://github.com/tukaani-project/xz/issues/180 Fixes: https://bugs.gentoo.org/956119 --- configure.ac | 23 +++++++++++++++++++++++ src/liblzma/Makefile.am | 2 ++ 2 files changed, 25 insertions(+) diff --git a/configure.ac b/configure.ac index 80d6d338..47e2dc65 100644 --- a/configure.ac +++ b/configure.ac @@ -758,6 +758,7 @@ fi # --with-pic and --without-pic though. As long as neither --with-pic nor # --without-pic is used then we can use #ifdef PIC to detect if the file is # being built for a shared library. +LINKER_FLAG_UNDEFINED_VERSION= AS_IF([test "x$enable_symbol_versions" = xno], [ enable_symbol_versions=no AC_MSG_RESULT([no]) @@ -831,12 +832,34 @@ AS_IF([test "x$enable_symbol_versions" = xno], [ AC_MSG_ERROR([unknown symbol versioning variant '$enable_symbol_versions']) fi AC_MSG_RESULT([yes ($enable_symbol_versions)]) + + # If features are disabled in liblzma, some symbols may be missing. + # LLVM's lld defaults to --no-undefined-version and the build breaks + # if not all symbols in the version script exist. That is good for + # catching errors like typos, but in our case the downside is too big. + # Avoid the problem by using --undefined-version if the linker + # supports it. + # + # GNU ld has had --no-undefined-version for a long time but it's not + # the default. The opposite option --undefined-version was only added + # in 2022, thus we must use --undefined-version conditionally. + AC_MSG_CHECKING([if linker supports --undefined-version]) + OLD_LDFLAGS=$LDFLAGS + LDFLAGS="$LDFLAGS -Wl,--undefined-version" + AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void) { return 0; }]])], [ + LINKER_FLAG_UNDEFINED_VERSION=-Wl,--undefined-version + AC_MSG_RESULT([yes]) + ], [ + AC_MSG_RESULT([no]) + ]) + LDFLAGS=$OLD_LDFLAGS ]) AM_CONDITIONAL([COND_SYMVERS_LINUX], [test "x$enable_symbol_versions" = xlinux]) AM_CONDITIONAL([COND_SYMVERS_GENERIC], [test "x$enable_symbol_versions" = xgeneric]) +AC_SUBST([LINKER_FLAG_UNDEFINED_VERSION]) ############################################################################### diff --git a/src/liblzma/Makefile.am b/src/liblzma/Makefile.am index d5547020..7a05881b 100644 --- a/src/liblzma/Makefile.am +++ b/src/liblzma/Makefile.am @@ -25,10 +25,12 @@ liblzma_la_LDFLAGS = -no-undefined -version-info 13:1:8 EXTRA_DIST += liblzma_generic.map liblzma_linux.map validate_map.sh if COND_SYMVERS_GENERIC liblzma_la_LDFLAGS += \ + $(LINKER_FLAG_UNDEFINED_VERSION) \ -Wl,--version-script=$(top_srcdir)/src/liblzma/liblzma_generic.map endif if COND_SYMVERS_LINUX liblzma_la_LDFLAGS += \ + $(LINKER_FLAG_UNDEFINED_VERSION) \ -Wl,--version-script=$(top_srcdir)/src/liblzma/liblzma_linux.map endif