[PATCH] D92844: [gn build] Link with -Wl,--gdb-index

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 8 06:43:30 PST 2020


thakis created this revision.
thakis added reviewers: aeubanks, rnk, pcc.
Herald added a subscriber: arphaman.
thakis requested review of this revision.
Herald added a project: LLVM.

This makes linking 15% slower, but gdb startup 1500% faster
(for lld: link time 3.9s->4.4s, gdb load time >30s->2s).

For link time, I ran

  bench.py -o {noindex,index}.txt \
      sh -c 'rm out/gn/bin/lld && ninja -C out/gn/bin/lld'

and then `ministat noindex.txt index.txt`:

  x noindex.txt
  + index.txt
      N           Min           Max        Median           Avg        Stddev
  x   5      3.784461     4.0200169     3.8452811     3.8754988   0.089902595
  +   5       4.32496     4.6058481     4.3361208     4.4141198    0.12288267
  Difference at 95.0% confidence
          0.538621 +/- 0.15702
          13.8981% +/- 4.05161%
          (Student's t, pooled s = 0.107663)

For gdb load time I loaded the crash in PR48392 with

  gdb -ex r --args ../out/gn/bin/ld64.lld.darwinnew @response.txt

and just stopped the time until the crash got displayed with a stopwatch
a few times. So the speedup there is less precise, but it's so
pronounced that that's ok (loads ~instantly with the patch, takes a very
long time without it).

---

Not sure if anyone cares about this. Holler if you think we shouldn't do this and/or put it behind a flag. See comment in the build file for the reasoning why I think this is a good default.


https://reviews.llvm.org/D92844

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
@@ -75,6 +75,18 @@
   if (host_os != "win") {
     if (is_debug) {
       cflags += [ "-g" ]
+
+      # --gdb-index makes links ~15% slower, and gdb symbol reading time
+      # 15x faster (lld links in 4.4 instead of 3.9s, and gdb loads and runs
+      # it in 2s instead of in 30s). Since the GN build defaults to release
+      # builds, it's likely that people doing debug builds want to run a
+      # debugger. So this seems like the right tradeoff.
+      if (host_os != "mac") {
+        if (use_lld) {
+          cflags += [ "-ggnu-pubnames" ]  # PR34820
+        }
+        ldflags += [ "-Wl,--gdb-index" ]
+      }
     }
     if (is_optimized) {
       cflags += [ "-O3" ]


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92844.310177.patch
Type: text/x-patch
Size: 855 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201208/320f7559/attachment.bin>


More information about the llvm-commits mailing list