From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28192 invoked by alias); 13 Apr 2003 23:15:53 -0000 Mailing-List: contact binutils-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sources.redhat.com Received: (qmail 28185 invoked from network); 13 Apr 2003 23:15:52 -0000 Received: from unknown (63.201.54.26) by sources.redhat.com with QMTP; 13 Apr 2003 23:15:52 -0000 Received: (qmail 30526 invoked by uid 10); 13 Apr 2003 23:15:52 -0000 Received: (qmail 21337 invoked by uid 500); 13 Apr 2003 23:15:47 -0000 Mail-Followup-To: binutils@sources.redhat.com, black@ieee.org, zack@codesourcery.com To: Zack Weinberg Cc: binutils@sources.redhat.com, black@ieee.org Subject: Re: [BUG] ld behavior varies for C++ static initializer depending on .a or .o input References: <3E9639F9.9050503@vt.edu> <3E978F84.4050603@vt.edu> <3E98219D.7010506@ieee.org> <3E98546A.9060507@ieee.org> <87he92ngiz.fsf@egil.codesourcery.com> From: Ian Lance Taylor Date: Sun, 13 Apr 2003 23:15:00 -0000 In-Reply-To: <87he92ngiz.fsf@egil.codesourcery.com> Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2003-04/txt/msg00298.txt.bz2 Zack Weinberg writes: > Ian Lance Taylor writes: > > > Hal Black writes: > >> Yes. That's the desired behavior. If a developer were to develop a > >> library with a static initializer with side-effects, it would be > >> something that should be called whenever that library was used. > > > > No Unix linker has ever worked that way. > > > > Basically, you misunderstand how ld and ar work. If you feel that you > > have been misled by existing documentation, please let us know so that > > we can fix it. > > I'd like to point out that while this is true for static (.a) > libraries, it is not true for shared (.so) libraries -- the linker > generates DT_NEEDED entries for every shared library on the command > line, whether or not they satisfy undefined symbols. Personally I > consider this a bug. I think that one is debatable. It's certainly true that shared libraries and archive libraries don't work the same way; as you say, one obvious difference is in fact the very one we are talking about--all static initializers in a shared library are run, whether they are required or not. There are a number of other differences--only in simple case can you just replace a .a file with a .so file. I think the general attitude of linker implementors has been that if you list a shared library on the command line, you must want it in there. That is, a .so file is in that sense more like a .o file than a .a file. But I agree that it could be argued the other way. I don't know of any ELF linker which does not generate a DT_NEEDED for a .so listed on the command line, but perhaps there is one. Ian