From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2103) id 034293849ADD; Fri, 19 Apr 2024 15:52:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 034293849ADD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1713541967; bh=S5JXaq9jMD+X5ZXsWcDu/SnrLQ29cbBsP5XIZoo80MQ=; h=From:To:Subject:Date:From; b=jmaCOCFbyohWzD68fJxHH+DulqhwKNMTfYUzxGb+Sw+sFkTLJ01pqfNFFBtutUgWV v3Lhc7BezzPmy0GAjdtip3Ax3mVmJAp1kNLC2rEPIMJZlp1HRtb7Hs6+kXrwWrfwIM Acl+kKkBMHpvjC+LiLsUhRnO8HSyeGCG0mJYZ0VY= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Nick Alcock To: binutils-cvs@sourceware.org Subject: [binutils-gdb] libctf: do not include undefined functions in libctf.ver X-Act-Checkin: binutils-gdb X-Git-Author: Nick Alcock X-Git-Refname: refs/heads/master X-Git-Oldrev: d8e1bca7ebc357ebd9b7a338a53d2767cf0564b6 X-Git-Newrev: edc27e2d90a2af3afddd68e7a534afcc428719e5 Message-Id: <20240419155247.034293849ADD@sourceware.org> Date: Fri, 19 Apr 2024 15:52:46 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dedc27e2d90a2= af3afddd68e7a534afcc428719e5 commit edc27e2d90a2af3afddd68e7a534afcc428719e5 Author: Nick Alcock Date: Wed Apr 17 19:06:17 2024 +0100 libctf: do not include undefined functions in libctf.ver =20 libctf's version script is applied to two libraries: libctf.so, and libctf-nobfd.so. The latter library is a subset of the former which does not link to libbfd and does not include a few public entry points that use it (found in libctf-open-bfd.c). This means that some of the symbols in this version script only exist in one of the libraries it's applied to. =20 A number of linkers dislike this: before now, only Solaris's linker caused serious problems, introducing NOTYPE-typed symbols when such things were found, but now LLD has started to complain as well: =20 ld: error: version script assignment of 'LIBCTF_1.0' to symbol 'ctf_arc= _open' failed: symbol not defined ld: error: version script assignment of 'LIBCTF_1.0' to symbol 'ctf_fdo= pen' failed: symbol not defined ld: error: version script assignment of 'LIBCTF_1.0' to symbol 'ctf_ope= n' failed: symbol not defined ld: error: version script assignment of 'LIBCTF_1.0' to symbol 'ctf_bfd= open' failed: symbol not defined ld: error: version script assignment of 'LIBCTF_1.0' to symbol 'ctf_bfd= open_ctfsect' failed: symbol not defined =20 Rather than adding more and more whack-a-mole fixes for every linker we encounter that does this, simply exclude such symbols unconditionally, using the same trick we used to use for Solaris. (Well, unconditionally if we can use version scripts with this linker at all, which is not always the case.) =20 Thanks to Nicholas Vinson for the original report and a fix very similar to this one (but not quite identical). =20 libctf/ =20 * configure.ac: Always exclude libctf symbols from libctf-nobfd's version script. * configure: Regenerated. Diff: --- libctf/configure | 21 ++++++++++++++++----- libctf/configure.ac | 21 ++++++++++++++++----- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/libctf/configure b/libctf/configure index 778c141571e..1faadefa068 100755 --- a/libctf/configure +++ b/libctf/configure @@ -16952,7 +16952,10 @@ fi =20 =20 # Use a version script, if possible, or an -export-symbols-regex otherwise. +# First figure out the version script flag: then massage the script, if +# needed. decommented_version_script=3D +no_version_script=3D { $as_echo "$as_me:${as_lineno-$LINENO}: checking for linker versioning fl= ags" >&5 $as_echo_n "checking for linker versioning flags... " >&6; } if ${ac_cv_libctf_version_script+:} false; then : @@ -16969,7 +16972,7 @@ int ctf_foo (void) { return 0; } int main (void) { return ctf_foo(); } _ACEOF if ac_fn_c_try_link "$LINENO"; then : - ac_cv_libctf_version_script=3D"-Wl,--version-script=3D'$srcdir/libctf.ve= r'" + ac_cv_libctf_version_script=3D"-Wl,--version-script" fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext @@ -16994,22 +16997,30 @@ rm -f core conftest.err conftest.$ac_objext \ =20 if test -z "$ac_cv_libctf_version_script"; then ac_cv_libctf_version_script=3D'-export-symbols-regex ctf_.*' + no_version_script=3Dt fi rm -f conftest.ver fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_libctf_version_scr= ipt" >&5 $as_echo "$ac_cv_libctf_version_script" >&6; } + +# Ensure that no symbols exist in the version script for libctf-nobfd.so +# that do not exist in the shared library itself, since some linkers (Sola= ris) +# add such symbols with type NOTYPE, and others (LLVM) complain loudly +# and fail to link. +grep -v 'libctf only' $srcdir/libctf.ver > libctf-nobfd.ver + if test -n "$decommented_version_script"; then # Solaris's version scripts use shell-style comments rather than the C-= style # used by GNU ld. Use cpp to strip the comments out. (cpp exists unde= r this # name on all platforms that support ld -z gnu-version-script.) - # Also ensure that no symbols exist in the version script for libctf-no= bfd.so - # that do not exist in the shared library itself, since some linkers ad= d such - # symbols with type NOTYPE. /lib/cpp < $srcdir/libctf.ver > libctf-decommented.ver - grep -v 'libctf only' $srcdir/libctf.ver | /lib/cpp > libctf-nobfd-deco= mmented.ver + /lib/cpp < $srcdir/libctf-nobfd.ver > libctf-nobfd-decommented.ver VERSION_FLAGS=3D"$ac_cv_libctf_version_script=3D'libctf-decommented.ver= '" VERSION_FLAGS_NOBFD=3D"$ac_cv_libctf_version_script=3D'libctf-nobfd-dec= ommented.ver'" +elif test -z "$no_version_script"; then + VERSION_FLAGS=3D"$ac_cv_libctf_version_script=3D'$srcdir/libctf.ver'" + VERSION_FLAGS_NOBFD=3D"$ac_cv_libctf_version_script=3D'libctf-nobfd.ver= '" else VERSION_FLAGS=3D"$ac_cv_libctf_version_script" VERSION_FLAGS_NOBFD=3D"$ac_cv_libctf_version_script" diff --git a/libctf/configure.ac b/libctf/configure.ac index f327d48f249..ced1aeb7ccf 100644 --- a/libctf/configure.ac +++ b/libctf/configure.ac @@ -249,7 +249,10 @@ fi AC_SUBST(HAVE_TCL_TRY) =20 # Use a version script, if possible, or an -export-symbols-regex otherwise. +# First figure out the version script flag: then massage the script, if +# needed. decommented_version_script=3D +no_version_script=3D AC_CACHE_CHECK([for linker versioning flags], [ac_cv_libctf_version_script= ], [echo 'FOO { global: mai*; local: ctf_fo*; };' > conftest.ver old_LDFLAGS=3D"$LDFLAGS" @@ -258,7 +261,7 @@ AC_CACHE_CHECK([for linker versioning flags], [ac_cv_li= bctf_version_script], CFLAGS=3D"$CFLAGS -fPIC" AC_LINK_IFELSE([AC_LANG_SOURCE([[int ctf_foo (void) { return 0; } int main (void) { return ctf_foo(); }]])], - [ac_cv_libctf_version_script=3D"-Wl,--version-script=3D'$srcdir/libctf= .ver'"], + [ac_cv_libctf_version_script=3D"-Wl,--version-script"], []) LDFLAGS=3D"$old_LDFLAGS" =20 @@ -275,19 +278,27 @@ AC_CACHE_CHECK([for linker versioning flags], [ac_cv_= libctf_version_script], =20 if test -z "$ac_cv_libctf_version_script"; then ac_cv_libctf_version_script=3D'-export-symbols-regex ctf_.*' + no_version_script=3Dt fi rm -f conftest.ver]) + +# Ensure that no symbols exist in the version script for libctf-nobfd.so +# that do not exist in the shared library itself, since some linkers (Sola= ris) +# add such symbols with type NOTYPE, and others (LLVM) complain loudly +# and fail to link. +grep -v 'libctf only' $srcdir/libctf.ver > libctf-nobfd.ver + if test -n "$decommented_version_script"; then # Solaris's version scripts use shell-style comments rather than the C-= style # used by GNU ld. Use cpp to strip the comments out. (cpp exists unde= r this # name on all platforms that support ld -z gnu-version-script.) - # Also ensure that no symbols exist in the version script for libctf-no= bfd.so - # that do not exist in the shared library itself, since some linkers ad= d such - # symbols with type NOTYPE. /lib/cpp < $srcdir/libctf.ver > libctf-decommented.ver - grep -v 'libctf only' $srcdir/libctf.ver | /lib/cpp > libctf-nobfd-deco= mmented.ver + /lib/cpp < $srcdir/libctf-nobfd.ver > libctf-nobfd-decommented.ver VERSION_FLAGS=3D"$ac_cv_libctf_version_script=3D'libctf-decommented.ver= '" VERSION_FLAGS_NOBFD=3D"$ac_cv_libctf_version_script=3D'libctf-nobfd-dec= ommented.ver'" +elif test -z "$no_version_script"; then + VERSION_FLAGS=3D"$ac_cv_libctf_version_script=3D'$srcdir/libctf.ver'" + VERSION_FLAGS_NOBFD=3D"$ac_cv_libctf_version_script=3D'libctf-nobfd.ver= '" else VERSION_FLAGS=3D"$ac_cv_libctf_version_script" VERSION_FLAGS_NOBFD=3D"$ac_cv_libctf_version_script"