diff options
| author | bors <bors@rust-lang.org> | 2022-05-18 12:45:44 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-05-18 12:45:44 +0000 |
| commit | 936eba3b348e65b658b60218cc9237f02abdbeb4 (patch) | |
| tree | 170ce02aaa1fca72948775fc8adaccf2952f82e7 /src | |
| parent | e5732a21711e7cefa6eb22e1790406b269d6197a (diff) | |
| parent | 6411fef3aba5ba54a02b54b171b4e9bc83687ce9 (diff) | |
| download | rust-936eba3b348e65b658b60218cc9237f02abdbeb4.tar.gz rust-936eba3b348e65b658b60218cc9237f02abdbeb4.zip | |
Auto merge of #96867 - michaelwoerister:path-prefix-fixes-2, r=davidtwco
--remap-path-prefix: Fix duplicated path components in debuginfo This PR fixes an issue with `--remap-path-prefix` where path components could appear twice in the remapped version of the path (e.g. https://github.com/rust-lang/rust/issues/78479). The underlying problem was that `--remap-path-prefix` is often used to map an absolute path to something that looks like a relative path, e.g.: ``` --remap-path-prefix=/home/calvin/.cargo/registry/src/github.com-1ecc6299db9ec823=crates.io", ``` and relative paths in debuginfo are interpreted as being relative to the compilation directory. So if Cargo invokes the compiler with `/home/calvin/.cargo/registry/src/github.com-1ecc6299db9ec823/some_crate-0.1.0/src/lib.rs` as input and `/home/calvin/.cargo/registry/src/github.com-1ecc6299db9ec823/some_crate-0.1.0` as the compiler's working directory, then debuginfo will state that the working directory was `crates.io/some_crate-0.1.0` and the file is question was `crates.io/some_crate-0.1.0/src/lib.rs`, which combined gives the path: ``` crates.io/some_crate-0.1.0/crates.io/some_crate-0.1.0/src/lib.rs ``` With this PR the compiler will detect this situation and set up debuginfo in LLVM in a way that makes it strip the duplicated path components when emitting DWARF. The PR also extracts the logic for making remapped paths absolute into a common helper function that is now used by debuginfo too (instead of just during crate metadata generation).
Diffstat (limited to 'src')
| -rw-r--r-- | src/bootstrap/dist.rs | 1 | ||||
| -rw-r--r-- | src/test/codegen/remap_path_prefix/main.rs | 2 | ||||
| -rw-r--r-- | src/test/run-make/remap-path-prefix-dwarf/Makefile | 77 | ||||
| -rw-r--r-- | src/test/run-make/remap-path-prefix-dwarf/src/quux.rs | 5 |
4 files changed, 84 insertions, 1 deletions
diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 6181a611ec3..16727f4398d 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -2047,6 +2047,7 @@ impl Step for RustDev { "llvm-cov", "llvm-dwp", "llvm-nm", + "llvm-dwarfdump", ] { tarball.add_file(src_bindir.join(exe(bin, target)), "bin", 0o755); } diff --git a/src/test/codegen/remap_path_prefix/main.rs b/src/test/codegen/remap_path_prefix/main.rs index b13d576295c..381f11ff1ef 100644 --- a/src/test/codegen/remap_path_prefix/main.rs +++ b/src/test/codegen/remap_path_prefix/main.rs @@ -22,7 +22,7 @@ fn main() { } // Here we check that local debuginfo is mapped correctly. -// CHECK: !DIFile(filename: "/the/src/remap_path_prefix/main.rs", directory: "/the/cwd" +// CHECK: !DIFile(filename: "/the/src/remap_path_prefix/main.rs", directory: "" // And here that debuginfo from other crates are expanded to absolute paths. // CHECK: !DIFile(filename: "/the/aux-src/remap_path_prefix_aux.rs", directory: "" diff --git a/src/test/run-make/remap-path-prefix-dwarf/Makefile b/src/test/run-make/remap-path-prefix-dwarf/Makefile new file mode 100644 index 00000000000..561a343d60b --- /dev/null +++ b/src/test/run-make/remap-path-prefix-dwarf/Makefile @@ -0,0 +1,77 @@ +# This test makes sure that --remap-path-prefix has the expected effects on paths in debuginfo. +# It tests several cases, each of them has a detailed description attached to it. + +# ignore-windows + +SRC_DIR := $(abspath .) +SRC_DIR_PARENT := $(abspath ..) + +-include ../../run-make-fulldeps/tools.mk + +all: \ + abs_input_outside_working_dir \ + rel_input_remap_working_dir \ + rel_input_remap_working_dir_parent \ + rel_input_remap_working_dir_child \ + abs_input_inside_working_dir \ + abs_input_outside_working_dir + +# The compiler is called with an *ABSOLUTE PATH* as input, and that absolute path *is* within +# the working directory of the compiler. We are remapping the path that contains `src`. +abs_input_inside_working_dir: + # We explicitly switch to a directory that *is* a prefix of the directory our + # source code is contained in. + cd $(SRC_DIR) && $(RUSTC) $(SRC_DIR)/src/quux.rs -o "$(TMPDIR)/abs_input_inside_working_dir.rlib" -Cdebuginfo=2 --remap-path-prefix $(SRC_DIR)=REMAPPED + # We expect the path to the main source file to be remapped. + "$(LLVM_BIN_DIR)"/llvm-dwarfdump $(TMPDIR)/abs_input_inside_working_dir.rlib | $(CGREP) "REMAPPED/src/quux.rs" + # No weird duplication of remapped components (see #78479) + "$(LLVM_BIN_DIR)"/llvm-dwarfdump $(TMPDIR)/abs_input_inside_working_dir.rlib | $(CGREP) -v "REMAPPED/REMAPPED" + +# The compiler is called with an *ABSOLUTE PATH* as input, and that absolute path is *not* within +# the working directory of the compiler. We are remapping both the path that contains `src` and +# the working directory to the same thing. This setup corresponds to a workaround that is needed +# when trying to remap everything to something that looks like a local path. +# Relative paths are interpreted as relative to the compiler's working directory (e.g. in +# debuginfo). If we also remap the working directory, the compiler strip it from other paths so +# that the final outcome is the desired one again. +abs_input_outside_working_dir: + # We explicitly switch to a directory that is *not* a prefix of the directory our + # source code is contained in. + cd $(TMPDIR) && $(RUSTC) $(SRC_DIR)/src/quux.rs -o "$(TMPDIR)/abs_input_outside_working_dir.rlib" -Cdebuginfo=2 --remap-path-prefix $(SRC_DIR)=REMAPPED --remap-path-prefix $(TMPDIR)=REMAPPED + "$(LLVM_BIN_DIR)"/llvm-dwarfdump $(TMPDIR)/abs_input_outside_working_dir.rlib | $(CGREP) "REMAPPED/src/quux.rs" + # No weird duplication of remapped components (see #78479) + "$(LLVM_BIN_DIR)"/llvm-dwarfdump $(TMPDIR)/abs_input_outside_working_dir.rlib | $(CGREP) -v "REMAPPED/REMAPPED" + +# The compiler is called with a *RELATIVE PATH* as input. We are remapping the working directory of +# the compiler, which naturally is an implicit prefix of our relative input path. Debuginfo will +# expand the relative path to an absolute path and we expect the working directory to be remapped +# in that expansion. +rel_input_remap_working_dir: + cd $(SRC_DIR) && $(RUSTC) src/quux.rs -o "$(TMPDIR)/rel_input_remap_working_dir.rlib" -Cdebuginfo=2 --remap-path-prefix "$(SRC_DIR)=REMAPPED" + "$(LLVM_BIN_DIR)"/llvm-dwarfdump "$(TMPDIR)/rel_input_remap_working_dir.rlib" | $(CGREP) "REMAPPED/src/quux.rs" + # No weird duplication of remapped components (see #78479) + "$(LLVM_BIN_DIR)"/llvm-dwarfdump "$(TMPDIR)/rel_input_remap_working_dir.rlib" | $(CGREP) -v "REMAPPED/REMAPPED" + +# The compiler is called with a *RELATIVE PATH* as input. We are remapping a *SUB-DIRECTORY* of the +# compiler's working directory. This test makes sure that that directory is remapped even though it +# won't actually show up in this form in the compiler's SourceMap and instead is only constructed +# on demand during debuginfo generation. +rel_input_remap_working_dir_child: + cd $(SRC_DIR) && $(RUSTC) src/quux.rs -o "$(TMPDIR)/rel_input_remap_working_dir_child.rlib" -Cdebuginfo=2 --remap-path-prefix "$(SRC_DIR)/src=REMAPPED" + # We expect `src/quux.rs` to have been remapped to `REMAPPED/quux.rs`. + "$(LLVM_BIN_DIR)"/llvm-dwarfdump "$(TMPDIR)/rel_input_remap_working_dir_child.rlib" | $(CGREP) "REMAPPED/quux.rs" + # We don't want to find the path that we just remapped anywhere in the DWARF + "$(LLVM_BIN_DIR)"/llvm-dwarfdump "$(TMPDIR)/rel_input_remap_working_dir_child.rlib" | $(CGREP) -v "$(SRC_DIR)/src" + # No weird duplication of remapped components (see #78479) + "$(LLVM_BIN_DIR)"/llvm-dwarfdump "$(TMPDIR)/rel_input_remap_working_dir_child.rlib" | $(CGREP) -v "REMAPPED/REMAPPED" + +# The compiler is called with a *RELATIVE PATH* as input. We are remapping a *PARENT DIRECTORY* of +# the compiler's working directory. +rel_input_remap_working_dir_parent: + cd $(SRC_DIR) && $(RUSTC) src/quux.rs -o "$(TMPDIR)/rel_input_remap_working_dir_parent.rlib" -Cdebuginfo=2 --remap-path-prefix "$(SRC_DIR_PARENT)=REMAPPED" + # We expect `src/quux.rs` to have been remapped to `REMAPPED/remap-path-prefix-dwarf/src/quux.rs`. + "$(LLVM_BIN_DIR)"/llvm-dwarfdump "$(TMPDIR)/rel_input_remap_working_dir_parent.rlib" | $(CGREP) "REMAPPED/remap-path-prefix-dwarf/src/quux.rs" + # We don't want to find the path that we just remapped anywhere in the DWARF + "$(LLVM_BIN_DIR)"/llvm-dwarfdump "$(TMPDIR)/rel_input_remap_working_dir_parent.rlib" | $(CGREP) -v "$(SRC_DIR_PARENT)" + # No weird duplication of remapped components (see #78479) + "$(LLVM_BIN_DIR)"/llvm-dwarfdump "$(TMPDIR)/rel_input_remap_working_dir_parent.rlib" | $(CGREP) -v "REMAPPED/REMAPPED" diff --git a/src/test/run-make/remap-path-prefix-dwarf/src/quux.rs b/src/test/run-make/remap-path-prefix-dwarf/src/quux.rs new file mode 100644 index 00000000000..38d5ef6194c --- /dev/null +++ b/src/test/run-make/remap-path-prefix-dwarf/src/quux.rs @@ -0,0 +1,5 @@ +#![crate_type = "rlib"] + +pub fn foo() { + println!("foo"); +} |
