public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: Optimization -  removing unused code
@ 2005-01-12 16:49 Madani, Srikanth, VF-DE
       [not found] ` <8FACC07CE2E5774FB9B14B643263BA13EABBD9@DEDUS-WICL02M01.vf-de.internal .vodafone.com>
  0 siblings, 1 reply; 2+ messages in thread
From: Madani, Srikanth, VF-DE @ 2005-01-12 16:49 UTC (permalink / raw)
  To: gcc-help, Eljay Love-Jensen, Graham Stott, Sriharsha, gcc-help,
	Labermeier Norbert

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");
}
$>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-01-12 17:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-12 16:49 Optimization - removing unused code Madani, Srikanth, VF-DE
     [not found] ` <8FACC07CE2E5774FB9B14B643263BA13EABBD9@DEDUS-WICL02M01.vf-de.internal .vodafone.com>
2005-01-12 17:35   ` Ramana Radhakrishnan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).