public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: binutils@sources.redhat.com
Subject: Re: [PATCH] Fix DT_NEEDED search with --as-needed libraries (PR ld/2721)
Date: Fri, 02 Jun 2006 09:03:00 -0000	[thread overview]
Message-ID: <20060602084938.GE3823@sunsite.mff.cuni.cz> (raw)
In-Reply-To: <20060602051344.GC26009@bubble.grove.modra.org>

On Fri, Jun 02, 2006 at 02:43:44PM +0930, Alan Modra wrote:
> On Thu, Jun 01, 2006 at 05:09:07PM +0200, Jakub Jelinek wrote:
> > If some --as-needed library mentioned on the command line isn't directly
> > needed by executable being linked, but it is mentioned in DT_NEEDED of some
> > needed library, then without this patch ld will disregard the library
> > mentioned on the command line and look for a different one (e.g. in system
> > paths).
> 
> According to the current specification of --as-needed, isn't that
> exactly what ld should do?  --as-needed is supposed to cause ld to only
> link a lib if it satisfies some reference from a regular object
> (ie. non-dynamic) at that point in the link process.  This patch makes
> --as-needed have another meaning entirely.
> 
> I'm willing to consider a behaviour change for --as-needed, eg. that
> references from other dynamic libs cause a lib to be linked, but this
> particular change seems a little odd.  Why should a library that you
> decide isn't needed be considered again, unless it is also found by the
> normal search mechanism?

Because without it --as-needed isn't really usable with libtool,
unless libtool is changed to pass -Wl,--rpath-link with every single library
it adds (and even in that case it might do unexpected things if there are
multiple libraries in the same directory).
The testcase in the PR is a simplified version of
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=193689
which is I think quite commonly used scenario.  A project that builds
2 or more shared libraries in the build process, where the second of these
depends on the first one, and then build a binary that depends on the second
of the shared library (but doesn't have direct dependencies on the first).
The first library is actually needed by the program, as it is a dependency
of the second, but as it is not a direct dependency, it is not needed
in DT_NEEDED of the program.
The --as-needed documentation doesn't talk about linking/not linking some
library, it solely talks about DT_NEEDED:
`--as-needed'
`--no-as-needed'
     This option affects ELF DT_NEEDED tags for dynamic libraries
     mentioned on the command line after the `--as-needed' option.
     Normally, the linker will add a DT_NEEDED tag for each dynamic
     library mentioned on the command line, regardless of whether the
     library is actually needed.  `--as-needed' causes DT_NEEDED tags
     to only be emitted for libraries that satisfy some symbol
     reference from regular objects which is undefined at the point
     that the library was linked.  `--no-as-needed' restores the
     default behaviour.
With the patch I posted, the first library won't be in binary's DT_NEEDED,
which matches the documentation, but there is no word about --as-needed
affecting anything else, particularly what libraries are searched when
trying to satisfy undefined references in shared libraries mentioned
in DT_NEEDED.

The second testcase in the PR is a regression from 2.16.90.x.y btw.

	Jakub

  reply	other threads:[~2006-06-02  8:49 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-01 15:26 Jakub Jelinek
2006-06-01 15:31 ` Jakub Jelinek
2006-06-01 18:23 ` H. J. Lu
2006-06-02  7:14 ` Alan Modra
2006-06-02  9:03   ` Jakub Jelinek [this message]
2006-06-02 13:55     ` Diego 'Flameeyes' Pettenò
2006-06-02 14:51     ` Alan Modra
2006-06-02 15:57       ` Jakub Jelinek
2006-06-02 16:43         ` Alan Modra
2006-06-04 14:42           ` Alan Modra
2006-06-07 15:16             ` Daniel Jacobowitz
2006-06-08  9:59               ` Alan Modra

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=20060602084938.GE3823@sunsite.mff.cuni.cz \
    --to=jakub@redhat.com \
    --cc=binutils@sources.redhat.com \
    /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).