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.
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 attributeALLOC
and others not. Only those markedALLOC
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 withobjdump --full-contents
anddiff
if you like. The only differences are in sections that are not markedALLOC
; these are not loaded into memory and have no effect at runtime.