From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6213 invoked by alias); 12 Jan 2005 17:35:07 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 6149 invoked from network); 12 Jan 2005 17:34:54 -0000 Received: from unknown (HELO marvin.codito.net) (203.197.88.2) by sourceware.org with SMTP; 12 Jan 2005 17:34:54 -0000 Received: from webmail.codito.com (localhost [127.0.0.1]) by marvin.codito.net (8.13.2/8.13.2/Debian-1) with ESMTP id j0CHroNO022956; Wed, 12 Jan 2005 23:23:50 +0530 Received: from 203.212.198.180 (SquirrelMail authenticated user ramana.radhakrishnan); by webmail.codito.com with HTTP; Wed, 12 Jan 2005 23:23:54 +0530 (IST) Message-ID: <33987.203.212.198.180.1105552434.squirrel@webmail.codito.com> In-Reply-To: <8FACC07CE2E5774FB9B14B643263BA13EABBD9@DEDUS-WICL02M01.vf-de.internal .vodafone.com> References: <8FACC07CE2E5774FB9B14B643263BA13EABBD9@DEDUS-WICL02M01.vf-de.internal.vodafone.com> Date: Wed, 12 Jan 2005 17:35:00 -0000 Subject: RE: Optimization - removing unused code From: "Ramana Radhakrishnan" To: "Madani, Srikanth, VF-DE" Cc: gcc-help@gcc.gnu.org, "Eljay Love-Jensen" , "Graham Stott" , "Sriharsha" , "Labermeier Norbert" Reply-To: ramana.radhakrishnan@codito.com User-Agent: SquirrelMail/1.4.3a MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-SW-Source: 2005-01/txt/msg00101.txt.bz2 Hi, Yeah I can imagine why it would be hard to do --gc-sections for dynamically linked executables . You would have to worry about the semantics of weak symbol definitions , weak function definitions to worry about. Other than that I can't think of any other issues off the cuff. It looks as though no one has done it yet and possibly would be a nifty feature to have, though using google I could only find this thread as a reference : http://sources.redhat.com/ml/binutils/2001-11/msg00339.html and more specifically this reply : http://sources.redhat.com/ml/binutils/2001-11/msg00350.html In any case maybe future discussions about this should possibly move to binutils@sources.redhat.com and maybe no longer here. cheers Ramana --- Ramana Radhakrishnan GNU Tools Support codito ergo sum (www.codito.com) > Following up the thread titled "RE: ld warning (was Optimization, remove > unused code from Image)": > >> Will retry on a Linux machine where everything is GNU, and see if I have >> better results there. > > #Compilation : gcc version 3.3.1 (SuSE Linux) > $> gcc -c -ffunction-sections *.c > > #Linking : GNU ld version 2.14.90.0.5 20030722 (SuSE Linux) > $> gcc -Wl,--gc-sections *.o > > $> file a.out > a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for > GNU/Linux 2.2.5, dynamically linked (uses shared libs), not stripped > > a.out works fine, but contains the uncalled function func3() in the code > section. > > If I link it statically, however: > $> gcc -Wl,--gc-sections,-static *.o > > $> file a.out > a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), > statically linked, not stripped > > > And a.out doesn't contain func3(). AND, it doesn't contain func2() either. > > So, unused code has been removed - but only (as man ld stipulates) if you > link statically. > > Cheers, > Srikanth Madani > Düsseldorf, NRW > > > > > ________________________________________________________________ > The source files are: > > $> cat hello.c > int main(void) { > printf("\nHello world!\n"); > func1(); > exit(0); > } > $> > > > $> cat fun1.c > void func1(void) { > printf("\nIn function func1()\n"); > } > void func2(void) { > func3(); > } > $> > > > $> cat fun2.c > void func3(void) { > printf("\nIn function func3()\n"); > } > $> > ---- Ramana Radhakrishnan Codito Technologies