public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* --gc-sections on x86
@ 2006-12-05  9:28 Gabriel Linder
  2006-12-05  9:57 ` Brian Dessent
  2006-12-05 13:04 ` John Love-Jensen
  0 siblings, 2 replies; 5+ messages in thread
From: Gabriel Linder @ 2006-12-05  9:28 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 558 bytes --]

Hi list,

I am trying to remove some unused functions from our programs, with gcc 
flag -ffunction-sections and ld flag --gc-sections, but it doesn't seem 
to work at all :-(

I use gcc 3.2.2, and I get the following (sample source attached, 18 
lines) :
2828 bytes with gcc -march=i686 -O2 -ffunction-sections 
-Wl,--gc-sections oblivion.c -o oblivion && strip -s oblivion
2812 bytes with gcc -DNOTHING -march=i686 -O2 -ffunction-sections 
-Wl,--gc-sections oblivion.c -o oblivion && strip -s oblivion

Is this a known problem ? Is a workaround available ?

[-- Attachment #2: oblivion.c --]
[-- Type: text/plain, Size: 234 bytes --]

#include <stdio.h>

#ifndef NOTHING
int nothing(int n) // unused function, should not be in binary !
{
	return n;
}
#endif

int hello(void) // used function
{
	return printf("I do nothing !\n");
}

int main(void)
{
	return hello();
}

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

* Re: --gc-sections on x86
  2006-12-05  9:28 --gc-sections on x86 Gabriel Linder
@ 2006-12-05  9:57 ` Brian Dessent
  2006-12-05 10:13   ` Gabriel Linder
  2006-12-05 13:04 ` John Love-Jensen
  1 sibling, 1 reply; 5+ messages in thread
From: Brian Dessent @ 2006-12-05  9:57 UTC (permalink / raw)
  To: gcc-help

Gabriel Linder wrote:

> I am trying to remove some unused functions from our programs, with gcc
> flag -ffunction-sections and ld flag --gc-sections, but it doesn't seem
> to work at all :-(
> 
> I use gcc 3.2.2, and I get the following (sample source attached, 18
> lines) :
> 2828 bytes with gcc -march=i686 -O2 -ffunction-sections
> -Wl,--gc-sections oblivion.c -o oblivion && strip -s oblivion
> 2812 bytes with gcc -DNOTHING -march=i686 -O2 -ffunction-sections
> -Wl,--gc-sections oblivion.c -o oblivion && strip -s oblivion
> 
> Is this a known problem ? Is a workaround available ?

This testcase may not be actually showing you what you want.  You have
to balance the extra overhead of having a section for each function
against the savings, and in this case the function being removed is
completely trivial.  When you're looking at a 2800 byte ELF file the
noise (headers, padding, etc) is going to overwhelm everything.  Try a
more realistic testcase.

Brian

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

* Re: --gc-sections on x86
  2006-12-05  9:57 ` Brian Dessent
@ 2006-12-05 10:13   ` Gabriel Linder
  2006-12-05 14:27     ` Perry Smith
  0 siblings, 1 reply; 5+ messages in thread
From: Gabriel Linder @ 2006-12-05 10:13 UTC (permalink / raw)
  To: gcc-help

Brian Dessent wrote:
> This testcase may not be actually showing you what you want.  You have
> to balance the extra overhead of having a section for each function
> against the savings, and in this case the function being removed is
> completely trivial.  When you're looking at a 2800 byte ELF file the
> noise (headers, padding, etc) is going to overwhelm everything.  Try a
> more realistic testcase.
Well, that was a trivial testcase, as you said. In real life I have a 
lot of .c files with generic functions, but not all of them are used by 
all binaries I build. So I search for a way to clean out unused 
functions between modules, if possible.

The --gc-sections trick was found after some search, I found also a "set 
inline function size to 0 and enable inlining" hint (on RedHat lists, if 
I remember correctly) but none of them works.

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

* Re: --gc-sections on x86
  2006-12-05  9:28 --gc-sections on x86 Gabriel Linder
  2006-12-05  9:57 ` Brian Dessent
@ 2006-12-05 13:04 ` John Love-Jensen
  1 sibling, 0 replies; 5+ messages in thread
From: John Love-Jensen @ 2006-12-05 13:04 UTC (permalink / raw)
  To: Gabriel Linder, MSX to GCC

Hi Gabriel,

Don't go by size, especially for such a trivial test case.

Use the nm command to confirm that the nothing() routine is no longer in
your first test case.

HTH,
--Eljay

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

* Re: --gc-sections on x86
  2006-12-05 10:13   ` Gabriel Linder
@ 2006-12-05 14:27     ` Perry Smith
  0 siblings, 0 replies; 5+ messages in thread
From: Perry Smith @ 2006-12-05 14:27 UTC (permalink / raw)
  To: Gabriel Linder; +Cc: gcc-help

On Dec 5, 2006, at 4:13 AM, Gabriel Linder wrote:

> Brian Dessent wrote:
>> This testcase may not be actually showing you what you want.  You  
>> have
>> to balance the extra overhead of having a section for each function
>> against the savings, and in this case the function being removed is
>> completely trivial.  When you're looking at a 2800 byte ELF file the
>> noise (headers, padding, etc) is going to overwhelm everything.   
>> Try a
>> more realistic testcase.
> Well, that was a trivial testcase, as you said. In real life I have  
> a lot of .c files with generic functions, but not all of them are  
> used by all binaries I build. So I search for a way to clean out  
> unused functions between modules, if possible.
>
> The --gc-sections trick was found after some search, I found also a  
> "set inline function size to 0 and enable inlining" hint (on RedHat  
> lists, if I remember correctly) but none of them works.

It seems like if you had to, you could analyze the output of nm of  
the object files -- maybe even the final compiled program.  nm will  
tell you where symbols are defined and reference.

Perry Smith ( pedz@easesoftware.com )
Ease Software, Inc. ( http://www.easesoftware.com )

Low cost SATA Disk Systems for IBMs p5, pSeries, and RS/6000 AIX systems


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

end of thread, other threads:[~2006-12-05 14:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-12-05  9:28 --gc-sections on x86 Gabriel Linder
2006-12-05  9:57 ` Brian Dessent
2006-12-05 10:13   ` Gabriel Linder
2006-12-05 14:27     ` Perry Smith
2006-12-05 13:04 ` John Love-Jensen

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).