public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Nick Alcock <nick.alcock@oracle.com>
To: binutils@sourceware.org
Subject: [PATCH 3/4] libctf: try several possibilities for linker versioning flags
Date: Fri, 25 Jun 2021 17:13:34 +0100	[thread overview]
Message-ID: <20210625161335.4831-4-nick.alcock@oracle.com> (raw)
In-Reply-To: <20210625161335.4831-1-nick.alcock@oracle.com>

Checking for linker versioning by just grepping ld --help output for
mentions of --version-script is inadequate now that Solaris 11.4
implements a --version-script with different semantics.  Try linking a
test program with a small wildcard-using version script with each
supported set of flags in turn, to make sure that linker versioning is
not only advertised but actually works.

The Solaris "GNU-compatible" linker versioning is not quite
GNU-compatible enough, but we can work around the differences by
generating a new version script that removes the comments from the
original (Solaris ld requires #-style comments), and making another
version script for libctf-nonbfd in particular which doesn't mention any
of the symbols that appear in libctf.la, to avoid Solaris ld introducing
corresponding new NOTYPE symbols to match the version script.

libctf/ChangeLog
2021-06-22  Nick Alcock  <nick.alcock@oracle.com>

	PR libctf/27482
	* configure.ac (VERSION_FLAGS): Replace with...
	(ac_cv_libctf_version_script): ... this multiple test.
	(VERSION_FLAGS_NOBFD): Substitute this too.
	* Makefile.am (libctf_nobfd_la_LDFLAGS): Use it.  Split out...
	(libctf_ldflags_nover): ... non-versioning flags here.
	(libctf_la_LDFLAGS): Use it.
	* libctf.ver: Give every symbol not in libctf-nobfd a comment on
	the same line noting as much.
---
 libctf/Makefile.am  |  5 +++--
 libctf/configure.ac | 46 ++++++++++++++++++++++++++++++++++++++++++---
 libctf/libctf.ver   | 10 ++++------
 3 files changed, 50 insertions(+), 11 deletions(-)

diff --git a/libctf/Makefile.am b/libctf/Makefile.am
index 308daa9a03c..38d86bc4f9d 100644
--- a/libctf/Makefile.am
+++ b/libctf/Makefile.am
@@ -42,7 +42,8 @@ noinst_LTLIBRARIES = libctf.la libctf-nobfd.la
 endif
 
 libctf_nobfd_la_LIBADD = @CTF_LIBADD@ $(ZLIB)
-libctf_nobfd_la_LDFLAGS = -version-info 0:0:0 @SHARED_LDFLAGS@ @VERSION_FLAGS@
+libctf_ldflags_nover = -version-info 0:0:0 @SHARED_LDFLAGS@
+libctf_nobfd_la_LDFLAGS = $(libctf_ldflags_nover) @VERSION_FLAGS_NOBFD@
 libctf_nobfd_la_CPPFLAGS = $(AM_CPPFLAGS) -DNOBFD=1
 libctf_nobfd_la_SOURCES = ctf-archive.c ctf-dump.c ctf-create.c ctf-decl.c ctf-error.c \
 			  ctf-hash.c ctf-labels.c ctf-dedup.c ctf-link.c ctf-lookup.c \
@@ -58,7 +59,7 @@ endif
 # references in there get picked up.
 libctf_la_LIBADD =  @CTF_LIBADD@ ../bfd/libbfd.la $(libctf_nobfd_la_LIBADD)
 libctf_la_CPPFLAGS = $(AM_CPPFLAGS) -DNOBFD=0
-libctf_la_LDFLAGS = $(libctf_nobfd_la_LDFLAGS)
+libctf_la_LDFLAGS = $(libctf_ldflags_nover) @VERSION_FLAGS@
 libctf_la_SOURCES = $(libctf_nobfd_la_SOURCES) ctf-open-bfd.c
 
 # Setup the testing framework, if you have one
diff --git a/libctf/configure.ac b/libctf/configure.ac
index 80644b89d67..4e12a4fa8f6 100644
--- a/libctf/configure.ac
+++ b/libctf/configure.ac
@@ -219,11 +219,51 @@ fi`
 AM_CONDITIONAL(TCL_TRY, test "${ac_cv_libctf_tcl_try}" = yes)
 
 # Use a version script, if possible, or an -export-symbols-regex otherwise.
-VERSION_FLAGS='-export-symbols-regex ctf_.*'
-if $LD --help 2>&1 | grep -- --version-script >/dev/null; then
-    VERSION_FLAGS="-Wl,--version-script='$srcdir/libctf.ver'"
+decommented_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"
+   old_CFLAGS="$CFLAGS"
+   LDFLAGS="$LDFLAGS -shared -Wl,--version-script=conftest.ver"
+   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'"],
+		  [])
+   LDFLAGS="$old_LDFLAGS"
+
+   if test -z "$ac_cv_libctf_version_script"; then
+     LDFLAGS="$LDFLAGS -shared -Wl,-B,local -Wl,-z,gnu-version-script=conftest.ver"
+     AC_LINK_IFELSE([AC_LANG_SOURCE([[int ctf_foo (void) { return 0; }
+				      int main (void) { return ctf_foo(); }]])],
+		    [ac_cv_libctf_version_script="-Wl,-B,local -Wl,-z,gnu-version-script"
+		     decommented_version_script=t],
+		    [])
+     LDFLAGS="$old_LDFLAGS"
+   fi
+   CFLAGS="$old_CFLAGS"
+
+   if test -z "$ac_cv_libctf_version_script"; then
+     ac_cv_libctf_version_script='-export-symbols-regex ctf_.*'
+   fi
+   rm -f conftest.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
+   VERSION_FLAGS="$ac_cv_libctf_version_script='libctf-decommented.ver'"
+   VERSION_FLAGS_NOBFD="$ac_cv_libctf_version_script='libctf-nobfd-decommented.ver'"
+else
+   VERSION_FLAGS="$ac_cv_libctf_version_script"
+   VERSION_FLAGS_NOBFD="$ac_cv_libctf_version_script"
 fi
 AC_SUBST(VERSION_FLAGS)
+AC_SUBST(VERSION_FLAGS_NOBFD)
 
 AC_CONFIG_FILES(Makefile)
 AC_CONFIG_HEADERS(config.h)
diff --git a/libctf/libctf.ver b/libctf/libctf.ver
index 0b182f37228..602c13fba17 100644
--- a/libctf/libctf.ver
+++ b/libctf/libctf.ver
@@ -165,12 +165,10 @@ LIBCTF_1.0 {
 	ctf_link_shuffle_syms;
 	ctf_link_write;
 
-	/* In libctf alone.  */
-
-	ctf_fdopen;
-	ctf_open;
-	ctf_bfdopen;
-	ctf_bfdopen_ctfsect;
+	ctf_fdopen;                             /* libctf only.  */
+	ctf_open;                               /* libctf only.  */
+	ctf_bfdopen;                            /* libctf only.  */
+	ctf_bfdopen_ctfsect;                    /* libctf only.  */
     local:
 	*;
 };
-- 
2.32.0.255.gd9b1d14a2a


  parent reply	other threads:[~2021-06-25 16:13 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-25 16:13 [PATCH 0/4 REVIEW] libtool and libctf fixes for Solaris 11 Nick Alcock
2021-06-25 16:13 ` [PATCH 1/4] libtool.m4: augment symcode " Nick Alcock
2021-06-25 16:13 ` [PATCH 2/4 REVIEW] libtool.m4: fix nm BSD flag detection Nick Alcock
2021-07-06 19:37   ` Nick Alcock
2021-07-07 14:39     ` Nick Clifton
2021-07-07 19:03       ` Nick Alcock
2021-07-21  8:22         ` Alan Modra
2021-09-09 12:39           ` Nick Alcock
2021-06-25 16:13 ` Nick Alcock [this message]
2021-06-25 16:13 ` [PATCH 4/4] configure: regenerate in all projects that use libtool.m4 Nick Alcock

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210625161335.4831-4-nick.alcock@oracle.com \
    --to=nick.alcock@oracle.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).