* 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
* RE: Optimization - removing unused code
[not found] ` <8FACC07CE2E5774FB9B14B643263BA13EABBD9@DEDUS-WICL02M01.vf-de.internal .vodafone.com>
@ 2005-01-12 17:35 ` Ramana Radhakrishnan
0 siblings, 0 replies; 2+ messages in thread
From: Ramana Radhakrishnan @ 2005-01-12 17:35 UTC (permalink / raw)
To: Madani, Srikanth, VF-DE
Cc: gcc-help, Eljay Love-Jensen, Graham Stott, Sriharsha, Labermeier Norbert
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
^ 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).