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,43 @@ 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"
3135 {
32- filename . starts_with ( "libstd-" ) && filename . ends_with ( ".rlib" )
36+ true
3337 } else {
3438 false
3539 }
3640 } ) ;
3741
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- } ;
42+ // There must be at least one rlib (libstd itself, plus many others)
43+ assert ! ( !all_rlibs. is_empty( ) , "no rlibs found in target libdir {target_libdir:?}" ) ;
44+
45+ for rlib in & all_rlibs {
46+ // Use a stable symlink name based on the crate part (before the '-<hash>' suffix).
47+ // e.g. "libstd-92abaa9b58c011c1.rlib" → "libstd.rlib"
48+ let filename = rlib. file_name ( ) . unwrap ( ) . to_string_lossy ( ) ;
49+ let link_name = match filename. split_once ( '-' ) {
50+ Some ( ( prefix, _) ) => format ! ( "{prefix}.rlib" ) ,
51+ None => filename. to_string ( ) ,
52+ } ;
53+
54+ // Symlink the original rlib to avoid absolute paths from dwarfdump itself
55+ rfs:: symlink_file ( rlib, & link_name) ;
4256
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" ) ;
57+ // Check that no distributed rlib leaks the checkout/source root path.
58+ let completed = llvm_dwarfdump ( ) . input ( & link_name) . run ( ) ;
4659
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 ( ) ) ;
60+ completed. assert_stdout_not_contains ( source_root ( ) . to_string_lossy ( ) ) ;
61+
62+ // Check that we have `/rustc` in the output if the rlib has any debug info.
63+ if completed. stdout_utf8 ( ) . contains ( "DW_TAG_compile_unit" ) {
64+ completed. assert_stdout_contains ( "/rustc" ) ;
65+ }
66+ }
5367}
0 commit comments