Authoritative answer wanted: "-g -O1" vs. "-O1"
David Brown
david@westcontrol.com
Tue Jun 18 14:37:00 GMT 2013
On 18/06/13 07:47, Ian Lance Taylor wrote:
> On Mon, Jun 17, 2013 at 10:21 PM, Gene Smith <gds@chartertn.net> wrote:
>> If I compile my embedded program with options "-g -O1" I obtain an elf file
>> with debug information. I can objcopy the elf file to a binary or hex file
>> that can be loaded to flash, effectively striping out the debug information
>> leaving only the optimized code in ROM.
>>
>> But if I re-build with options the same except omit the -g option, obviously
>> I will have no symbols in the elf file making debugging impossible or at
>> least more difficult. However, when I object copy this elf to a binary or
>> hex file they are different somewhat than the binary or hex produced with
>> options -g present. At least with 4.7.3 the main difference, as seen with
>> objdump, is in the prologue to certain function calls with only a few bytes
>> different in total code length on a fairly large embedded application (arm).
>> So -g has some effect on the actual code produced it appears.
>>
>> Is this difference expected? Should -g cause changes in the actual code
>> generated and not just add debug symbols to the elf? Possibly it is related
>> to the optimization level? I have not checked to see if the results differ
>> with higher or lower levels than -O1.
>>
>> I have seen several opinions regarding this but no authoritative answer. The
>> gcc manual also does not really answer this.
>
> If the only change in the command line options is whether you use -g,
> you should get exactly the same code. Any difference in code
> generation is a bug. Please try to file a bug report according to the
> guidelines at http://gcc.gnu.org/bugs/ . Thanks.
>
> Ian
>
I did not think that was the case. As I understood it, "-g" /may/ cause
to the code to improve debugging. I can't say that I have ever noticed
any code changes, but I've always assumed it is possible especially with
more advanced optimisations.
I certainly don't see anything in the documentation that suggests "-g"
cannot change the code - only that "-g -O" will generate optimised and
debugable code (though possibly with confusing debugging).
More information about the Gcc-help
mailing list