Skip to content

Commit 1d2e78e

Browse files
Auto merge of #143669 - jieyouxu:fmt-write-bloat, r=<try>
[WIP] Make sure `fmt-write-bloat` doesn't vacuously pass on no symbols Previously, the test only checks for the absence of certain panic symbols, but having no symbols was also a possible albeit vacuous way to satisfy this assertion. Fix this by checking we at least observe the `main` symbol which is always expected to be present. Noticed in #142841 (comment). r? `@ChrisDenton` try-job: aarch64-apple try-job: x86_64-apple-1 try-job: x86_64-msvc-1 try-job: i686-msvc-1 try-job: x86_64-mingw-1
2 parents 558d253 + 63b9636 commit 1d2e78e

File tree

4 files changed

+65
-5
lines changed

4 files changed

+65
-5
lines changed

Cargo.lock

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,12 @@ dependencies = [
11961196
"once_cell",
11971197
]
11981198

1199+
[[package]]
1200+
name = "fallible-iterator"
1201+
version = "0.2.0"
1202+
source = "registry+https://github.com/rust-lang/crates.io-index"
1203+
checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7"
1204+
11991205
[[package]]
12001206
name = "fallible-iterator"
12011207
version = "0.3.0"
@@ -1478,7 +1484,7 @@ version = "0.31.1"
14781484
source = "registry+https://github.com/rust-lang/crates.io-index"
14791485
checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
14801486
dependencies = [
1481-
"fallible-iterator",
1487+
"fallible-iterator 0.3.0",
14821488
"indexmap",
14831489
"stable_deref_trait",
14841490
]
@@ -1489,7 +1495,7 @@ version = "0.32.0"
14891495
source = "registry+https://github.com/rust-lang/crates.io-index"
14901496
checksum = "93563d740bc9ef04104f9ed6f86f1e3275c2cdafb95664e26584b9ca807a8ffe"
14911497
dependencies = [
1492-
"fallible-iterator",
1498+
"fallible-iterator 0.3.0",
14931499
"indexmap",
14941500
"stable_deref_trait",
14951501
]
@@ -2765,6 +2771,17 @@ version = "0.2.3"
27652771
source = "registry+https://github.com/rust-lang/crates.io-index"
27662772
checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3"
27672773

2774+
[[package]]
2775+
name = "pdb"
2776+
version = "0.8.0"
2777+
source = "registry+https://github.com/rust-lang/crates.io-index"
2778+
checksum = "82040a392923abe6279c00ab4aff62d5250d1c8555dc780e4b02783a7aa74863"
2779+
dependencies = [
2780+
"fallible-iterator 0.2.0",
2781+
"scroll",
2782+
"uuid",
2783+
]
2784+
27682785
[[package]]
27692786
name = "percent-encoding"
27702787
version = "2.3.1"
@@ -3221,6 +3238,7 @@ dependencies = [
32213238
"gimli 0.32.0",
32223239
"libc",
32233240
"object 0.37.1",
3241+
"pdb",
32243242
"regex",
32253243
"serde_json",
32263244
"similar",
@@ -4930,6 +4948,12 @@ version = "1.2.0"
49304948
source = "registry+https://github.com/rust-lang/crates.io-index"
49314949
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
49324950

4951+
[[package]]
4952+
name = "scroll"
4953+
version = "0.11.0"
4954+
source = "registry+https://github.com/rust-lang/crates.io-index"
4955+
checksum = "04c565b551bafbef4157586fa379538366e4385d42082f255bfd96e4fe8519da"
4956+
49334957
[[package]]
49344958
name = "self_cell"
49354959
version = "1.2.0"

src/tools/run-make-support/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ gimli = "0.32"
1313
build_helper = { path = "../../build_helper" }
1414
serde_json = "1.0"
1515
libc = "0.2"
16+
pdb = "0.8.0"
1617

1718
[lib]
1819
crate-type = ["lib", "dylib"]

src/tools/run-make-support/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pub use bstr;
4141
pub use gimli;
4242
pub use libc;
4343
pub use object;
44+
pub use pdb;
4445
pub use regex;
4546
pub use serde_json;
4647
pub use similar;

tests/run-make/fmt-write-bloat/rmake.rs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
1818
//@ ignore-cross-compile
1919

20-
use run_make_support::artifact_names::bin_name;
2120
use run_make_support::env::no_debug_assertions;
22-
use run_make_support::rustc;
2321
use run_make_support::symbols::any_symbol_contains;
22+
use run_make_support::{bin_name, is_msvc, pdb, rustc, target};
2423

2524
fn main() {
2625
rustc().input("main.rs").opt().run();
@@ -31,5 +30,40 @@ fn main() {
3130
// otherwise, add them to the list of symbols to deny.
3231
panic_syms.extend_from_slice(&["panicking", "panic_fmt", "pad_integral", "Display"]);
3332
}
34-
assert!(!any_symbol_contains(bin_name("main"), &panic_syms));
33+
34+
if is_msvc() {
35+
use pdb::FallibleIterator;
36+
37+
let file = std::fs::File::open("main.pdb").expect("failed to open `main.pdb`");
38+
let mut pdb = pdb::PDB::open(file).expect("failed to parse `main.pdb`");
39+
40+
let symbol_table = pdb.global_symbols().expect("failed to parse PDB global symbols");
41+
let mut symbols = symbol_table.iter();
42+
43+
let mut found_symbols = vec![];
44+
45+
while let Some(symbol) = symbols.next().expect("failed to parse symbol") {
46+
match symbol.parse() {
47+
Ok(pdb::SymbolData::Public(data)) => {
48+
found_symbols.push(data.name.to_string());
49+
}
50+
_ => {}
51+
}
52+
}
53+
54+
// Make sure we at least have the `main` symbol itself, otherwise even no symbols can
55+
// trivially satisfy the "no panic symbol" assertion.
56+
assert!(found_symbols.iter().any(|sym| sym == "main"), "expected `main` symbol");
57+
58+
for found_symbol in found_symbols {
59+
for panic_symbol in &panic_syms {
60+
assert_ne!(found_symbol, *panic_symbol, "found unexpected panic machinery symbol");
61+
}
62+
}
63+
} else {
64+
// Make sure we at least have the `main` symbol itself, otherwise even no symbols can
65+
// trivially satisfy the "no panic symbol" assertion.
66+
assert!(any_symbol_contains(bin_name("main"), &["main"]));
67+
assert!(!any_symbol_contains(bin_name("main"), &panic_syms));
68+
}
3569
}

0 commit comments

Comments
 (0)