[cfe-dev] RFC: Adding constructor homing to clang's limited debug info mode

Amy Huang via cfe-dev cfe-dev at lists.llvm.org
Wed May 6 15:03:43 PDT 2020

Recently I added a level to clang's debug info
(-debug-info-kind=constructor) based on Reid's constructor type homing
idea. Since classes typically live in header files and have no natural
"home", class type information is emitted in every translation unit where
it is required to be complete, which results in a lot of duplicate debug
info. Constructor type homing attempts to reduce the amount of duplicate
debug info by emitting debug info for classes only where the constructor is
emitted. It's based on the assumption that if complete debug info for a
class is needed, then it should be constructed somewhere in the program.
Currently this applies to classes with nontrivial, user-defined
constructors. For classes with no constructors or no nontrivial
constructors, there is no change, so debug info is still emitted
everywhere. This RFC proposes using constructor homing as part of clang's
limited debug info level.

Currently clang's limited debug info mode already has some optimizations
for limiting the amount of class debug info; for example, we emit debug
info for dynamic classes only when the vtable is emitted, since the program
will fail to link if the vtable is not provided.

Link to the original patch adding `-debug-info-kind=constructor`:
Patch for the proposed change: https://reviews.llvm.org/D79147

*Some numbers from the LLVM build*
This is a comparison I did on my machine of total object file size in Clang
debug builds, with and without constructor homing (-debug-info-kind=limited
vs. constructor). In general it seems to reduce the total object file size
by 30-50%.
on Linux
before: 9345 MB
after: 4553 MB

on Windows
before: 6096 MB
after: 3979 MB

We also enabled this in Chromium a few months ago, and saw a similar change
in object / split dwarf file size.

There isn't a very comprehensive way that I know of to test debug info. I
tested a few things:
- Ran the LLDB test suite with this change as part of
-debug-info-kind=limited. This caught an edge case with constexpr
constructors. After fixing this, the LLDB test suite now passes with this
mode (minus one test case that happens to fail, and is updated in the
proposed patch)
-Compared clang.pdb files in a Windows LLVM debug build, and looked at the
list of types that are no longer complete with the constructor homing
change. We looked into some of these types, and they are constructed in
functions that aren't used in clang.exe. In this case, it makes sense to
not emit complete debug information.
-Enabled this in Chromium and we haven't yet received any bug reports about
debug info.

We talked about running the GDB test suite with Clang in this mode, but the
GDB test suite doesn't currently pass with Clang. Triaging GDB test suite
failures is probably more than a month of work, so we don't plan to pursue

Any feedback is welcome! Especially looking for opinions on whether this
should be the default for limited debug info, or if more testing is
preferred, what that might look like.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200506/acba3bf1/attachment.html>

More information about the cfe-dev mailing list