From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15634 invoked by alias); 29 Sep 2009 14:28:25 -0000 Received: (qmail 15620 invoked by uid 22791); 29 Sep 2009 14:28:24 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org Received: from hagrid.ecoscentric.com (HELO mail.ecoscentric.com) (212.13.207.197) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 29 Sep 2009 14:28:18 +0000 Received: from localhost (hagrid.ecoscentric.com [127.0.0.1]) by mail.ecoscentric.com (Postfix) with ESMTP id 8C630151B5B2; Tue, 29 Sep 2009 15:28:16 +0100 (BST) Received: from mail.ecoscentric.com ([127.0.0.1]) by localhost (hagrid.ecoscentric.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Iu8W-mbV7Z1b; Tue, 29 Sep 2009 15:28:11 +0100 (BST) Date: Tue, 29 Sep 2009 14:28:00 -0000 Message-Id: From: Bart Veer To: Jonathan Larmour CC: ecos-discuss@sourceware.org In-reply-to: <4AAAF97F.5090705@jifvik.org> (message from Jonathan Larmour on Sat, 12 Sep 2009 02:29:35 +0100) References: <4A97F60C.2030208@dallaway.org.uk> <4A9CDD08.7090408@cetoni.de> <4A9D2171.30108@dallaway.org.uk> <4AA6749E.8040908@cetoni.de> <4AA67F59.8010204@dallaway.org.uk> <4AA75263.5040409@cetoni.de> <4AA797AF.3020201@dallaway.org.uk> <4AA8491F.3040408@jifvik.org> <4AAAF97F.5090705@jifvik.org> Mailing-List: contact ecos-discuss-help@ecos.sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: ecos-discuss-owner@ecos.sourceware.org Subject: Re: [ECOS] Re: uSTL hello world X-SW-Source: 2009-09/txt/msg00258.txt.bz2 >>>>> "Jifl" == Jonathan Larmour writes: Jifl> Unfortunately we have another problem. I've looked at the Jifl> output of our recent compilers, and I see that Jifl> CYG_REFERENCE_OBJECT no longer appears to be effective :-(. Jifl> The reference gets removed by more aggressive compiler Jifl> optimisation at -O2. This is a much wider problem than just Jifl> stdin/out/err of course. Jifl> Solving that efficiently may be difficult (although I don't Jifl> consider the current implementation to necessarily be Jifl> efficient either, when it worked, anyway). Managing to get Jifl> the reference into .text/.rodata would probably be better Jifl> than .data/.bss. Even better would be if it were possible to Jifl> play tricks to get it into a non-loadable section, although Jifl> that starts to venture into the world of HAL-specific stuff. Jifl> I see a .comment section though. Something along those lines Jifl> might work (and by overridable by specific HALs if needed). Jifl> But I've experimented (admittedly briefly) and not got as Jifl> far as even making the reference. I've tried using various Jifl> attributes, nested functions, volatiles, embedding Jifl> asm(".word " #__object__ ";"), etc. It may be that we can Jifl> only do this properly using HAL-specific inline asm :-(. The Jifl> least worst idea I've had which actually creates a reference Jifl> is to have a real function cyg_reference_object(void*) and Jifl> call it with the address of the object to reference, but Jifl> which returns immediately. Jifl> Any other ideas? At least there are not many uses of Jifl> CYG_REFERENCE_OBJECT. I think the following may do the trick: ---------------------------------------------------------------------------- // The unused attribute stops the compiler warning about the variable // not being used. // The used attribute prevents the compiler from optimizing it away. #define NEW_CYG_REFERENCE_OBJECT(__object__) \ CYG_MACRO_START \ static const void* __cygvar_discard_me__ \ __attribute__ ((unused, used)) = (const void*)&(__object__); \ CYG_MACRO_END ---------------------------------------------------------------------------- I have tried it in a simple testcase at -O2. The compiler does not optimize away __cygvar_discard_me__ because the used attribute prevents that. Hence the referenced object gets pulled in during the link. Subsequently linker garbage collection eliminates __cygvar_discard_me__. If the referenced object is a C++ object then it will be preserved because of the KEEP(*.ctors) in the linker script. So, even though it seems peculiar to have a variable both used and unused, that combo appears to do what we want and should be fully portable. Looking at the gcc ChangeLog-2001, attribute(used) was added on 2001-10-18 so has probably been available since gcc 3.1 days. However there is a comment in cyg_type.h associated with CYGBLD_ATTRIB_USED claiming >= 3.3.2. Let me know if it still does not solve the problem in al cases, and I can investigate further. Bart -- Bart Veer eCos Configuration Architect eCosCentric Limited The eCos experts http://www.ecoscentric.com/ Barnwell House, Barnwell Drive, Cambridge, UK. Tel: +44 1223 245571 Registered in England and Wales: Reg No 4422071. >>>> Visit us at ESC-UK http://www.embedded.co.uk <<<< >>>> Oct 7-8 on Stand 433 at FIVE ISC, Farnborough <<<< -- Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss