Skip to content

Commit a714f44

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, `SO` symbols should be remapped correctly.
1 parent 4109b5b commit a714f44

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

src/cargo/core/compiler/mod.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 15 additions & 17 deletions
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();
@@ -479,12 +479,10 @@ fn object_works() {
479479
}
480480

481481
fn object_works_helper(run: impl Fn(&std::path::Path) -> Vec<u8>) {
482-
use std::os::unix::ffi::OsStrExt;
483-
484482
let registry_src = paths::home().join(".cargo/registry/src");
485483
let pkg_remap = format!("{}/[..]/bar-0.0.1=bar-0.0.1", registry_src.display());
486484
let rust_src = "/lib/rustc/src/rust".as_bytes();
487-
let registry_src_bytes = registry_src.as_os_str().as_bytes();
485+
let registry_src_bytes = registry_src.as_os_str().as_encoded_bytes();
488486

489487
Package::new("bar", "0.0.1")
490488
.file("Cargo.toml", &basic_manifest("bar", "0.0.1"))
@@ -507,7 +505,7 @@ fn object_works_helper(run: impl Fn(&std::path::Path) -> Vec<u8>) {
507505
.build();
508506

509507
let pkg_root = p.root();
510-
let pkg_root = pkg_root.as_os_str().as_bytes();
508+
let pkg_root = pkg_root.as_os_str().as_encoded_bytes();
511509

512510
p.cargo("build").run();
513511

@@ -549,7 +547,7 @@ fn object_works_helper(run: impl Fn(&std::path::Path) -> Vec<u8>) {
549547
[COMPILING] foo v0.0.1 ([CWD])
550548
[RUNNING] `rustc [..]\
551549
-Zremap-path-scope=object \
552-
--remap-path-prefix=[CWD]= \
550+
--remap-path-prefix=[CWD]=. \
553551
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
554552
[FINISHED] dev [..]",
555553
))
@@ -577,7 +575,7 @@ fn object_works_helper(run: impl Fn(&std::path::Path) -> Vec<u8>) {
577575
// on macOS `SO` symbols are embedded in final binaries and should be trimmed.
578576
// See rust-lang/rust#117652.
579577
assert!(
580-
memchr::memmem::find(line, b" SO ").is_some(),
578+
memchr::memmem::find(line, b" SO ").is_none(),
581579
"untrimmed `SO` symbol found"
582580
)
583581
}
@@ -699,7 +697,7 @@ fn lldb_works_after_trimmed() {
699697
"\
700698
[RUNNING] `rustc [..]\
701699
-Zremap-path-scope=object \
702-
--remap-path-prefix=[CWD]= \
700+
--remap-path-prefix=[CWD]=. \
703701
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]",
704702
)
705703
.run();

0 commit comments

Comments
 (0)