diff --git a/llvm/utils/gn/build/BUILD.gn b/llvm/utils/gn/build/BUILD.gn --- a/llvm/utils/gn/build/BUILD.gn +++ b/llvm/utils/gn/build/BUILD.gn @@ -77,8 +77,25 @@ 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" ]