Skip to content

Commit beab94c

Browse files
committed
test(trim-paths): add test for each split-debuginfo options
Also demonstarte that on Linux with split-debuginfo on the remap is broken
1 parent 985d49b commit beab94c

File tree

1 file changed

+81
-31
lines changed

1 file changed

+81
-31
lines changed

tests/testsuite/profile_trim_paths.rs

Lines changed: 81 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -453,33 +453,65 @@ fn diagnostics_works() {
453453
}
454454

455455
#[cfg(target_os = "macos")]
456-
#[cargo_test(requires_nm, nightly, reason = "-Zremap-path-scope is unstable")]
457-
fn object_works() {
458-
object_works_helper(|path| {
456+
mod object_works {
457+
use super::*;
458+
459+
fn inspect_debuginfo(path: &std::path::Path) -> Vec<u8> {
459460
std::process::Command::new("nm")
460461
.arg("-pa")
461462
.arg(path)
462463
.output()
463464
.expect("nm works")
464465
.stdout
465-
})
466+
}
467+
468+
#[cargo_test(requires_nm, nightly, reason = "-Zremap-path-scope is unstable")]
469+
fn with_split_debuginfo_off() {
470+
object_works_helper("off", inspect_debuginfo);
471+
}
472+
473+
#[cargo_test(requires_nm, nightly, reason = "-Zremap-path-scope is unstable")]
474+
fn with_split_debuginfo_packed() {
475+
object_works_helper("packed", inspect_debuginfo);
476+
}
477+
478+
#[cargo_test(requires_nm, nightly, reason = "-Zremap-path-scope is unstable")]
479+
fn with_split_debuginfo_unpacked() {
480+
object_works_helper("packed", inspect_debuginfo);
481+
}
466482
}
467483

468484
#[cfg(target_os = "linux")]
469-
#[cargo_test(requires_readelf, nightly, reason = "-Zremap-path-scope is unstable")]
470-
fn object_works() {
471-
object_works_helper(|path| {
485+
mod object_works {
486+
use super::*;
487+
488+
fn inspect_debuginfo(path: &std::path::Path) -> Vec<u8> {
472489
std::process::Command::new("readelf")
473490
.arg("-wi")
474491
.arg(path)
475492
.output()
476493
.expect("readelf works")
477494
.stdout
478-
})
495+
}
496+
497+
#[cargo_test(requires_readelf, nightly, reason = "-Zremap-path-scope is unstable")]
498+
fn with_split_debuginfo_off() {
499+
object_works_helper("off", inspect_debuginfo);
500+
}
501+
502+
#[cargo_test(requires_readelf, nightly, reason = "-Zremap-path-scope is unstable")]
503+
fn with_split_debuginfo_packed() {
504+
object_works_helper("packed", inspect_debuginfo);
505+
}
506+
507+
#[cargo_test(requires_readelf, nightly, reason = "-Zremap-path-scope is unstable")]
508+
fn with_split_debuginfo_unpacked() {
509+
object_works_helper("packed", inspect_debuginfo);
510+
}
479511
}
480512

481513
#[cfg(unix)]
482-
fn object_works_helper(run: impl Fn(&std::path::Path) -> Vec<u8>) {
514+
fn object_works_helper(split_debuginfo: &str, run: impl Fn(&std::path::Path) -> Vec<u8>) {
483515
use std::os::unix::ffi::OsStrExt;
484516

485517
let registry_src = paths::home().join(".cargo/registry/src");
@@ -495,14 +527,19 @@ fn object_works_helper(run: impl Fn(&std::path::Path) -> Vec<u8>) {
495527
let p = project()
496528
.file(
497529
"Cargo.toml",
498-
r#"
530+
&format!(
531+
r#"
499532
[package]
500533
name = "foo"
501534
version = "0.0.1"
502535
503536
[dependencies]
504537
bar = "0.0.1"
505-
"#,
538+
539+
[profile.dev]
540+
split-debuginfo = "{split_debuginfo}"
541+
"#
542+
),
506543
)
507544
.file("src/main.rs", "fn main() { bar::f(); }")
508545
.build();
@@ -530,14 +567,14 @@ fn object_works_helper(run: impl Fn(&std::path::Path) -> Vec<u8>) {
530567
.with_stderr(&format!(
531568
"\
532569
[COMPILING] bar v0.0.1
533-
[RUNNING] `rustc [..]\
570+
[RUNNING] `rustc [..]-C split-debuginfo={split_debuginfo} [..]\
534571
-Zremap-path-scope=object \
535572
--remap-path-prefix={pkg_remap} \
536573
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
537574
[COMPILING] foo v0.0.1 ([CWD])
538-
[RUNNING] `rustc [..]\
575+
[RUNNING] `rustc [..]-C split-debuginfo={split_debuginfo} [..]\
539576
-Zremap-path-scope=object \
540-
--remap-path-prefix=[CWD]= \
577+
--remap-path-prefix=[CWD]=. \
541578
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
542579
[FINISHED] dev [..]",
543580
))
@@ -547,31 +584,44 @@ fn object_works_helper(run: impl Fn(&std::path::Path) -> Vec<u8>) {
547584
assert!(bin_path.is_file());
548585
let stdout = run(&bin_path);
549586
assert!(memchr::memmem::find(&stdout, rust_src).is_none());
550-
if cfg!(target_os = "macos") {
551-
for line in stdout.split(|c| c == &b'\n') {
552-
let registry = memchr::memmem::find(line, registry_src_bytes).is_none();
553-
let local = memchr::memmem::find(line, pkg_root).is_none();
554-
if registry && local {
555-
continue;
556-
}
587+
for line in stdout.split(|c| c == &b'\n') {
588+
let registry = memchr::memmem::find(line, registry_src_bytes).is_none();
589+
let local = memchr::memmem::find(line, pkg_root).is_none();
590+
if registry && local {
591+
continue;
592+
}
557593

594+
#[cfg(target_os = "macos")]
595+
{
596+
// `OSO` symbols can't be trimmed at this moment.
597+
// See <https://github.com/rust-lang/rust/issues/116948#issuecomment-1793617018>
558598
if memchr::memmem::find(line, b" OSO ").is_some() {
559-
// `OSO` symbols can't be trimmed at this moment.
560-
// See <https://github.com/rust-lang/rust/issues/116948#issuecomment-1793617018>
561-
// TODO: Change to `is_none()` once the issue is resolved.
562599
continue;
563600
}
564601

565602
// on macOS `SO` symbols are embedded in final binaries and should be trimmed.
566603
// See rust-lang/rust#117652.
567-
assert!(
568-
memchr::memmem::find(line, b" SO ").is_some(),
569-
"untrimmed `SO` symbol found"
570-
)
604+
if memchr::memmem::find(line, b" SO ").is_some() {
605+
continue;
606+
}
607+
}
608+
609+
#[cfg(target_os = "linux")]
610+
{
611+
// There is a bug in rustc `-Zremap-path-scope`.
612+
// See rust-lang/rust/pull/118518
613+
if memchr::memmem::find(line, b"DW_AT_comp_dir").is_some() {
614+
continue;
615+
}
616+
if memchr::memmem::find(line, b"DW_AT_GNU_dwo_name").is_some() {
617+
continue;
618+
}
571619
}
572-
} else {
573-
assert!(memchr::memmem::find(&stdout, registry_src_bytes).is_none());
574-
assert!(memchr::memmem::find(&stdout, pkg_root).is_none());
620+
621+
panic!(
622+
"unexpected untrimmed symbol: {}",
623+
String::from_utf8(line.into()).unwrap()
624+
);
575625
}
576626
}
577627

0 commit comments

Comments
 (0)