Page 1 of 1

Does optimization for GDB work at all in GCC 9.2.1?

Posted: Tue Apr 06, 2021 2:59 pm
by szekelyisz
Hi,

I'm using ChibiStudio with included GCC 9.2.1. I noticed that when I compile my code with -O0 I get a binary size of around 70 kB. But when I wanted to add more debugging information with -Og -ggdb, the compiled binary size dropped to 47kB and the debugging experience is like with -O2 or -O3 (stepping through the code line by line jumps around like it was optimized on some level). Optimizing for GDB should leave even more information in the binary so I'd expect the size of it to be bigger, and linear code execution just like -O0.

Has anybody come across this?

Here are all my compiler flags:

Code: Select all

-specs=nano.specs -mcpu=cortex-m4 -Og -ggdb3 -fomit-frame-pointer -falign-functions=16 -Wall -ffunction-sections -fdata-sections -fno-common -nostartfiles -Wl,-Map=build/Debug/ch.map,--cref,--no-warn-mismatch,--library-path=/home/szabi/chibios/os/common/startup/ARMCMx/compilers/GCC/ld,--script=board/STM32F427xG.ld,--gc-sections,-print-memory-usage,--defsym=__process_stack_size__=0x1000,--defsym=__main_stack_size__=0x400 -mno-thumb-interwork


Thanks,
Szabi

Re: Does optimization for GDB work at all in GCC 9.2.1?

Posted: Tue Apr 06, 2021 3:09 pm
by Giovanni
Hi,

As far I know debugging information do not contribute to the binary image size, it is metadata used by the debugger.

Giovanni

Re: Does optimization for GDB work at all in GCC 9.2.1?

Posted: Tue Apr 06, 2021 3:17 pm
by szekelyisz
Thanks. That makes sense, but it still doesn't explain why -Og code is smaller than -O0. As far as I understand -Og disables at least all those optimizations as -O0 (and maybe more).

Re: Does optimization for GDB work at all in GCC 9.2.1?

Posted: Tue Apr 06, 2021 3:19 pm
by Giovanni
-Og disables all optimizations that impact "debug experience quality" and only those
-O0 disables all optimizations, all of them

Giovanni