| 
12 | 12 | //! present.  | 
13 | 13 | //!  | 
14 | 14 | //! Some CI jobs try to run faster by disabling debug assertions (through setting  | 
15 |  | -//! `NO_DEBUG_ASSERTIONS=1`). If debug assertions are disabled, then we can check for the absence of  | 
16 |  | -//! additional `usize` formatting and padding related symbols.  | 
 | 15 | +//! `NO_DEBUG_ASSERTIONS=1`). If std debug assertions are disabled, then we can check for the  | 
 | 16 | +//! absence of additional `usize` formatting and padding related symbols.  | 
 | 17 | +
  | 
 | 18 | +// ignore-tidy-linelength  | 
17 | 19 | 
 
  | 
18 | 20 | //@ ignore-cross-compile  | 
19 | 21 | 
 
  | 
20 |  | -use run_make_support::artifact_names::bin_name;  | 
 | 22 | +// NOTE: against the GCC codegen backend, the assertion  | 
 | 23 | +// `object_contains_any_symbol_substring(&expect_panic_symbols, &panic_syms)` fails.  | 
 | 24 | +//@ ignore-backends: gcc  | 
 | 25 | + | 
 | 26 | +use std::path::Path;  | 
 | 27 | + | 
21 | 28 | use run_make_support::env::std_debug_assertions_enabled;  | 
22 |  | -use run_make_support::rustc;  | 
 | 29 | +use run_make_support::llvm::{llvm_filecheck, llvm_pdbutil};  | 
23 | 30 | use run_make_support::symbols::object_contains_any_symbol_substring;  | 
 | 31 | +use run_make_support::{bin_name, is_windows_msvc, rfs, rustc};  | 
24 | 32 | 
 
  | 
25 | 33 | fn main() {  | 
26 |  | -    rustc().input("main.rs").opt().run();  | 
27 | 34 |     // panic machinery identifiers, these should not appear in the final binary  | 
28 | 35 |     let mut panic_syms = vec!["panic_bounds_check", "Debug"];  | 
29 | 36 |     if std_debug_assertions_enabled() {  | 
30 | 37 |         // if debug assertions are allowed, we need to allow these,  | 
31 | 38 |         // otherwise, add them to the list of symbols to deny.  | 
32 | 39 |         panic_syms.extend_from_slice(&["panicking", "panic_fmt", "pad_integral", "Display"]);  | 
33 | 40 |     }  | 
34 |  | -    assert!(!object_contains_any_symbol_substring(bin_name("main"), &panic_syms));  | 
 | 41 | + | 
 | 42 | +    let expect_no_panic_symbols = bin_name("expect_no_panic_symbols");  | 
 | 43 | +    let expect_no_panic_symbols = Path::new(&expect_no_panic_symbols);  | 
 | 44 | +    rustc().input("main.rs").output(&expect_no_panic_symbols).opt().run();  | 
 | 45 | + | 
 | 46 | +    let expect_panic_symbols = bin_name("expect_panic_symbols");  | 
 | 47 | +    let expect_panic_symbols = Path::new(&expect_panic_symbols);  | 
 | 48 | +    rustc().input("main.rs").output(&expect_panic_symbols).run();  | 
 | 49 | + | 
 | 50 | +    if is_windows_msvc() {  | 
 | 51 | +        // FIXME(#143737): use actual DIA wrappers instead of parsing `llvm-pdbutil` textual output.  | 
 | 52 | + | 
 | 53 | +        let expect_no_filecheck_pattern = r#"  | 
 | 54 | +            CHECK: main  | 
 | 55 | +            CHECK-NOT: {{.*}}Display{{.*}}  | 
 | 56 | +            CHECK-NOT: {{.*}}panic_bounds_check{{.*}}  | 
 | 57 | +        "#;  | 
 | 58 | +        let expect_no_filecheck_path = Path::new("expect_no_panic_symbols_filecheck.txt");  | 
 | 59 | +        rfs::write(&expect_no_filecheck_path, expect_no_filecheck_pattern);  | 
 | 60 | + | 
 | 61 | +        let expect_no_panic_symbols_pdbutil_dump = llvm_pdbutil()  | 
 | 62 | +            .arg("dump")  | 
 | 63 | +            .arg("-publics")  | 
 | 64 | +            .input(expect_no_panic_symbols.with_extension("pdb"))  | 
 | 65 | +            .run();  | 
 | 66 | +        llvm_filecheck()  | 
 | 67 | +            .patterns(expect_no_filecheck_path)  | 
 | 68 | +            .stdin_buf(expect_no_panic_symbols_pdbutil_dump.stdout_utf8())  | 
 | 69 | +            .run();  | 
 | 70 | + | 
 | 71 | +        // NOTE: on different platforms, they may not go through the same code path. E.g. on  | 
 | 72 | +        // `i686-msvc`, we do not go through `panic_fmt` (only `panic`). So for the check here we  | 
 | 73 | +        // only try to match for mangled `core::panicking` module path.  | 
 | 74 | +        let expect_filecheck_pattern = r#"  | 
 | 75 | +            CHECK: main  | 
 | 76 | +            CHECK: {{.*}}core{{.*}}panicking{{.*}}  | 
 | 77 | +            // _ZN4core3fmt3num3imp54_$LT$impl$u20$core..fmt..Display$u20$for$u20$usize...  | 
 | 78 | +            CHECK: {{.*}}Display{{.*}}  | 
 | 79 | +            CHECK-NOT: {{.*}}panic_bounds_check{{.*}}  | 
 | 80 | +        "#;  | 
 | 81 | +        let expect_filecheck_path = Path::new("expect_panic_symbols_filecheck.txt");  | 
 | 82 | +        rfs::write(&expect_filecheck_path, expect_filecheck_pattern);  | 
 | 83 | + | 
 | 84 | +        let expect_panic_symbols_pdbutil_dump = llvm_pdbutil()  | 
 | 85 | +            .arg("dump")  | 
 | 86 | +            .arg("-publics")  | 
 | 87 | +            .input(expect_panic_symbols.with_extension("pdb"))  | 
 | 88 | +            .run();  | 
 | 89 | +        llvm_filecheck()  | 
 | 90 | +            .patterns(expect_filecheck_path)  | 
 | 91 | +            .stdin_buf(expect_panic_symbols_pdbutil_dump.stdout_utf8())  | 
 | 92 | +            .run();  | 
 | 93 | +    } else {  | 
 | 94 | +        // At least the `main` symbol (or `_main`) should be present.  | 
 | 95 | +        assert!(object_contains_any_symbol_substring(&expect_no_panic_symbols, &["main"]));  | 
 | 96 | +        assert!(object_contains_any_symbol_substring(&expect_panic_symbols, &["main"]));  | 
 | 97 | + | 
 | 98 | +        assert!(!object_contains_any_symbol_substring(&expect_no_panic_symbols, &panic_syms));  | 
 | 99 | +        assert!(object_contains_any_symbol_substring(&expect_panic_symbols, &panic_syms));  | 
 | 100 | +    }  | 
35 | 101 | }  | 
0 commit comments