public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Nick Alcock <nick.alcock@oracle.com>
To: binutils@sourceware.org
Subject: [PATCH 1/3] libctf: link against libiberty before linking in libbfd or libctf-nobfd
Date: Fri, 25 Jun 2021 17:12:41 +0100	[thread overview]
Message-ID: <20210625161243.4747-2-nick.alcock@oracle.com> (raw)
In-Reply-To: <20210625161243.4747-1-nick.alcock@oracle.com>

This ensures that the CTF_LIBADD, which always contains at least this
when doing a shared link:

-L`pwd`/../libiberty/pic -liberty

appears in the link line before any requirements pulled in by libbfd.la,
which include -liberty but because it is install-time do not include the
-L`pwd`/../libiberty/pic portion (in an indirect dep like this, the path
comes from the libbfd.la file, and is an install path).  libiberty also
appears after libbfd in the link line by virtue of libctf-nobfd.la,
because libctf-nobfd has to follow libbfd in the link line, and that
needs symbols from libiberty too.

Without this, an installed liberty might well be pulled in by libbfd,
and if --enable-install-libiberty is not specified this libiberty might
be completely incompatible with what is being installed and break either
or boht of libbfd and libctf. (The specific problem observed here is
that bsearch_r was not present, but other problems might easily be
observed in future too.)

Because ld links against libctf, this has a tendency to break the system
linker at install time too, if installing with --prefix=/usr.  That's
quite unpleasant to recover from.

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

	PR libctf/27360
	* Makefile.am (libctf_la_LIBADD): Link against libiberty
	before pulling in libbfd.la or pulling in libctf-nobfd.la.
	* Makefile.in: Regenerate.
---
 libctf/Makefile.am | 6 +++++-
 libctf/Makefile.in | 7 ++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/libctf/Makefile.am b/libctf/Makefile.am
index e586d25fb37..308daa9a03c 100644
--- a/libctf/Makefile.am
+++ b/libctf/Makefile.am
@@ -52,7 +52,11 @@ if NEED_CTF_QSORT_R
 libctf_nobfd_la_SOURCES += ctf-qsort_r.c
 endif
 
-libctf_la_LIBADD = ../bfd/libbfd.la $(libctf_nobfd_la_LIBADD)
+# @CTF_LIBADD@ appears here twice: once, to force libiberty to get searched before
+# install-time libbfd adds a -L to the install dir (possibly pointing at an
+# incompatible libiberty), and once via lictf_nobfd_la_LIBADD so that the
+# 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_SOURCES = $(libctf_nobfd_la_SOURCES) ctf-open-bfd.c
diff --git a/libctf/Makefile.in b/libctf/Makefile.in
index 5cfa100f9cc..b594a3e1362 100644
--- a/libctf/Makefile.in
+++ b/libctf/Makefile.in
@@ -476,7 +476,12 @@ 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 ctf-open.c ctf-serialize.c ctf-sha1.c \
 	ctf-string.c ctf-subr.c ctf-types.c ctf-util.c $(am__append_1)
-libctf_la_LIBADD = ../bfd/libbfd.la $(libctf_nobfd_la_LIBADD)
+
+# @CTF_LIBADD@ appears here twice: once, to force libiberty to get searched before
+# install-time libbfd adds a -L to the install dir (possibly pointing at an
+# incompatible libiberty), and once via lictf_nobfd_la_LIBADD so that the
+# 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_SOURCES = $(libctf_nobfd_la_SOURCES) ctf-open-bfd.c
-- 
2.32.0.255.gd9b1d14a2a


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

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-25 16:12 [PATCH 0/3] libctf: small fixes Nick Alcock
2021-06-25 16:12 ` Nick Alcock [this message]
2021-06-25 16:12 ` [PATCH 2/3] libctf: fix handling of CTF symtypetab sections emitted by older GCC Nick Alcock
2021-06-25 16:12 ` [PATCH 3/3] libctf, testsuite: fix various warnings in tests 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=20210625161243.4747-2-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).