Skip to content

Commit 39c6aa5

Browse files
committed
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/
1 parent 5a1ae7a commit 39c6aa5

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/cargo/core/compiler/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ fn trim_paths_args(
12301230
// * path dependencies outside workspace root directory
12311231
if is_local && pkg_root.strip_prefix(ws_root).is_ok() {
12321232
remap.push(ws_root);
1233-
remap.push("="); // empty to remap to relative paths.
1233+
remap.push("=."); // remap to relative rustc work dir explicitly
12341234
} else {
12351235
remap.push(pkg_root);
12361236
remap.push("=");

tests/testsuite/profile_trim_paths.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fn release_profile_default_to_object() {
8383
[COMPILING] foo v0.0.1 ([CWD])
8484
[RUNNING] `rustc [..]\
8585
-Zremap-path-scope=object \
86-
--remap-path-prefix=[CWD]= \
86+
--remap-path-prefix=[CWD]=. \
8787
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
8888
[FINISHED] release [..]",
8989
)
@@ -121,7 +121,7 @@ fn one_option() {
121121
[COMPILING] foo v0.0.1 ([CWD])
122122
[RUNNING] `rustc [..]\
123123
-Zremap-path-scope={option} \
124-
--remap-path-prefix=[CWD]= \
124+
--remap-path-prefix=[CWD]=. \
125125
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
126126
[FINISHED] dev [..]",
127127
))
@@ -158,7 +158,7 @@ fn multiple_options() {
158158
[COMPILING] foo v0.0.1 ([CWD])
159159
[RUNNING] `rustc [..]\
160160
-Zremap-path-scope=diagnostics,macro,object \
161-
--remap-path-prefix=[CWD]= \
161+
--remap-path-prefix=[CWD]=. \
162162
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
163163
[FINISHED] dev [..]",
164164
)
@@ -193,7 +193,7 @@ fn profile_merge_works() {
193193
[COMPILING] foo v0.0.1 ([CWD])
194194
[RUNNING] `rustc [..]\
195195
-Zremap-path-scope=diagnostics \
196-
--remap-path-prefix=[CWD]= \
196+
--remap-path-prefix=[CWD]=. \
197197
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
198198
[FINISHED] custom [..]",
199199
)
@@ -243,7 +243,7 @@ fn registry_dependency() {
243243
[COMPILING] foo v0.0.1 ([CWD])
244244
[RUNNING] `rustc [..]\
245245
-Zremap-path-scope=object \
246-
--remap-path-prefix=[CWD]= \
246+
--remap-path-prefix=[CWD]=. \
247247
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
248248
[FINISHED] dev [..]
249249
[RUNNING] `target/debug/foo[EXE]`"
@@ -297,7 +297,7 @@ fn git_dependency() {
297297
[COMPILING] foo v0.0.1 ([CWD])
298298
[RUNNING] `rustc [..]\
299299
-Zremap-path-scope=object \
300-
--remap-path-prefix=[CWD]= \
300+
--remap-path-prefix=[CWD]=. \
301301
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
302302
[FINISHED] dev [..]
303303
[RUNNING] `target/debug/foo[EXE]`"
@@ -338,12 +338,12 @@ fn path_dependency() {
338338
[COMPILING] bar v0.0.1 ([..]/cocktail-bar)
339339
[RUNNING] `rustc [..]\
340340
-Zremap-path-scope=object \
341-
--remap-path-prefix=[CWD]= \
341+
--remap-path-prefix=[CWD]=. \
342342
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
343343
[COMPILING] foo v0.0.1 ([CWD])
344344
[RUNNING] `rustc [..]\
345345
-Zremap-path-scope=object \
346-
--remap-path-prefix=[CWD]= \
346+
--remap-path-prefix=[CWD]=. \
347347
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
348348
[FINISHED] dev [..]
349349
[RUNNING] `target/debug/foo[EXE]`"
@@ -392,7 +392,7 @@ fn path_dependency_outside_workspace() {
392392
[COMPILING] foo v0.0.1 ([CWD])
393393
[RUNNING] `rustc [..]\
394394
-Zremap-path-scope=object \
395-
--remap-path-prefix=[CWD]= \
395+
--remap-path-prefix=[CWD]=. \
396396
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
397397
[FINISHED] dev [..]
398398
[RUNNING] `target/debug/foo[EXE]`"
@@ -446,7 +446,7 @@ fn diagnostics_works() {
446446
"\
447447
[RUNNING] [..]rustc [..]\
448448
-Zremap-path-scope=diagnostics \
449-
--remap-path-prefix=[CWD]= \
449+
--remap-path-prefix=[CWD]=. \
450450
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]",
451451
)
452452
.run();
@@ -574,7 +574,7 @@ fn object_works_helper(split_debuginfo: &str, run: impl Fn(&std::path::Path) ->
574574
[COMPILING] foo v0.0.1 ([CWD])
575575
[RUNNING] `rustc [..]\
576576
-Zremap-path-scope=object \
577-
--remap-path-prefix=[CWD]= \
577+
--remap-path-prefix=[CWD]=. \
578578
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
579579
[FINISHED] dev [..]",
580580
))
@@ -724,7 +724,7 @@ fn lldb_works_after_trimmed() {
724724
"\
725725
[RUNNING] `rustc [..]\
726726
-Zremap-path-scope=object \
727-
--remap-path-prefix=[CWD]= \
727+
--remap-path-prefix=[CWD]=. \
728728
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]",
729729
)
730730
.run();

0 commit comments

Comments
 (0)