public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
* [binutils-gdb] libctf: do not include undefined functions in libctf.ver
@ 2024-04-19 15:52 Nick Alcock
  0 siblings, 0 replies; only message in thread
From: Nick Alcock @ 2024-04-19 15:52 UTC (permalink / raw)
  To: binutils-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=edc27e2d90a2af3afddd68e7a534afcc428719e5

commit edc27e2d90a2af3afddd68e7a534afcc428719e5
Author: Nick Alcock <nick.alcock@oracle.com>
Date:   Wed Apr 17 19:06:17 2024 +0100

    libctf: do not include undefined functions in libctf.ver
    
    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.
    
    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:
    
    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_fdopen' failed: symbol not defined
    ld: error: version script assignment of 'LIBCTF_1.0' to symbol 'ctf_open' failed: symbol not defined
    ld: error: version script assignment of 'LIBCTF_1.0' to symbol 'ctf_bfdopen' failed: symbol not defined
    ld: error: version script assignment of 'LIBCTF_1.0' to symbol 'ctf_bfdopen_ctfsect' failed: symbol not defined
    
    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.)
    
    Thanks to Nicholas Vinson for the original report and a fix very
    similar to this one (but not quite identical).
    
    libctf/
    
            * 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
 
 
 # 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=
+no_version_script=
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for linker versioning flags" >&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="-Wl,--version-script='$srcdir/libctf.ver'"
+  ac_cv_libctf_version_script="-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 \
 
    if test -z "$ac_cv_libctf_version_script"; then
      ac_cv_libctf_version_script='-export-symbols-regex ctf_.*'
+     no_version_script=t
    fi
    rm -f conftest.ver
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_libctf_version_script" >&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 (Solaris)
+# 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 under this
    # name on all platforms that support ld -z gnu-version-script.)
-   # Also 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 add such
-   # symbols with type NOTYPE.
    /lib/cpp < $srcdir/libctf.ver > libctf-decommented.ver
-   grep -v 'libctf only' $srcdir/libctf.ver | /lib/cpp > libctf-nobfd-decommented.ver
+   /lib/cpp < $srcdir/libctf-nobfd.ver > libctf-nobfd-decommented.ver
    VERSION_FLAGS="$ac_cv_libctf_version_script='libctf-decommented.ver'"
    VERSION_FLAGS_NOBFD="$ac_cv_libctf_version_script='libctf-nobfd-decommented.ver'"
+elif test -z "$no_version_script"; then
+   VERSION_FLAGS="$ac_cv_libctf_version_script='$srcdir/libctf.ver'"
+   VERSION_FLAGS_NOBFD="$ac_cv_libctf_version_script='libctf-nobfd.ver'"
 else
    VERSION_FLAGS="$ac_cv_libctf_version_script"
    VERSION_FLAGS_NOBFD="$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)
 
 # 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=
+no_version_script=
 AC_CACHE_CHECK([for linker versioning flags], [ac_cv_libctf_version_script],
   [echo 'FOO { global: mai*; local: ctf_fo*; };' > conftest.ver
    old_LDFLAGS="$LDFLAGS"
@@ -258,7 +261,7 @@ AC_CACHE_CHECK([for linker versioning flags], [ac_cv_libctf_version_script],
    CFLAGS="$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="-Wl,--version-script='$srcdir/libctf.ver'"],
+		  [ac_cv_libctf_version_script="-Wl,--version-script"],
 		  [])
    LDFLAGS="$old_LDFLAGS"
 
@@ -275,19 +278,27 @@ AC_CACHE_CHECK([for linker versioning flags], [ac_cv_libctf_version_script],
 
    if test -z "$ac_cv_libctf_version_script"; then
      ac_cv_libctf_version_script='-export-symbols-regex ctf_.*'
+     no_version_script=t
    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 (Solaris)
+# 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 under this
    # name on all platforms that support ld -z gnu-version-script.)
-   # Also 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 add such
-   # symbols with type NOTYPE.
    /lib/cpp < $srcdir/libctf.ver > libctf-decommented.ver
-   grep -v 'libctf only' $srcdir/libctf.ver | /lib/cpp > libctf-nobfd-decommented.ver
+   /lib/cpp < $srcdir/libctf-nobfd.ver > libctf-nobfd-decommented.ver
    VERSION_FLAGS="$ac_cv_libctf_version_script='libctf-decommented.ver'"
    VERSION_FLAGS_NOBFD="$ac_cv_libctf_version_script='libctf-nobfd-decommented.ver'"
+elif test -z "$no_version_script"; then
+   VERSION_FLAGS="$ac_cv_libctf_version_script='$srcdir/libctf.ver'"
+   VERSION_FLAGS_NOBFD="$ac_cv_libctf_version_script='libctf-nobfd.ver'"
 else
    VERSION_FLAGS="$ac_cv_libctf_version_script"
    VERSION_FLAGS_NOBFD="$ac_cv_libctf_version_script"

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-19 15:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-19 15:52 [binutils-gdb] libctf: do not include undefined functions in libctf.ver Nick Alcock

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).