From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17100 invoked by alias); 15 May 2011 10:14:38 -0000 Received: (qmail 17090 invoked by uid 22791); 15 May 2011 10:14:37 -0000 X-SWARE-Spam-Status: No, hits=1.5 required=5.0 tests=AWL,BAYES_40,TVD_RCVD_IP X-Spam-Check-By: sourceware.org Received: from 123-243-254-105.static.tpgi.com.au (HELO racky.postincrement.net) (123.243.254.105) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 15 May 2011 10:14:23 +0000 Received: from Seawolf.local ([10.0.2.200]) (authenticated bits=0) by racky.postincrement.net (8.14.4/8.14.3) with ESMTP id p4FAEJpt020832 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Sun, 15 May 2011 20:14:19 +1000 Message-ID: <4DCFA77B.9060300@postincrement.com> Date: Sun, 15 May 2011 10:14:00 -0000 From: Craig Southeren User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 To: binutils@sourceware.org Subject: Re: PATCH: PR ld/12730: regression] crash when allocating in a static constructor Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-IsSubscribed: yes Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2011-05/txt/msg00197.txt.bz2 ------------------------------------------------------------------------ > On Mon, May 9, 2011 at 6:53 AM, Alan Modra wrote: > > I'm starting to wonder whether ld/testsuite/ld-elf/pr12730.cc is > > valid. ?Does gcc actually make any guarantee about order of static > > constructors and __attribute ((constructor)) functions? > > I have similar doubt. > > > Compiled with gcc-4.3 branch g++, the testcase segfaults at all > > optimization levels. ?Compiled with gcc-4.4 branch g++, the testcase > > runs at -O0 but segfaults at -O1 and above. ?It happens to run OK with > > gcc mainline and 4.6. ?Given that behaviour, and the fact that some > > popular distros ship gcc-4.4 based compilers, I'm thinking that the > > testcase should be removed. > > > > I will do that. > At the heart of the issue is the timing of initialising statics at the global/namespace level. Prior to the recent change, these statics were initialised the first time that any code from the enclosing translation unit was executed. Now, it appears that all such statics in all translation units are instantiated at start-up. As the order of statics the global/namespace level is not strictly defined, the new implementation is probably compliant. However, this choice means that global/namespace statics do not have the same kind of behaviour as member statics. Member statics are only initialised if the program control flow passes their declaration. If the control flow never executes the declaration, then the static is never instantiated. Previously, global/namespace statics had similar behaviour - they were only initialised if code in the enclosing translation unit was executed. This is no longer the case. Global/namespace statics now appear to be instantiated regardless of whether code in the enclosing translation unit is used. This may increase the memory footprint for applications that have global/namespace statics in translation units containing code that may be conditionally executed. In some cases (such as PTLib) this may lead to different behaviour. In the case of PTLib (disclaimer: I am the co-author and co-maintainer) we can work around this issue using the "initialise on first use" paradigm. But it may be that other application maintainers will not be so fortunate to have the zealous co-maintainers that tracked down this issue for us. Of course, I expect that most application won't notice the difference, other than perhaps some slight increase in runtime memory usage, Craig -- ----------------------------------------------------------------------- Craig Southeren Post Increment ñ VoIP Consulting and Software craigs@postincrement.com.au www.postincrement.com.au Phone: +61 243654666 ICQ: #86852844 Fax: +61 243656905 MSN:craig_southeren@hotmail.com Mobile: +61 417231046 Jabber:craigs@jabber.org "Science is the poetry of reality." Richard Dawkins