From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26936 invoked by alias); 11 Apr 2003 03:43:57 -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 26924 invoked from network); 11 Apr 2003 03:43:57 -0000 Received: from unknown (HELO mail.hal.cx) (68.32.53.147) by sources.redhat.com with SMTP; 11 Apr 2003 03:43:57 -0000 Received: from vt.edu (unknown [192.168.0.108]) by mail.hal.cx (Postfix) with ESMTP id 2BBE62EE12 for ; Thu, 10 Apr 2003 23:43:53 -0400 (EDT) Message-ID: <3E9639F9.9050503@vt.edu> Date: Fri, 11 Apr 2003 03:43:00 -0000 From: Hal Black User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4a) Gecko/20030328 X-Accept-Language: en,pdf,ja MIME-Version: 1.0 To: binutils@sources.redhat.com Subject: [BUG] ld behavior varies for C++ static initializer depending on .a or .o input Content-Type: multipart/mixed; boundary="------------060001090500040002020209" X-SW-Source: 2003-04/txt/msg00262.txt.bz2 This is a multi-part message in MIME format. --------------060001090500040002020209 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1442 Using GNU ld version 2.13.90.0.18 20030206 (comes with Redhat 9) Also experienced with previous 3.x and 2.9x versions. When linking with a bunch of .o files, the desired behavior (static initializers are called) happens. But when linking .a files composed of those .o files, static initializers are not called. On the other hand, when the .cpp files are combined to make a single .o file, which is then used to form a .a file, that works. This was previously reported to gcc bugs, but they sent me here (I've been lurking for quite a while to see if it was okay to post bugs here): http://gcc.gnu.org/cgi-bin/gnatsweb.pl (bug 7769) There is some good discussion there. Full source code and makefile follows in the attachment. See below for a quick glance of what I'm talking about. one.cc ------ #include class A { public: A() { printf("Hello world!\n"); } }; A a; ------ two.cc ------ int main() {} ------ combined.cc ----------- #include "one.cc" #include "two.cc" ----------- Makefile -------- CPP=g++ test:main1 main2 main3 main4 ./main1 ./main2 ./main3 ./main4 %.o:%.cc $(CPP) -c $< lib%.a:%.o ar rv $@ $< both.a:one.o two.o ar rv $@ $^ main1:one.o two.o $(CPP) one.o two.o -o main1 main2:libone.a libtwo.a $(CPP) libone.a libtwo.a -o main2 main3:both.a $(CPP) both.a -o main3 main4:libcombined.a $(CPP) libcombined.a -o main4 clean: rm -f *.a *.o main* -------- thanks for your time. Hal --------------060001090500040002020209 Content-Type: application/octet-stream; name="static_init.tar.bz2" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="static_init.tar.bz2" Content-length: 753 QlpoOTFBWSZTWVpn72EAAhp/08awACB+e/+faGdEBf/v34oBAAAEQAAAAIAI QAH8o6FBCmUzSPUxGnpNNNAGRkaGgZDIAAHMARgmIBgEwTRkNDAJgjEw0mhN E0BoNNAAAAAAAAAkkTQBqEan6I1PJqeRlGhp5J6mRoeU2iek2p+Eduxi3AHt q4zIYczMhDTpIFixY5xwhwT9DOhJ0Pc67OI5UMIChFKFi93DDybFtjG5n6YD aaJqtESk1nOf1iqVhBAh1ELYZWvIEmbydHCicQo94zCmHgwoSQgkt+8PCiQ5 tvKeWq09cbfJD0fzMQ5rKNaP0iozyUmXxcKwN96/pZ78h9nvfJIzmHMQen41 3gxQGPJ1pLMkmEbnhu2ttlRKI1NKwPR2SaxGmrCnzBBzp+5wMTrSCDGKMjNC 3EhQCzUpsjJK1NAOGkmMDTZsCBLNNc2UMIog5SlKe1UKYUs0rnhMSThI+UQ8 WirB8a56r9EDV15y9nyPNEmXpR8OrnO9ikX7E7wqwIejMkV6xBuuiNFqLx4O R5KZcHGqm15ENzDhRFIZV2ltlxVqL+xTJOZf3fCLT73Ky1HiikCRHdmEG9Xl 5kKu554gwiD6nzfggQgnZUdom1iBDG0pBmYNBoO8Xh0QVsnpMItRhBlX6BIy fYrhX1RIzQTo2JekcsDdDlyo44W9ePDntRSCuPiq0XS/furkwLijEZUoB5tZ nEB/xdyRThQkFpn72EA= --------------060001090500040002020209--