Skip to content

Commit

Permalink
fix(trim-paths): explicit remap to current dir .
Browse files Browse the repository at this point in the history
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/
  • Loading branch information
weihanglo committed Dec 8, 2023
1 parent 70d0a3c commit de33737
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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("=");
Expand Down
22 changes: 11 additions & 11 deletions tests/testsuite/profile_trim_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 [..]",
)
Expand Down Expand Up @@ -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 [..]",
))
Expand Down Expand Up @@ -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 [..]",
)
Expand Down Expand Up @@ -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 [..]",
)
Expand Down Expand Up @@ -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]`"
Expand Down Expand Up @@ -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]`"
Expand Down Expand Up @@ -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]`"
Expand Down Expand Up @@ -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]`"
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -737,7 +737,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();
Expand Down

0 comments on commit de33737

Please sign in to comment.