is possible to compile a project with differentOptimization?

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

Hi all. I've a question.
I have a project that fill all my flash memory in -O0 mode, but in -Os the flash usage is about 60%.
Question. Is possible to compile some file in -Os mode for saving space and the file that I've to debug in -O0 mode?
thanks.

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

Yes, compile them seperately.

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

then link all toghether?
ok, I'm going to try.

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

Indeed - a Makefile will only rebuild a .o if the .c for it is younger. So as long as you don't change the source it will just link the pre-built .o's each time. If you wanted to be sure you could divide up your Makefile and have two sets of build - one with a set of CFLAGS where -O0 is used and one with -Os

(Personally I'd just learn to debug -Os code if I were you)

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

ok, it works fine! but how can I learn to debug in -Os?
Maybe using a large number of printf enabled only #ifdef BEBUG ? or there is another way?

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

I find the best way to debug optimised code is:

1) always use the interleaved C/Asm view
2) learn to understand the assembler the compiler is likely to generate
3) watch variables in the AVR register display rather than a watch window by studying the generated Asm and working out which registers specific variables are being held in.

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

Quote:
or there is another way?

Yes, learn to read the mixed source/assembly listings code that comes out after the optimization.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"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

read assembly code isn't a big problem for me. I don't use the mixed source/assembly listings code because the generated asm can varies all times I recompile the code.. but if this is the way, I will follow that way :) Thanks in advance.

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

That's exactly why you need to look at the mixed view - because the compiler eliminates/rearranges the code when it optimizes.