Skip to content

Commit 9b6cc88

Browse files
committed
fix(trim-paths): explicit remap to current dir .
On macOS in https://github.com/rust-lang/rust/blob/87e1447aa/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs#L856 when `work_dir` is remapped to an empty string, LLVM won't generate any `N_SO` and `N_OSO` symbols, resulting in corrupted debuginfo. This commit fixes that by always appending an explicit `.` when `--remap-path-prefix` remaps to relative workspace root. Also, `N_SO` symbols should be remapped correctly with this patch.
1 parent 9787229 commit 9b6cc88

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
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("=."); // explicitly remap to cwd (rustc working dir).
12341234
} else {
12351235
remap.push(pkg_root);
12361236
remap.push("=");

tests/testsuite/profile_trim_paths.rs

+13-13
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();
@@ -550,7 +550,7 @@ fn object_works_helper(run: impl Fn(&std::path::Path) -> Vec<u8>) {
550550
[COMPILING] foo v0.0.1 ([CWD])
551551
[RUNNING] `rustc [..]\
552552
-Zremap-path-scope=object \
553-
--remap-path-prefix=[CWD]= \
553+
--remap-path-prefix=[CWD]=. \
554554
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
555555
[FINISHED] dev [..]",
556556
))
@@ -578,7 +578,7 @@ fn object_works_helper(run: impl Fn(&std::path::Path) -> Vec<u8>) {
578578
// on macOS `SO` symbols are embedded in final binaries and should be trimmed.
579579
// See rust-lang/rust#117652.
580580
assert!(
581-
memchr::memmem::find(line, b" SO ").is_some(),
581+
memchr::memmem::find(line, b" SO ").is_none(),
582582
"untrimmed `SO` symbol found"
583583
)
584584
}
@@ -700,7 +700,7 @@ fn lldb_works_after_trimmed() {
700700
"\
701701
[RUNNING] `rustc [..]\
702702
-Zremap-path-scope=object \
703-
--remap-path-prefix=[CWD]= \
703+
--remap-path-prefix=[CWD]=. \
704704
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]",
705705
)
706706
.run();

0 commit comments

Comments
 (0)