1

Does the -g (or --debug) clang command option increase the memory footprint of the compiled application? Specifically, does it change the binary size loaded on an embedded ARM system?

Note: I know the debug build adds symbol table and some more debug information to the ELF, but this should be used by the debugger, running on the host machine (say, a PC with Eclipse). Question is if it changes the size of the loaded image.

ysap
  • 7,723
  • 7
  • 59
  • 122
  • Tip: convert `.elf` file to `.bin` file. Does it change with `-g`? `an embedded ARM system?` The word "embedded" changes it's meaning - do you mean a _bare-metal_ embedded platform? Can you give an example of such system? Is raspberrypi3 or stm32 what you have in mind? – KamilCuk Sep 24 '20 at 20:28
  • I guess the term "bare metal" is what you'd describe the system in question. It is a dev board encompassing an ASIC with an ARM core (and the accompanying ecosystem) embedded. We load the FW on the chip using the ARM Dev Studio debugger. – ysap Sep 24 '20 at 20:37
  • Usually you don't load `elf` directly on such a systems. Only the essential binary is stripped down and loaded. – Eugene Sh. Sep 24 '20 at 20:39
  • @EugeneSh. - yes, which is what the debugger is doing. – ysap Sep 24 '20 at 20:49
  • 1
    @ysap Not necessarily. You might be able to flash your binary (generated with `fromelf` utility for example) to the target and it will run standalone still able to attach to a debugger. Then the debugger can load the corresponding symbols from the original ELF. – Eugene Sh. Sep 24 '20 at 20:53
  • @EugeneSh. - yes, we do this occasionally, but anyway, it is not the ELF that's being loaded on the chip. As you noted, it is a stripped version (or, an image generated with different options, or using fromelf). In any case, it'd be the loader that will extract the loadable parts from the binary. I think we are in agreement. – ysap Sep 24 '20 at 21:36

1 Answers1

4

No

The -g option only adds debug information in the binary, in sections which are not loaded into memory. The actual code and data generated is not affected.

Try running objdump -h on both versions of the ELF binary. You will see some sections marked with attribute ALLOC and others not. Only those marked ALLOC are loaded or allocated memory at runtime. You should observe that those sections have exactly the same size between both versions; indeed, they should have exactly the same contents, which you can verify with objdump --full-contents and diff if you like. The only differences are in sections that are not marked ALLOC; these are not loaded into memory and have no effect at runtime.

Nate Eldredge
  • 48,811
  • 6
  • 54
  • 82