Skip to content

Commit

Permalink
fix(trim-paths): explicit remap to current dir .
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
weihanglo committed Dec 5, 2023
1 parent 4109b5b commit a714f44
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 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("=."); // explicitly remap to cwd (rustc working dir).
} else {
remap.push(pkg_root);
remap.push("=");
Expand Down
32 changes: 15 additions & 17 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 @@ -479,12 +479,10 @@ fn object_works() {
}

fn object_works_helper(run: impl Fn(&std::path::Path) -> Vec<u8>) {
use std::os::unix::ffi::OsStrExt;

let registry_src = paths::home().join(".cargo/registry/src");
let pkg_remap = format!("{}/[..]/bar-0.0.1=bar-0.0.1", registry_src.display());
let rust_src = "/lib/rustc/src/rust".as_bytes();
let registry_src_bytes = registry_src.as_os_str().as_bytes();
let registry_src_bytes = registry_src.as_os_str().as_encoded_bytes();

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

let pkg_root = p.root();
let pkg_root = pkg_root.as_os_str().as_bytes();
let pkg_root = pkg_root.as_os_str().as_encoded_bytes();

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

Expand Down Expand Up @@ -549,7 +547,7 @@ fn object_works_helper(run: impl Fn(&std::path::Path) -> Vec<u8>) {
[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 [..]",
))
Expand Down Expand Up @@ -577,7 +575,7 @@ fn object_works_helper(run: impl Fn(&std::path::Path) -> Vec<u8>) {
// on macOS `SO` symbols are embedded in final binaries and should be trimmed.
// See rust-lang/rust#117652.
assert!(
memchr::memmem::find(line, b" SO ").is_some(),
memchr::memmem::find(line, b" SO ").is_none(),
"untrimmed `SO` symbol found"
)
}
Expand Down Expand Up @@ -699,7 +697,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 a714f44

Please sign in to comment.