On the importance of optimization flags

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

I am making an application on a ATMEGA168 so I have 16Kb of flash space. I added and added functionnalities and the size grows a lot with time.

This is the basic optimization there was in my Makefile (with -Os of course)
-funsigned-char -funsigned-bitfields -fshort-enums -fpack-struct

resulting in my application being 18030 bytes.

I then search a little bit on the net how to optimize for avr-gcc (I have version 4.3.0), what I did is try each parameter one by one with a "make clean all" to check the size result. Some parameters produce bigger size, some give a few bytes, some give hundreds, I took only the one that gave me a gain.

I ended with:
-funsigned-char -funsigned-bitfields -fshort-enums -fpack-struct -ffunction-sections -fdata-sections -fno-split-wide-types -Wl,--relax,--gc-sections -fno-inline-small-functions -mcall-prologues -morder1

and my application is now 15858 bytes

difference : 2172 bytes

So I just wanted to share my result if it can be useful for other people with limited flash :D

EDIT: typo

Last Edited: Tue. Oct 6, 2009 - 04:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try:
--combine -fwhole-program

Peter

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

danni wrote:
Try:
--combine -fwhole-program
Peter

I tried combining all the .c on one line only with these 2 parameters, it gives 15942 bytes, go figure :?