omitting unused functions

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I made a timer0_pwm library for atmega16 that has these functions:

void PWM0_init();
void PWM0_start(uint16 freq); // the frequency here because the timer start running by putting the prescaler which is a factor of frequency
void PWM0_setDuty(uint8 duty_perrcent);
void PWM0_stop();

 

in the main function I only used PWM0_init(); but I looked into the assembly file and I found that all the functions were written in the application code- not only the function I used-, also I found that it put all the functions from another library that I added to the directory of project even that I didn't includ it's .h file in the main file.I also found that it added the division functions that are required for these other functions but not needed for the PWM0_init() function. How can I make the compiler put the only function called and omit the rest of the unused functions from the timer0_pwm library and the other libraries?

Last Edited: Thu. May 18, 2017 - 11:38 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What compiler are we discussing here?
What compile and link options are you using?
Usually it is the linker that decides what to throw away, so have you examined the linker output?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
What compiler are we discussing here?

Essential information indeed!

 

Whether this facility is available at all and, if it is, how to control it will both be specific to the particular toolchain.

 

Usually it is the linker that decides what to throw away, so have you examined the linker output?

ISTR, for GCC ARM, it needs both a Compiler and a Linker option to be correctly set for this to work:

  1. The Compiler has to be told to make things "removable";
  2. The Linker has to be told to do the actual "removing".
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
ISTR, for GCC ARM, it needs both a Compiler and a Linker option [...]

 

Same for avr-gcc.

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you are using avr-gcc in AS7 it already passes -ffunction-sections, - fdata-sections and -gc-sections 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

the compiler is  AVR-GCC

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

the compiler is AVR-GCC  .... and the IDE is eclipse .. does we set these options by code or in project settings .. and please how?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yes Iam using avr-gcc but it doesn't remove them I opened the .lss file and all the functions were in the code

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Weren't you listening?  I just told you the options. You pass - ffunction-sections and -fdata-sections to the compiler and -Wl,-gc-sections to the linker. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I searched for this problem in some other threads here and I found  another thread were you had put the solution of putting every function in separate library and calling then including them all in one library:

http://www.nongnu.org/avr-libc/u...

 

so which one is the better solution ?

Last Edited: Fri. May 19, 2017 - 06:35 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What I just told you. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks