Skip to content

Commit d8ee768

Browse files
committed
tests: check std rmeta for local path leaks
The current dwarfdump checks cannot see `.rmeta` leaks: * The compiler keeps unremapped local paths in metadata unless the remap scope is `all` (see issue 159621) * std ships metadata as separate `.rmeta` via `-Zembed-metadata=no` so the leak does not even appear in the rlibs This commit enhances to also check rmeta files.
1 parent 2ba4d38 commit d8ee768

1 file changed

Lines changed: 25 additions & 7 deletions

File tree

  • tests/run-make/remap-path-prefix-std

tests/run-make/remap-path-prefix-std/rmake.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ fn main() {
4343
// There must be at least one rlib (libstd itself, plus many others)
4444
assert!(!all_rlibs.is_empty(), "no rlibs found in target libdir {target_libdir:?}");
4545

46+
let source_root = source_root();
47+
let cargo_home = std::env::var("CARGO_HOME").map(PathBuf::from);
48+
let mut local_roots = vec![("source-root", source_root.to_string_lossy())];
49+
if let Ok(cargo_home) = &cargo_home {
50+
local_roots.push(("cargo-home", cargo_home.to_string_lossy()));
51+
}
52+
4653
for rlib in &all_rlibs {
4754
// Use a stable symlink name based on the crate part (before the '-<hash>' suffix).
4855
// e.g. "libstd-92abaa9b58c011c1.rlib" → "libstd.rlib"
@@ -63,13 +70,6 @@ fn main() {
6370
}
6471

6572
let stdout = completed.stdout_utf8();
66-
let source_root = source_root();
67-
68-
let cargo_home = std::env::var("CARGO_HOME").map(PathBuf::from);
69-
let mut local_roots = vec![("source-root", source_root.to_string_lossy())];
70-
if let Ok(cargo_home) = &cargo_home {
71-
local_roots.push(("cargo-home", cargo_home.to_string_lossy()));
72-
}
7373

7474
for (kind, root) in &local_roots {
7575
if let Some((i, _)) =
@@ -98,4 +98,22 @@ fn main() {
9898
);
9999
}
100100
}
101+
102+
// `-Zembed-metadata=no` creates separate rmeta that may leak absolute paths
103+
let all_rmetas = shallow_find_files(&target_libdir, |p| {
104+
p.extension().is_some_and(|ext| ext == "rmeta")
105+
});
106+
assert!(!all_rmetas.is_empty(), "no rmeta files found in target libdir {target_libdir:?}");
107+
108+
for rmeta in &all_rmetas {
109+
let filename = rmeta.file_name().unwrap().to_string_lossy();
110+
let bytes = rfs::read(rmeta);
111+
112+
for (kind, root) in &local_roots {
113+
let root = root.as_bytes();
114+
if bytes.windows(root.len()).any(|window| window == root) {
115+
panic!("found leaked {kind} path in {filename}");
116+
}
117+
}
118+
}
101119
}

0 commit comments

Comments
 (0)