|
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 | +use std::path::Path; |
| 23 | + |
21 | 24 | use run_make_support::env::std_debug_assertions_enabled;
|
22 |
| -use run_make_support::rustc; |
| 25 | +use run_make_support::llvm::{llvm_filecheck, llvm_pdbutil}; |
23 | 26 | use run_make_support::symbols::object_contains_any_symbol_substring;
|
| 27 | +use run_make_support::{is_windows_msvc, rfs, rustc}; |
24 | 28 |
|
25 | 29 | fn main() {
|
26 |
| - rustc().input("main.rs").opt().run(); |
27 | 30 | // panic machinery identifiers, these should not appear in the final binary
|
28 | 31 | let mut panic_syms = vec!["panic_bounds_check", "Debug"];
|
29 |
| - if std_debug_assertions_enabled() { |
| 32 | + if !std_debug_assertions_enabled() { |
30 | 33 | // if debug assertions are allowed, we need to allow these,
|
31 | 34 | // otherwise, add them to the list of symbols to deny.
|
32 | 35 | panic_syms.extend_from_slice(&["panicking", "panic_fmt", "pad_integral", "Display"]);
|
33 | 36 | }
|
34 |
| - assert!(!object_contains_any_symbol_substring(bin_name("main"), &panic_syms)); |
| 37 | + |
| 38 | + let expect_no_panic_symbols = Path::new("expect_no_panic_symbols"); |
| 39 | + rustc().input("main.rs").output(&expect_no_panic_symbols).opt().run(); |
| 40 | + |
| 41 | + let expect_panic_symbols = Path::new("expect_panic_symbols"); |
| 42 | + rustc().input("main.rs").output(&expect_panic_symbols).run(); |
| 43 | + |
| 44 | + if is_windows_msvc() { |
| 45 | + // FIXME(#143737): use actual DIA wrappers instead of parsing `llvm-pdbutil` textual output. |
| 46 | + |
| 47 | + let expect_no_filecheck_pattern = r#" |
| 48 | + CHECK: main |
| 49 | + CHECK-NOT: {{.*}}Display{{.*}} |
| 50 | + CHECK-NOT: {{.*}}panic_bounds_check{{.*}} |
| 51 | + "#; |
| 52 | + let expect_no_filecheck_path = Path::new("expect_no_panic_symbols_filecheck.txt"); |
| 53 | + rfs::write(&expect_no_filecheck_path, expect_no_filecheck_pattern); |
| 54 | + |
| 55 | + let expect_no_panic_symbols_pdbutil_dump = llvm_pdbutil() |
| 56 | + .arg("dump") |
| 57 | + .arg("-publics") |
| 58 | + .input(expect_no_panic_symbols.with_extension("pdb")) |
| 59 | + .run(); |
| 60 | + llvm_filecheck() |
| 61 | + .patterns(expect_no_filecheck_path) |
| 62 | + .stdin_buf(expect_no_panic_symbols_pdbutil_dump.stdout_utf8()) |
| 63 | + .run(); |
| 64 | + |
| 65 | + let expect_filecheck_pattern = r#" |
| 66 | + CHECK: main |
| 67 | + CHECK: {{.*}}core{{.*}}fmt{{.*}}write{{.*}} |
| 68 | + CHECK: {{.*}}core{{.*}}panicking{{.*}}panic_fmt{{.*}} |
| 69 | + // _ZN4core3fmt3num3imp54_$LT$impl$u20$core..fmt..Display$u20$for$u20$usize... |
| 70 | + CHECK: {{.*}}Display{{.*}} |
| 71 | + CHECK-NOT: {{.*}}panic_bounds_check{{.*}} |
| 72 | + "#; |
| 73 | + let expect_filecheck_path = Path::new("expect_panic_symbols_filecheck.txt"); |
| 74 | + rfs::write(&expect_filecheck_path, expect_filecheck_pattern); |
| 75 | + |
| 76 | + let expect_panic_symbols_pdbutil_dump = llvm_pdbutil() |
| 77 | + .arg("dump") |
| 78 | + .arg("-publics") |
| 79 | + .input(expect_panic_symbols.with_extension("pdb")) |
| 80 | + .run(); |
| 81 | + llvm_filecheck() |
| 82 | + .patterns(expect_filecheck_path) |
| 83 | + .stdin_buf(expect_panic_symbols_pdbutil_dump.stdout_utf8()) |
| 84 | + .run(); |
| 85 | + } else { |
| 86 | + assert!(!object_contains_any_symbol_substring(&expect_no_panic_symbols, &panic_syms)); |
| 87 | + assert!(object_contains_any_symbol_substring(&expect_panic_symbols, &panic_syms)); |
| 88 | + } |
35 | 89 | }
|
0 commit comments