summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksei Vetrov <vvvvvv@google.com>2024-03-12 15:41:31 +0000
committerAleksei Vetrov <vvvvvv@google.com>2024-03-19 14:17:58 +0000
commit5003de911644e1e8d04d6b0c7f4b027825cb5a21 (patch)
tree0b8a401fa9fc6c9cf8c75a7e4ca11676f4b63553
parent380cf0091e727229b89d547e3f8b7784efd7605f (diff)
downloadbuild-5003de911644e1e8d04d6b0c7f4b027825cb5a21.tar.gz
kleaf: use /proc/self/cwd as root directory in debug info
We use "-ffile-prefix-map" option to remove build directory from debug info and to allow debugging on any machine with source code available. But this rule was transforming an absolute path to a relative path, which triggers a bug in DWARF and compilers, see https://github.com/llvm/llvm-project/issues/83174. "/proc/self/cwd" is an absolute path that resolves to a directory where debugger runs, so debug information remains "relocatable" and the bug is not triggered. Original rules were relative to a "${{KERNEL_DIR}}", but in this change "/proc/self/cwd" corresponds to the top repo directory, because: * Users start Bazel in top directory, it would be convenient not to change directory when switching to debugger. * Generated files live outside of "${{KERNEL_DIR}}", and in non-sandbox build (config=local or config=fast) they are accessible from the top directory. * No need to have a separate rule to rewrite "${{ROOT_DIR}}/${{KERNEL_DIR}}" except for unsanboxed builds, where "${{KERNEL_DIR}}" is a symlink to a directory outside of "${{ROOT_DIR}}". Test: TH, manual builds with config=local and config=fast Bug: 315009365 Change-Id: I7727fa93ddf39301f9f755a748d2ef3ad91007bb
-rw-r--r--kleaf/impl/kernel_env.bzl18
1 files changed, 14 insertions, 4 deletions
diff --git a/kleaf/impl/kernel_env.bzl b/kleaf/impl/kernel_env.bzl
index 56573e7..0577263 100644
--- a/kleaf/impl/kernel_env.bzl
+++ b/kleaf/impl/kernel_env.bzl
@@ -385,15 +385,25 @@ def _get_env_setup_cmds(ctx):
## Set up KCPPFLAGS
- # use relative paths for file name references in the binaries
- # (e.g. debug info)
- export KCPPFLAGS="-ffile-prefix-map=${{ROOT_DIR}}/${{KERNEL_DIR}}/= -ffile-prefix-map=${{ROOT_DIR}}/="
+ # Replace ${{ROOT_DIR}} with "/proc/self/cwd" in the file name
+ # references in the binaries (e.g. debug info).
+ # "/proc/self/cwd" is an absolute path that resolves to a directory
+ # where debugger runs. And ${{ROOT_DIR}} layout should be the same as
+ # layout on the top of the repo, so if you start a debugger from the
+ # top directory, all paths should resolve correctly even on another
+ # machine.
+ export KCPPFLAGS="-ffile-prefix-map=${{ROOT_DIR}}=/proc/self/cwd"
# For Kleaf local (non-sandbox) builds, $ROOT_DIR is under execroot but
# $ROOT_DIR/$KERNEL_DIR is a symlink to the real source tree under
# workspace root, making $abs_srctree not under $ROOT_DIR.
+ # Because compiler puts a real path to a binary, it should be a real
+ # path in -ffile-prefix-map. Also we would like to leave
+ # ${{KERNEL_DIR}} part in the path to be able to run debugger from the
+ # top directory, so we go one directory up from
+ # ${{ROOT_DIR}}/${{KERNEL_DIR}} before calling realpath.
if [[ "$(realpath ${{ROOT_DIR}}/${{KERNEL_DIR}})" != "${{ROOT_DIR}}/${{KERNEL_DIR}}" ]]; then
- export KCPPFLAGS="$KCPPFLAGS -ffile-prefix-map=$(realpath ${{ROOT_DIR}}/${{KERNEL_DIR}})/="
+ export KCPPFLAGS="$KCPPFLAGS -ffile-prefix-map=$(realpath ${{ROOT_DIR}}/${{KERNEL_DIR}}/..)=/proc/self/cwd"
fi
""".format(
get_make_jobs_cmd = status.get_volatile_status_cmd(ctx, "MAKE_JOBS"),