Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 37 additions & 17 deletions tests/run-make/remap-path-prefix-std/rmake.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This test makes sure that we do not leak paths to the checkout
// (i.e. /checkout in CI) in the distributed `libstd` debuginfo.
// (ie. /checkout in CI) in the distributed standard library debuginfo.
// It checks all rlibs found in the target libdir, not just libstd.
//
// This test only runs on Linux and dist builder (or with `rust.remap-debuginfo = true`
// set in your `bootstrap.toml`).
Expand All @@ -24,30 +25,49 @@ fn main() {
path
};

// Find all the `libstd-.*.rlib` files under the libdir
let libstd_rlibs = shallow_find_files(&target_libdir, |p| {
// Find all rlib files under the libdir (the full standard library set)
let all_rlibs = shallow_find_files(&target_libdir, |p| {
if let Some(filename) = p.file_name()
&& let filename = filename.to_string_lossy()
&& let Some(ext) = p.extension()
&& filename.starts_with("lib")
&& ext == "rlib"
&& filename.contains('-')
{
filename.starts_with("libstd-") && filename.ends_with(".rlib")
true
} else {
false
}
});

// Assert that there is only one rlib for the `libstd`
let [libstd_rlib] = &libstd_rlibs[..] else {
unreachable!("multiple libstd rlib: {libstd_rlibs:?} in {target_libdir:?}");
};
// There must be at least one rlib (libstd itself, plus many others)
assert!(!all_rlibs.is_empty(), "no rlibs found in target libdir {target_libdir:?}");

for rlib in &all_rlibs {
// Use a stable symlink name based on the crate part (before the '-<hash>' suffix).
// e.g. "libstd-92abaa9b58c011c1.rlib" → "libstd.rlib"
let filename = rlib.file_name().unwrap().to_string_lossy();
let link_name = match filename.split_once('-') {
Some((prefix, _)) => format!("{prefix}.rlib"),
None => filename.to_string(),
};

// Symlink the original rlib to avoid absolute paths from dwarfdump itself
rfs::symlink_file(rlib, &link_name);

// Symlink the libstd rlib here to avoid absolute paths from llvm-dwarfdump own output
// and not from the debuginfo it-self
rfs::symlink_file(libstd_rlib, "libstd.rlib");
// Check that no distributed rlib leaks the checkout/source root path.
let completed = llvm_dwarfdump().input(&link_name).run();

// Check that there is only `/rustc/` paths and no `/checkout`, `/home`, or whatever
llvm_dwarfdump()
.input("libstd.rlib")
.run()
.assert_stdout_contains("/rustc/")
Comment thread
Urgau marked this conversation as resolved.
.assert_stdout_not_contains(source_root().to_string_lossy());
completed.assert_stdout_not_contains(source_root().to_string_lossy());

let stdout = completed.stdout_utf8();

// Check that remapped paths are present if the rlib has debug info.
if stdout.contains("DW_TAG_compile_unit") {
assert!(
stdout.contains("/rustc/") || stdout.contains("/rust/deps"),
"Expected remapped paths in dwarfdump output for {link_name}",
);
}
}
}
Loading