Skip to content

Commit ba1851e

Browse files
committed
Auto merge of #156570 - paradoxicalguy:test-extend-rmake-clean, r=<try>
tests: extend remap-path-prefix-std to all stdlib rlibs try-job: dist-i586-gnu-i586-i686-musl
2 parents 5d48869 + 6fe13d9 commit ba1851e

1 file changed

Lines changed: 58 additions & 17 deletions

File tree

  • tests/run-make/remap-path-prefix-std
Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// This test makes sure that we do not leak paths to the checkout
2-
// (i.e. /checkout in CI) in the distributed `libstd` debuginfo.
2+
// (ie. /checkout in CI) in the distributed standard library debuginfo.
3+
// It checks all rlibs found in the target libdir, not just libstd.
34
//
45
// This test only runs on Linux and dist builder (or with `rust.remap-debuginfo = true`
56
// set in your `bootstrap.toml`).
@@ -24,30 +25,70 @@ fn main() {
2425
path
2526
};
2627

27-
// Find all the `libstd-.*.rlib` files under the libdir
28-
let libstd_rlibs = shallow_find_files(&target_libdir, |p| {
28+
// Find all rlib files under the libdir (the full standard library set)
29+
let all_rlibs = shallow_find_files(&target_libdir, |p| {
2930
if let Some(filename) = p.file_name()
3031
&& let filename = filename.to_string_lossy()
32+
&& let Some(ext) = p.extension()
33+
&& filename.starts_with("lib")
34+
&& ext == "rlib"
35+
&& filename.contains('-')
3136
{
32-
filename.starts_with("libstd-") && filename.ends_with(".rlib")
37+
true
3338
} else {
3439
false
3540
}
3641
});
3742

38-
// Assert that there is only one rlib for the `libstd`
39-
let [libstd_rlib] = &libstd_rlibs[..] else {
40-
unreachable!("multiple libstd rlib: {libstd_rlibs:?} in {target_libdir:?}");
41-
};
43+
// There must be at least one rlib (libstd itself, plus many others)
44+
assert!(!all_rlibs.is_empty(), "no rlibs found in target libdir {target_libdir:?}");
45+
46+
for rlib in &all_rlibs {
47+
// Use a stable symlink name based on the crate part (before the '-<hash>' suffix).
48+
// e.g. "libstd-92abaa9b58c011c1.rlib" → "libstd.rlib"
49+
let filename = rlib.file_name().unwrap().to_string_lossy();
50+
let link_name = match filename.split_once('-') {
51+
Some((prefix, _)) => format!("{prefix}.rlib"),
52+
None => filename.to_string(),
53+
};
4254

43-
// Symlink the libstd rlib here to avoid absolute paths from llvm-dwarfdump own output
44-
// and not from the debuginfo it-self
45-
rfs::symlink_file(libstd_rlib, "libstd.rlib");
55+
// Symlink the original rlib to avoid absolute paths from dwarfdump itself
56+
rfs::symlink_file(rlib, &link_name);
57+
58+
// Check that no distributed rlib leaks the checkout/source root path.
59+
let completed = llvm_dwarfdump().input(&link_name).run_unchecked();
60+
if !completed.status().success() {
61+
eprintln!("dwarfdump failed on {link_name}: exit status {:?}", completed.status());
62+
panic!("llvm-dwarfdump failed for {link_name}");
63+
}
64+
65+
let stdout = completed.stdout_utf8();
66+
let source_root = source_root();
67+
let root = source_root.to_string_lossy();
68+
69+
if let Some((i, _)) =
70+
stdout.lines().enumerate().find(|(_, line)| line.contains(root.as_ref()))
71+
{
72+
let lines: Vec<_> = stdout.lines().collect();
4673

47-
// Check that there is only `/rustc/` paths and no `/checkout`, `/home`, or whatever
48-
llvm_dwarfdump()
49-
.input("libstd.rlib")
50-
.run()
51-
.assert_stdout_contains("/rustc/")
52-
.assert_stdout_not_contains(source_root().to_string_lossy());
74+
let start = i.saturating_sub(2);
75+
let end = (i + 3).min(lines.len());
76+
77+
eprintln!("leaked source-root path found in {link_name}:");
78+
79+
for line in &lines[start..end] {
80+
eprintln!("{line}");
81+
}
82+
83+
panic!("found leaked source-root path in {link_name}");
84+
}
85+
86+
// Check that remapped paths are present if the rlib has debug info.
87+
if stdout.contains("DW_TAG_compile_unit") {
88+
assert!(
89+
stdout.contains("/rustc/") || stdout.contains("/rust/deps"),
90+
"Expected remapped paths in dwarfdump output for {link_name}",
91+
);
92+
}
93+
}
5394
}

0 commit comments

Comments
 (0)