From 39c6aa559adbb50d470e5adcf6a9c5ea32a5bd54 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Fri, 8 Dec 2023 13:52:40 -0500 Subject: [PATCH] fix(trim-paths): explicit remap to current dir `.` In https://github.com/rust-lang/rust/blob/87e1447aa/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs#L856 when the remap result of `work_dir` is an empty string, LLVM won't generate some symbols for root debuginfo node. For example, `N_SO` and `N_OSO` on macOS, or `DW_AT_comp_dir` on Linux when debuginfo is splitted. Precisely, it is observed that when the `DIFile` of compile unit was provied with an empty compilation `Directory` string, LLVM would not emit those symbols for the root DI node. This behavior is not desired, resulting in corrupted debuginfo and degrading debugging experience. This is might not be a bug of `--remap-path-prefix` in rustc, since `-fdebug-prefix-map` in clang 16 could have the same result (`DW_AT_comp_dir` is gone when `work_dir` is remapped to an empty string). However, in gcc 12 `fdebug-prefix-map` will return an absolute work_dir when an empty string occurs. To not bother whether this needs to be fixed in rustc or not, let's fix it by always appending an explicit `.` when `--remap-path-prefix` remaps to relative workspace root a.k.a. where rustc is invoking. For more on gcc/clang remap options, see https://reproducible-builds.org/docs/build-path/ --- src/cargo/core/compiler/mod.rs | 2 +- tests/testsuite/profile_trim_paths.rs | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index 14aa98148317..4b53a6cb8251 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -1230,7 +1230,7 @@ fn trim_paths_args( // * path dependencies outside workspace root directory if is_local && pkg_root.strip_prefix(ws_root).is_ok() { remap.push(ws_root); - remap.push("="); // empty to remap to relative paths. + remap.push("=."); // remap to relative rustc work dir explicitly } else { remap.push(pkg_root); remap.push("="); diff --git a/tests/testsuite/profile_trim_paths.rs b/tests/testsuite/profile_trim_paths.rs index 297e6dbd6a44..5cefde0f9dc5 100644 --- a/tests/testsuite/profile_trim_paths.rs +++ b/tests/testsuite/profile_trim_paths.rs @@ -83,7 +83,7 @@ fn release_profile_default_to_object() { [COMPILING] foo v0.0.1 ([CWD]) [RUNNING] `rustc [..]\ -Zremap-path-scope=object \ - --remap-path-prefix=[CWD]= \ + --remap-path-prefix=[CWD]=. \ --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] [FINISHED] release [..]", ) @@ -121,7 +121,7 @@ fn one_option() { [COMPILING] foo v0.0.1 ([CWD]) [RUNNING] `rustc [..]\ -Zremap-path-scope={option} \ - --remap-path-prefix=[CWD]= \ + --remap-path-prefix=[CWD]=. \ --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] [FINISHED] dev [..]", )) @@ -158,7 +158,7 @@ fn multiple_options() { [COMPILING] foo v0.0.1 ([CWD]) [RUNNING] `rustc [..]\ -Zremap-path-scope=diagnostics,macro,object \ - --remap-path-prefix=[CWD]= \ + --remap-path-prefix=[CWD]=. \ --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] [FINISHED] dev [..]", ) @@ -193,7 +193,7 @@ fn profile_merge_works() { [COMPILING] foo v0.0.1 ([CWD]) [RUNNING] `rustc [..]\ -Zremap-path-scope=diagnostics \ - --remap-path-prefix=[CWD]= \ + --remap-path-prefix=[CWD]=. \ --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] [FINISHED] custom [..]", ) @@ -243,7 +243,7 @@ fn registry_dependency() { [COMPILING] foo v0.0.1 ([CWD]) [RUNNING] `rustc [..]\ -Zremap-path-scope=object \ - --remap-path-prefix=[CWD]= \ + --remap-path-prefix=[CWD]=. \ --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] [FINISHED] dev [..] [RUNNING] `target/debug/foo[EXE]`" @@ -297,7 +297,7 @@ fn git_dependency() { [COMPILING] foo v0.0.1 ([CWD]) [RUNNING] `rustc [..]\ -Zremap-path-scope=object \ - --remap-path-prefix=[CWD]= \ + --remap-path-prefix=[CWD]=. \ --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] [FINISHED] dev [..] [RUNNING] `target/debug/foo[EXE]`" @@ -338,12 +338,12 @@ fn path_dependency() { [COMPILING] bar v0.0.1 ([..]/cocktail-bar) [RUNNING] `rustc [..]\ -Zremap-path-scope=object \ - --remap-path-prefix=[CWD]= \ + --remap-path-prefix=[CWD]=. \ --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] [COMPILING] foo v0.0.1 ([CWD]) [RUNNING] `rustc [..]\ -Zremap-path-scope=object \ - --remap-path-prefix=[CWD]= \ + --remap-path-prefix=[CWD]=. \ --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] [FINISHED] dev [..] [RUNNING] `target/debug/foo[EXE]`" @@ -392,7 +392,7 @@ fn path_dependency_outside_workspace() { [COMPILING] foo v0.0.1 ([CWD]) [RUNNING] `rustc [..]\ -Zremap-path-scope=object \ - --remap-path-prefix=[CWD]= \ + --remap-path-prefix=[CWD]=. \ --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] [FINISHED] dev [..] [RUNNING] `target/debug/foo[EXE]`" @@ -446,7 +446,7 @@ fn diagnostics_works() { "\ [RUNNING] [..]rustc [..]\ -Zremap-path-scope=diagnostics \ - --remap-path-prefix=[CWD]= \ + --remap-path-prefix=[CWD]=. \ --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]", ) .run(); @@ -574,7 +574,7 @@ fn object_works_helper(split_debuginfo: &str, run: impl Fn(&std::path::Path) -> [COMPILING] foo v0.0.1 ([CWD]) [RUNNING] `rustc [..]\ -Zremap-path-scope=object \ - --remap-path-prefix=[CWD]= \ + --remap-path-prefix=[CWD]=. \ --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] [FINISHED] dev [..]", )) @@ -724,7 +724,7 @@ fn lldb_works_after_trimmed() { "\ [RUNNING] `rustc [..]\ -Zremap-path-scope=object \ - --remap-path-prefix=[CWD]= \ + --remap-path-prefix=[CWD]=. \ --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]", ) .run();