]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
Build: With symbol versioning, try to pass --undefined-version to linker
authorLasse Collin <lasse.collin@tukaani.org>
Wed, 21 May 2025 13:07:01 +0000 (16:07 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Wed, 21 May 2025 13:07:01 +0000 (16:07 +0300)
Fixes: https://github.com/tukaani-project/xz/issues/180
Fixes: https://bugs.gentoo.org/956119
configure.ac
src/liblzma/Makefile.am

index 80d6d3387f45376cfbec44783718386513fcd373..47e2dc65bcdb7b133ae39be6255842b3731e0c3f 100644 (file)
@@ -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])
 
 
 ###############################################################################
index d5547020126522cbf97bfdcb18ace296f1274af1..7a05881b4d624e548a26a7b943d98793484d9a0c 100644 (file)
@@ -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