[Top][All Lists]

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

Re: [avr-gcc-list] AVR-GCC dead function elimination??

From: Christian Vogel
Subject: Re: [avr-gcc-list] AVR-GCC dead function elimination??
Date: Sun, 8 Jun 2003 11:46:54 +0200
User-agent: Mutt/

Hi David,

On Sun, Jun 08, 2003 at 03:31:33PM +1000, David Snowdon wrote:
> I had thought that GCC would simply remove functions which aren't used. 

The linker does try to resolve the symbols between the different object
files by using the references to external symbols in other object-files.
It does not care about the internal structure, so it only can work
on a file-by-file basis.

> Eric Waddington suggested (on an AVRFREAKS forum) that I should compile 
> each function into a different .o file, build a library using these 
> files, and then the linker would selectively include the .o files. 
> While it sounds like this would work, it seems like a bit of a hack!

No that's how it's supposed to be done. And it works. And you don't have
to split on single functions but can also split on "functional units"
which most likely will be used together anyway.

Try this: (did not use avr-gcc but normal intel-linux-gcc):

  func_a.c : int func_a(int a){ return 2*a; }
  func_b.c : int func_b(int a){ return 2*a; }
  func_c.c : int func_c(int a){ return 2*a; }
  main1.c : int main(){ return func_a(func_b(1)); }
  main2.c : int main(){ return func_b(func_c(1)); }

  gcc -g -c func_a.c (for every .c file)
  ar r libfunc.a func_*.o
  gcc -g -o main1 main1.o libfunc.a
  gcc -g -o main2 main2.o libfunc.a
  nm main1 | grep func_   --> only func_a, func_b included
  nm main2 | grep func_   --> only func_b, func_c included

"There are 10 different types of people in this world;
 Those who understand binary and those who don't".
  -- Seen on Usenet

reply via email to

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