Does optimization for GDB work at all in GCC 9.2.1?

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
szekelyisz
Posts: 11
Joined: Wed Jan 03, 2018 8:15 pm
Has thanked: 1 time

Does optimization for GDB work at all in GCC 9.2.1?

Post 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
User avatar
Giovanni
Site Admin
Posts: 14890
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

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

Post 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
szekelyisz
Posts: 11
Joined: Wed Jan 03, 2018 8:15 pm
Has thanked: 1 time

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

Post 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).
User avatar
Giovanni
Site Admin
Posts: 14890
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

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

Post by Giovanni »

-Og disables all optimizations that impact "debug experience quality" and only those
-O0 disables all optimizations, all of them

Giovanni
Post Reply