Does -g (or --debug) command option increase the loaded memory footprint?

136 views Asked by At

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.

1

There are 1 answers

0
Nate Eldredge On

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.