From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16068 invoked by alias); 2 Jun 2006 08:49:46 -0000 Received: (qmail 16060 invoked by uid 22791); 2 Jun 2006 08:49:46 -0000 X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 02 Jun 2006 08:49:41 +0000 Received: from sunsite.mff.cuni.cz (sunsite.mff.cuni.cz [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.1/8.13.1) with ESMTP id k528ndWa006481 for ; Fri, 2 Jun 2006 10:49:39 +0200 Received: (from jj@localhost) by sunsite.mff.cuni.cz (8.13.1/8.13.1/Submit) id k528ndJ8006480 for binutils@sources.redhat.com; Fri, 2 Jun 2006 10:49:39 +0200 Date: Fri, 02 Jun 2006 09:03:00 -0000 From: Jakub Jelinek To: binutils@sources.redhat.com Subject: Re: [PATCH] Fix DT_NEEDED search with --as-needed libraries (PR ld/2721) Message-ID: <20060602084938.GE3823@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek References: <20060601150907.GD3823@sunsite.mff.cuni.cz> <20060602051344.GC26009@bubble.grove.modra.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060602051344.GC26009@bubble.grove.modra.org> User-Agent: Mutt/1.4.1i X-IsSubscribed: yes Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2006-06/txt/msg00021.txt.bz2 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