[PATCH] D115040: [gn build] Build with Fission on non-mac non-win when using lld

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 3 07:07:19 PST 2021


thakis created this revision.
thakis added a reviewer: hans.
thakis requested review of this revision.
Herald added a project: LLVM.

In release+sym builds (-O2 -g), reduces time to link `clang`
from 2.3s to 1.3s (-42%).

In debug builds (-g), reduces time to link `clang`
from 5.4s to 4.5s (-17.4%).

See the phab review for full `ministat` numbers.

In the CMake build this is opt-in via LLVM_USE_SPLIT_DWARF.
Since the GN build is targeted at developers, enabling it by default
seems like a better default setting here. (If it turns out to cause
problems, we can add an opt-out.)

Time to load the binary into gdb and to set a breakpoint is unchanged.
Time from `run` to hitting a breakpoint in `main` feel a bit faster
(~4s -> ~2s), but I dind't do a careful statistical anlysis for this.


https://reviews.llvm.org/D115040

Files:
  llvm/utils/gn/build/BUILD.gn


Index: llvm/utils/gn/build/BUILD.gn
===================================================================
--- llvm/utils/gn/build/BUILD.gn
+++ llvm/utils/gn/build/BUILD.gn
@@ -72,6 +72,32 @@
       if (host_os != "mac" && use_lld) {
         cflags += [ "-ggnu-pubnames" ]  # PR34820
         ldflags += [ "-Wl,--gdb-index" ]
+
+        # Use debug fission. In this mode, detailed debug information is
+        # written to a .dwo file next to each .o file instead of into the .o
+        # file directly. The linker then only links the .o files, which contain
+        # a pointer to each .dwo file. The debugger then reads debug info out
+        # of all the .dwo files instead of from the binary.
+        #
+        # (The dwp tool can link all the debug info together into a single
+        # "debug info binary", but that's not done as part of the build.)
+        #
+        # This requires `-Wl,--gdb-index` (above) to work well.
+        #
+        # With lld, this reduces link time:
+        # - in release + symbol_level=2 builds: From 2.3s to 1.3s
+        # - in debug builds: From 5.2s to 4.6s
+        #
+        # Time needed for gdb startup and setting a breakpoint is comparable,
+        # the time from from `r` to hititng a breakpoint on main goes from 4s
+        # to 2s.
+        #
+        # (macOS's linker always keeps debug info out of its output executables
+        # and debuggers there also know to load debug info from the .o files.
+        # macOS also has a debug info linker like dwp, it's called dsymutil.
+        # This happens by default, so there's no need to pass a flag there.)
+        cflags += [ "-gsplit-dwarf" ]
+        ldflags += [ "-gsplit-dwarf" ]  # Needed for ThinLTO builds.
       }
     } else if (symbol_level == 1) {
       cflags += [ "-g1" ]
@@ -80,6 +106,8 @@
       # On the other hand, gdb startup is well below 1s with and without the
       # index, and people using -g1 likely don't use a debugger. So don't use
       # the flag here.
+      # Linetables always go in the .o file, even with -gsplit-dwarf, so there's
+      # no point in passing -gsplit-dwarf here.
     }
     if (is_optimized) {
       cflags += [ "-O3" ]


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115040.391628.patch
Type: text/x-patch
Size: 2194 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211203/9bfb6db1/attachment.bin>


More information about the llvm-commits mailing list