Skip to content

Commit 0124d28

Browse files
committed
Auto merge of #13118 - weihanglo:object-works-macos, r=epage
test(trim-paths): assert `OSO` and `SO` cannot be trimmed
2 parents a5fa676 + a4c607c commit 0124d28

File tree

1 file changed

+49
-8
lines changed

1 file changed

+49
-8
lines changed

tests/testsuite/profile_trim_paths.rs

+49-8
Original file line numberDiff line numberDiff line change
@@ -452,18 +452,35 @@ fn diagnostics_works() {
452452
.run();
453453
}
454454

455+
#[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| {
459+
std::process::Command::new("nm")
460+
.arg("-pa")
461+
.arg(path)
462+
.output()
463+
.expect("nm works")
464+
.stdout
465+
})
466+
}
467+
455468
#[cfg(target_os = "linux")]
456469
#[cargo_test(requires_readelf, nightly, reason = "-Zremap-path-scope is unstable")]
457470
fn object_works() {
458-
use std::os::unix::ffi::OsStrExt;
459-
460-
let run_readelf = |path| {
471+
object_works_helper(|path| {
461472
std::process::Command::new("readelf")
462473
.arg("-wi")
463474
.arg(path)
464475
.output()
465476
.expect("readelf works")
466-
};
477+
.stdout
478+
})
479+
}
480+
481+
#[cfg(unix)]
482+
fn object_works_helper(run: impl Fn(&std::path::Path) -> Vec<u8>) {
483+
use std::os::unix::ffi::OsStrExt;
467484

468485
let registry_src = paths::home().join(".cargo/registry/src");
469486
let pkg_remap = format!("{}/[..]/bar-0.0.1=bar-0.0.1", registry_src.display());
@@ -497,7 +514,7 @@ fn object_works() {
497514

498515
let bin_path = p.bin("foo");
499516
assert!(bin_path.is_file());
500-
let stdout = run_readelf(bin_path).stdout;
517+
let stdout = run(&bin_path);
501518
// TODO: re-enable this check when rustc bootstrap disables remapping
502519
// <https://github.com/rust-lang/cargo/pull/12625#discussion_r1371714791>
503520
// assert!(memchr::memmem::find(&stdout, rust_src).is_some());
@@ -541,10 +558,34 @@ fn object_works() {
541558

542559
let bin_path = p.bin("foo");
543560
assert!(bin_path.is_file());
544-
let stdout = run_readelf(bin_path).stdout;
561+
let stdout = run(&bin_path);
545562
assert!(memchr::memmem::find(&stdout, rust_src).is_none());
546-
assert!(memchr::memmem::find(&stdout, registry_src_bytes).is_none());
547-
assert!(memchr::memmem::find(&stdout, pkg_root).is_none());
563+
if cfg!(target_os = "macos") {
564+
for line in stdout.split(|c| c == &b'\n') {
565+
let registry = memchr::memmem::find(line, registry_src_bytes).is_none();
566+
let local = memchr::memmem::find(line, pkg_root).is_none();
567+
if registry && local {
568+
continue;
569+
}
570+
571+
if memchr::memmem::find(line, b" OSO ").is_some() {
572+
// `OSO` symbols can't be trimmed at this moment.
573+
// See <https://github.com/rust-lang/rust/issues/116948#issuecomment-1793617018>
574+
// TODO: Change to `is_none()` once the issue is resolved.
575+
continue;
576+
}
577+
578+
// on macOS `SO` symbols are embedded in final binaries and should be trimmed.
579+
// See rust-lang/rust#117652.
580+
assert!(
581+
memchr::memmem::find(line, b" SO ").is_some(),
582+
"untrimmed `SO` symbol found"
583+
)
584+
}
585+
} else {
586+
assert!(memchr::memmem::find(&stdout, registry_src_bytes).is_none());
587+
assert!(memchr::memmem::find(&stdout, pkg_root).is_none());
588+
}
548589
}
549590

550591
// TODO: might want to move to test/testsuite/build_script.rs once stabilized.

0 commit comments

Comments
 (0)