Skip to content

Commit

Permalink
linux: Improve gdb startup time for debug builds from over 4 minutes …
Browse files Browse the repository at this point in the history
…to 35s.

This change contains two parts, for full-symbol (symbol_level=2, default)
and reduced-symbol (symbol_level=1) debug builds. It has no effect on release
builds.

1.) For symbol_level=2, pass -Wl,--gdb-index to the linker. This lets the linker
write an index that lets it load binaries much faster.
gdb startup time for target chrome from goes from 60s to 10s and time from
`run` in gdb to the program actually starting from 270s to 45s.
In return, this slows down linking a bit, but for target chrome in a
debug build, it increases link time from 37s to 42s, which is better than
making people who want to use gdb wait several minutes every time they start
gdb.

There's some history here: We used to pass -Wl,--gdb-index long ago, and
then removed it in https://codereview.chromium.org/335903002/, with the
recommendation that people who want to use gdb could run build/gdb-add-index.
But running `gdb-add-index chrome` takes 73s nowadays, a lot more than the 5s
that gold needs. (Back then, gdb-add-index was faster, and gold, due to us
not yet defaulting to component builds in debug builds, was slower. Also,
people were on an older default Ubuntu and used an older gdb version.)

People who don't use gdb should use symbol_level=1 for their builds anyhow
(and bots do too), so this small regression in link time shouldn't affect
them.

Remove the explicit gdb_index gn arg now that this has a good default.

2) For symbol_level=1, make this mode actually work again after the gn swtich.
In symbol_level=1 builds, gn would pass `-g1 -gsplit-dwarf` to clang (*).
Surprisingly, -gsplit-dwarf implies -g2 with clang, so the -g1 gets
overriden by -g2 immediately.

Before this, symbol_level=1 in debug builds would produce full debug info.
Since all bots set symbol_level=1, this might help with build speed
on debug bots.  For people who set this locally, it'll also speed up
gdb startup time for target chrome from 39s to 13s and time from
`run` in gdb to the program actually starting from 255s to 35s.

*: clang always writes stack debug info to both .o and .dwo files, and lets
the linker link them into the executable, so -g1 -gsplit-dwarf would make
no sense. This was used as justification to make -gsplit-dwarf imply -g2,
as it otherwise wouldn't have an effect.

BUG=374952

Review-Url: https://codereview.chromium.org/2770933009
Cr-Commit-Position: refs/heads/master@{#459790}
  • Loading branch information
nico authored and Commit bot committed Mar 27, 2017
1 parent 581ff14 commit 7b26c51
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions build/config/compiler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ declare_args() {
exclude_unwind_tables = (is_chrome_branded && is_official_build) ||
(is_chromecast && !is_cast_desktop_build && !is_debug)

# If true, gold linker will save symbol table inside object files.
# This speeds up gdb startup by 60%
gdb_index = false

# If true, optimize for size. Does not affect windows builds.
# Linux & Mac favor speed over size.
# TODO(brettw) it's weird that Mac and desktop Linux are different. We should
Expand Down Expand Up @@ -309,7 +305,8 @@ config("compiler") {
ldflags += [ "-fPIC" ]
}

cflags += [ "-pipe" ] # Use pipes for communicating between sub-processes. Faster.
# Use pipes for communicating between sub-processes. Faster.
cflags += [ "-pipe" ]

ldflags += [
"-Wl,-z,noexecstack",
Expand Down Expand Up @@ -375,10 +372,6 @@ config("compiler") {
}
}

if (gdb_index) {
ldflags += [ "-Wl,--gdb-index" ]
}

# TODO(thestig): Make this flag work with GN.
#if (!is_official_build && !is_chromeos && !(is_asan || is_lsan || is_tsan || is_msan)) {
# ldflags += [
Expand Down Expand Up @@ -1662,6 +1655,9 @@ config("symbols") {
}
asmflags = cflags
ldflags = []
if (!is_mac && !is_ios && !is_nacl) {
ldflags += [ "-Wl,--gdb-index" ]
}
}
}

Expand All @@ -1683,9 +1679,8 @@ config("minimal_symbols") {
} else {
cflags = [ "-g1" ]
}
if (use_debug_fission) {
cflags += [ "-gsplit-dwarf" ]
}

# Note: -gsplit-dwarf implicitly turns on -g2 with clang, so don't pass it.
asmflags = cflags
ldflags = []
}
Expand Down

0 comments on commit 7b26c51

Please sign in to comment.