Task #5279
Updated by Davide Pesavento over 1 year ago
I'd like to propose changing our default CXXFLAGS to reduce the amount of debug info that ends up in the compiled object files and eventually in the final binaries.
### Motivation
The goal is to have smaller binaries and (in some cases) shorter build times without affecting the debugging experience too much (including symbolization of stack traces). Yes, it's already possible for users to manually strip the final binaries, but unless we integrate stripping in `./waf install` somehow, I think it's fair to assume that no one is doing it in practice when building from source (the PPA packages are a different story). Moreover, stripping destroys any chances of debugging or obtaining human-readable stack traces, while still paying the increased time and memory cost during compilation, so it's arguably worse than keeping a minimal/reduced amount
of debug info in the binary.
### Status quo
The current default CXXFLAGS contain `-g` (equivalent to `-g2`) in release builds and `-g3` in debug builds. See [GCC documentation on debugging options](https://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html). The corresponding clang options have very similar, if not identical, semantics.
### Reduced debug info
My suggestion is to switch release builds to `-g1` and debug builds to `-g2`.
I have verified that, at least on Linux/GCC, `-g1` is sufficient to produce human-readable function names in stack traces. This is also stated in the GCC documentation.
By downgrading from `-g3` to `-g2` we lose information on the macro definitions present in the program, but I've personally never had to use this functionality in a debugger. And if there is a (very rare) case where this is needed, it's easy enough to change the flag to `-g3` and recompile.
Most Linux distros use "split" debug info, which is typically handled automatically as part of the package build process, so it probably makes sense to override the (release) flags to restore `-g`/`-g2` for our PPA packages.
### Compressed debug sections
Another flag we could consider in the future, either in addition or in alternative to this proposal, is `-gz` which uses zlib to produce compressed debug sections.