From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1791) id 1C6213858C5E; Tue, 2 Apr 2024 15:59:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1C6213858C5E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1712073587; bh=T8GO7HXorY5Digv1NBApPeKJ5SGB7gqcdVGrzwznlyo=; h=From:To:Subject:Date:From; b=x7DHeq47DPf7WG6RebXwvVLfH5MA7X5JrJgmz3I+0qvuJkhh9nbLYGSO6BMCE+5/V SgpGRU7h6sYALPG4j0KqM9LBiHw+kvGm/VRj0HwVuMYvXYgKdNrnqf/ZnS/troPOJi fa8ZD9Q6NVqIgIZNqIW8tHyxSva7ApIQYE/TKUZU= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Adhemerval Zanella To: glibc-cvs@sourceware.org Subject: [glibc/azanella/clang] Use -Wl, --undefined-version if linker requires it X-Act-Checkin: glibc X-Git-Author: Adhemerval Zanella X-Git-Refname: refs/heads/azanella/clang X-Git-Oldrev: 83c227f66fb6427f7045c65fe61af7ee54d2a0f5 X-Git-Newrev: b37295d084d381a5f3595f6a8379739231c0ed20 Message-Id: <20240402155947.1C6213858C5E@sourceware.org> Date: Tue, 2 Apr 2024 15:59:47 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=b37295d084d381a5f3595f6a8379739231c0ed20 commit b37295d084d381a5f3595f6a8379739231c0ed20 Author: Adhemerval Zanella Date: Wed Jan 4 13:46:38 2023 -0300 Use -Wl,--undefined-version if linker requires it The lld might set --no-undefined-version as default, which triggers a lot of error since the Versions files may contain entries not exported by all ABI. The -Wl,--undefined-version can not be set by default, since binutils ld does not support (although gold does). So it requires to be checked at configure if linker requires and enabled it conditionally. Diff: --- Makeconfig | 9 ++++++++ configure | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 27 ++++++++++++++++++++++++ 3 files changed, 104 insertions(+) diff --git a/Makeconfig b/Makeconfig index acde47e99c..ce19406b88 100644 --- a/Makeconfig +++ b/Makeconfig @@ -424,6 +424,15 @@ ifndef after-link after-link = endif +# The Versions file may contain entries not exported by all ABI, which +# trigger errors if the linker defaults to --no-undefined-version. The +# configure checks whether it is the case and adds --undefined-version +# if required. +LDFLAGS-rtld += $(config-ldflags-undefined-version) +LDFLAGS-lib.so += $(config-ldflags-undefined-version) +LDFLAGS.so += $(config-ldflags-undefined-version) +link-extra-flags += $(config-ldflags-undefined-version) + # Additional libraries to link into every test. link-extra-libs-tests = $(libsupport) diff --git a/configure b/configure index 37af7ce6a2..d5ce50849a 100755 --- a/configure +++ b/configure @@ -6927,6 +6927,74 @@ printf "%s\n" "$libc_linker_feature" >&6; } config_vars="$config_vars have-no-dynamic-linker = $libc_cv_no_dynamic_linker" +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to suppress unused version in version script" >&5 +printf %s "checking whether to suppress unused version in version script... " >&6; } +if test ${libc_cv_undefined_version+y} +then : + printf %s "(cached) " >&6 +else $as_nop + cat > conftest.c < conftest.map <&5 + (eval $ac_try) 2>&5 + ac_status=$? + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; }; +then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for linker that supports --undefined-version" >&5 +printf %s "checking for linker that supports --undefined-version... " >&6; } +libc_linker_feature=no +cat > conftest.c <&5 + (eval $ac_try) 2>&5 + ac_status=$? + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; } +then + if ${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS $no_ssp -Wl,--undefined-version -nostdlib \ + -nostartfiles -fPIC -shared -o conftest.so conftest.c 2>&1 \ + | grep "warning: --undefined-version ignored" > /dev/null 2>&1; then + true + else + libc_linker_feature=yes + fi +fi +rm -f conftest* +if test $libc_linker_feature = yes; then + libc_cv_support_undefined_version=yes +else + libc_cv_support_undefined_version=no +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_linker_feature" >&5 +printf "%s\n" "$libc_linker_feature" >&6; } + if test "$libc_cv_support_undefined_version" = no; then + as_fn_error $? "support for -Wl,--undefined-version required" "$LINENO" 5 + fi + libc_cv_undefined_version="-Wl,--undefined-version" +fi +rm -f conftest.*t +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_undefined_version" >&5 +printf "%s\n" "$libc_cv_undefined_version" >&6; } +config_vars="$config_vars +config-ldflags-undefined-version = $libc_cv_undefined_version" + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for -static-pie" >&5 printf %s "checking for -static-pie... " >&6; } if test ${libc_cv_static_pie+y} diff --git a/configure.ac b/configure.ac index b501ddd439..5f75b25105 100644 --- a/configure.ac +++ b/configure.ac @@ -1254,6 +1254,33 @@ LIBC_LINKER_FEATURE([--no-dynamic-linker], [libc_cv_no_dynamic_linker=no]) LIBC_CONFIG_VAR([have-no-dynamic-linker], [$libc_cv_no_dynamic_linker]) +AC_CACHE_CHECK(whether to suppress unused version in version script, + libc_cv_undefined_version, [dnl +cat > conftest.c < conftest.map <