avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-gcc-list] how to remove unused code?


From: Weddington, Eric
Subject: RE: [avr-gcc-list] how to remove unused code?
Date: Mon, 18 Feb 2008 10:05:07 -0700

 

> -----Original Message-----
> From: 
> address@hidden 
> [mailto:address@hidden
> org] On Behalf Of Joerg Desch
> Sent: Monday, February 18, 2008 7:25 AM
> To: address@hidden
> Subject: [avr-gcc-list] how to remove unused code?
> 
> I'm trying to use the OSS library "libvisca" for controlling 
> a SONY camera. The port seems to compile, but the resulting 
> binary is ways to large. I only need some of the functions, 
> but the linker don't remove the unused stuff.
> 
> Isn't the linker smart enough for that?
> 
> libvisca comes as one big C file. Is this the problem?

Yes. Because then it is not truly a "library" per the definition.
 
> I'm using the WinAVR Makefile Template...
> 


You can enable the toolchain to remove unused code by adding these
flags:

CFLAGS += -ffunction-sections

This tells the compiler to put each function in its own section. This
must be used for all *compile* command lines, hence added to the CFLAGS
variable.

LDFLAGS += -Wl,-gc-sections

This tells GCC to send the -gc-sections flag to the linker (via -Wl).
The -gc-sections flag tells the linker to "garbage collect" (remove)
unused sections. Since all functions are now in their own individual
section, this has the effect of removing unused functions. This flag is
a linker flag, so it is set in the LDFLAGS variable.

HTH,
Eric Weddington




reply via email to

[Prev in Thread] Current Thread [Next in Thread]