Commit 40fd334b authored by Nico Weber's avatar Nico Weber Committed by Commit Bot

win: Pass /pdbaltpath:%_PDB% to the linker every time we pass /DEBUG.

The linker by defaults writes the absolute path to the corresponding pdb
into executables it creates (if /DEBUG is passed).

/pdbaltpath:%_PDB% tells it to instead just write the basename of the pdb
into the executable, which makes the build more reproducible:

1. Different build directories no longer cause the part of the exe that contains
   the pdb path to be different.

2. More subtly, the pdb file contains offsets into the executable, and if the
   pdb path has different lengths on different systems, the pdb file will be
   different due to the absolute pdb path in the executable.  lld-link sets the
   UUID of the pdb to the hash of the pdb file contents, and the UUID of the
   pdb is also stored in the executable.  So this is also one of the parts
   needed to make the pdb output deterministic.

(Note that while link.exe has supported /pdbaltpath:%_PDB% for a long time,
lld-link learned about %_PDB% only very recently, and this CL depends on the
clang roll https://chromium-review.googlesource.com/c/1271718.)

Bug: 330260
Change-Id: If4c505ababa46ed4f51330521ff09f12f6840a47
Reviewed-on: https://chromium-review.googlesource.com/c/1273475Reviewed-by: default avatarBruce Dawson <brucedawson@chromium.org>
Commit-Queue: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#598940}
parent 5a922743
...@@ -2182,6 +2182,22 @@ config("afdo") { ...@@ -2182,6 +2182,22 @@ config("afdo") {
# configs -= [ "//build/config/compiler:default_symbols" ] # configs -= [ "//build/config/compiler:default_symbols" ]
# configs += [ "//build/config/compiler:symbols" ] # configs += [ "//build/config/compiler:symbols" ]
# A helper config that all configs passing /DEBUG to the linker should
# include as sub-config.
config("win_pdbaltpath") {
visibility = [
":symbols",
":minimal_symbols",
]
# /DEBUG causes the linker to generate a pdb file, and to write the absolute
# path to it in the executable file it generates. This flag turns that
# absolute path into just the basename of the pdb file, which helps with
# build reproducibility. Debuggers look for pdb files next to executables,
# so there's no downside to always using this.
ldflags = [ "/pdbaltpath:%_PDB%" ]
}
# Full symbols. # Full symbols.
config("symbols") { config("symbols") {
if (is_win) { if (is_win) {
...@@ -2212,6 +2228,9 @@ config("symbols") { ...@@ -2212,6 +2228,9 @@ config("symbols") {
ldflags = [ "/DEBUG" ] ldflags = [ "/DEBUG" ]
} }
# All configs using /DEBUG should include this:
configs = [ ":win_pdbaltpath" ]
if (is_clang) { if (is_clang) {
# /DEBUG:FASTLINK requires every object file to have standalone debug # /DEBUG:FASTLINK requires every object file to have standalone debug
# information. # information.
...@@ -2287,6 +2306,9 @@ config("minimal_symbols") { ...@@ -2287,6 +2306,9 @@ config("minimal_symbols") {
cflags = [] cflags = []
ldflags = [ "/DEBUG" ] ldflags = [ "/DEBUG" ]
# All configs using /DEBUG should include this:
configs = [ ":win_pdbaltpath" ]
# For win/asan, get stack traces with full line numbers. # For win/asan, get stack traces with full line numbers.
# AddressSanitizerTests.TestAddressSanitizer needs this, and since # AddressSanitizerTests.TestAddressSanitizer needs this, and since
# win/asan isn't a default cq bot the build time hit is ok. # win/asan isn't a default cq bot the build time hit is ok.
......
...@@ -139,7 +139,7 @@ config("compiler") { ...@@ -139,7 +139,7 @@ config("compiler") {
if (!is_debug && !is_component_build) { if (!is_debug && !is_component_build) {
# Enable standard linker optimizations like GC (/OPT:REF) and ICF in static # Enable standard linker optimizations like GC (/OPT:REF) and ICF in static
# release builds. These are implied by /PROFILE below, but /PROFILE is # release builds. These are implied by /PROFILE below, but /PROFILE is
# incompatible with /debug:fastlink and LLD ignores it as of this writing. # incompatible with /debug:fastlink.
# Release builds always want these optimizations, so enable them explicitly. # Release builds always want these optimizations, so enable them explicitly.
# TODO(crbug.com/884545): Remove the checks for use_libfuzzer when # TODO(crbug.com/884545): Remove the checks for use_libfuzzer when
# libFuzzer's issues with /OPT:REF are resolved upstream. # libFuzzer's issues with /OPT:REF are resolved upstream.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment