Author: Nico Weber Date: 2020-12-17T15:39:00-05:00 New Revision: 7e33fd9ce2d8f94bb7195c417426620037804834
URL: https://github.com/llvm/llvm-project/commit/7e33fd9ce2d8f94bb7195c417426620037804834 DIFF: https://github.com/llvm/llvm-project/commit/7e33fd9ce2d8f94bb7195c417426620037804834.diff LOG: [gn build] Link with -Wl,--gdb-index when linking with LLD For full-debug-info (is_debug=true / symbol_level=2 builds), 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 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). Only doing this for LLD because I haven't tried it with other linkers. Differential Revision: https://reviews.llvm.org/D92844 Added: Modified: llvm/utils/gn/build/BUILD.gn Removed: ################################################################################ diff --git a/llvm/utils/gn/build/BUILD.gn b/llvm/utils/gn/build/BUILD.gn index 49caf447d019..92d667c16f70 100644 --- a/llvm/utils/gn/build/BUILD.gn +++ b/llvm/utils/gn/build/BUILD.gn @@ -77,8 +77,25 @@ config("compiler_defaults") { if (host_os != "win") { if (symbol_level == 2) { cflags += [ "-g" ] + + # For full debug-info -g builds, --gdb-index makes links ~15% slower, and + # gdb symbol reading time 1500% faster (lld links in 4.4 instead of 3.9s, + # and gdb loads and runs it in 2s instead of in 30s). It's likely that + # people doing symbol_level=2 want to run a debugger (since + # symbol_level=2 isn't the default). So this seems like the right + # tradeoff. + if (host_os != "mac" && use_lld) { + cflags += [ "-ggnu-pubnames" ] # PR34820 + ldflags += [ "-Wl,--gdb-index" ] + } } else if (symbol_level == 1) { cflags += [ "-g1" ] + + # For linetable-only -g1 builds, --gdb-index makes links ~8% slower, but + # links are 4x faster than -g builds so it's a fairly small absolute cost. + # 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. } if (is_optimized) { cflags += [ "-O3" ] _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits