Skip to content

Commit b55755a

Browse files
authored
Use debug-prefix-map to avoid absolute paths in debug info (#852)
For flutter/flutter#147750
1 parent 037a290 commit b55755a

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

build/config/BUILDCONFIG.gn

+1
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ if (is_win) {
371371
if (is_posix) {
372372
_native_compiler_configs += [
373373
"//build/config/gcc:no_exceptions",
374+
"//build/config/gcc:relative_paths",
374375
"//build/config/gcc:symbol_visibility_hidden",
375376
"//build/config:symbol_visibility_hidden",
376377
]

build/config/gcc/BUILD.gn

+44
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# found in the LICENSE file.
44

55
import("//build/config/profiler.gni")
6+
import("//build/toolchain/rbe.gni")
67

78
# This config causes functions not to be automatically exported from shared
89
# libraries. By default, all symbols are exported but this means there are
@@ -49,3 +50,46 @@ config("no_exceptions") {
4950
cflags_cc = no_exceptions_flags
5051
cflags_objcc = no_exceptions_flags
5152
}
53+
54+
config("relative_paths") {
55+
# Make builds independent of absolute file path. The file names
56+
# embedded in debugging information will be expressed as relative to
57+
# the build directory, e.g. "../.." for an "out/subdir" under //.
58+
# This is consistent with the file names in __FILE__ expansions
59+
# (e.g. in assertion messages), which the compiler doesn't provide a
60+
# way to remap. That way source file names in logging and
61+
# symbolization can all be treated the same way. This won't go well
62+
# if root_build_dir is not a subdirectory //, but there isn't a better
63+
# option to keep all source file name references uniformly relative to
64+
# a single root.
65+
cflags = []
66+
cflags_objcc = []
67+
absolute_path = rebase_path("//")
68+
relative_path = ""
69+
if (use_rbe) {
70+
# objc builds are always local even when rbe is enabled.
71+
cflags_objcc += [
72+
# This makes sure that the DW_AT_comp_dir string (the current
73+
# directory while running the compiler, which is the basis for all
74+
# relative source file names in the DWARF info) is represented as
75+
# relative to //.
76+
"-fdebug-prefix-map=$absolute_path=$relative_path",
77+
]
78+
} else {
79+
cflags += [
80+
"-fdebug-prefix-map=$absolute_path=$relative_path",
81+
]
82+
}
83+
cflags += [
84+
# This makes sure that include directories in the toolchain are
85+
# represented as relative to the build directory (because that's how
86+
# we invoke the compiler), rather than absolute. This can affect
87+
# __FILE__ expansions (e.g. assertions in system headers). We
88+
# normally run a compiler that's someplace within the source tree
89+
# (//buildtools/...), so its absolute installation path will have a
90+
# prefix matching absolute_path and hence be mapped to relative_path
91+
# in the debugging information, so this should actually be
92+
# superfluous for purposes of the debugging information.
93+
"-no-canonical-prefixes",
94+
]
95+
}

build/toolchain/mac/BUILD.gn

+3
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ if (use_goma) {
3030
} else if (use_rbe) {
3131
remote_wrapper =
3232
rebase_path("//flutter/build/rbe/remote_wrapper.sh", root_build_dir)
33+
local_wrapper =
34+
rebase_path("//flutter/build/rbe/local_wrapper.sh", root_build_dir)
3335
compiler_args = rewrapper_command + [
3436
"--remote_wrapper=$remote_wrapper",
37+
"--local_wrapper=$local_wrapper",
3538
"--labels=type=compile,compiler=clang,lang=cpp ",
3639
]
3740
cxx_prefix = string_join(" ", compiler_args)

0 commit comments

Comments
 (0)