From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25349 invoked by alias); 12 Apr 2003 16:52:29 -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 25341 invoked from network); 12 Apr 2003 16:52:28 -0000 Received: from unknown (63.201.54.26) by sources.redhat.com with QMTP; 12 Apr 2003 16:52:28 -0000 Received: (qmail 23855 invoked by uid 10); 12 Apr 2003 16:52:27 -0000 Received: (qmail 7831 invoked by uid 500); 12 Apr 2003 16:52:23 -0000 Mail-Followup-To: binutils@sources.redhat.com, black@ieee.org To: Hal Black Cc: binutils 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> From: Ian Lance Taylor Date: Sat, 12 Apr 2003 16:52:00 -0000 In-Reply-To: <3E98219D.7010506@ieee.org> 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/msg00284.txt.bz2 Hal Black writes: > What I'm saying is not to use all the symbols, but to include all > static initializers as "symbols that are being looked for". Even if > they aren't explicitly referenced by annother piece of code, they are > implicitly referenced by virtue of being static initializers. That would mean that every static initializer in a .a file would be brought in, which would doubtless bring in other object files as well. It means that including any class with a static initializer in a .a file would mean that that class would be included in all programs linked with that .a file. This would go against the very idea of a .a file, which is that only required objects are included. > I would say that not looking for static initializers constitutes > eliminating them... No, because they were never included in the first place. It's reasonably easy to avoid this problem: put the static initializer in the same source file as a class virtual function. Since the class virtual function must be included, the initializer will be brought in as well. If you don't have any virtual functions, then you do need to take some other action to force that object file to be included, such as using global variables in some way. Or maybe .a files are simply the wrong tool for the job. Maybe you should use ld -r to form several .o files into one large .o file. Linking against that will ensure that everything is brought in. Ian