-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Make sure fmt-write-bloat
doesn't vacuously pass on no symbols
#143669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,21 +15,89 @@ | |
//! `NO_DEBUG_ASSERTIONS=1`). If debug assertions are disabled, then we can check for the absence of | ||
//! additional `usize` formatting and padding related symbols. | ||
|
||
// ignore-tidy-linelength | ||
|
||
//@ ignore-cross-compile | ||
|
||
use run_make_support::artifact_names::bin_name; | ||
use run_make_support::env::no_debug_assertions; | ||
use run_make_support::rustc; | ||
use run_make_support::symbols::any_symbol_contains; | ||
use run_make_support::{bin_name, is_darwin, is_windows_msvc, pdb, rustc, target}; | ||
|
||
// Not applicable for `extern "C"` symbol decoration handling. | ||
fn sym(sym_name: &str) -> String { | ||
if is_darwin() { | ||
// Symbols are decorated with an underscore prefix on darwin platforms. | ||
format!("_{sym_name}") | ||
} else { | ||
sym_name.to_string() | ||
} | ||
} | ||
|
||
fn main() { | ||
rustc().input("main.rs").opt().run(); | ||
// panic machinery identifiers, these should not appear in the final binary | ||
let mut panic_syms = vec!["panic_bounds_check", "Debug"]; | ||
let mut panic_syms = vec![sym("panic_bounds_check"), sym("Debug")]; | ||
if no_debug_assertions() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remark: while investigating this test, I realized this is actually incorrect (even in the original # Allow for debug_assert!() in debug builds of std.
ifdef NO_DEBUG_ASSERTIONS
PANIC_SYMS += panicking panic_fmt pad_integral Display Debug
endif I believe I have a separate PR that I'll send first. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
// if debug assertions are allowed, we need to allow these, | ||
// otherwise, add them to the list of symbols to deny. | ||
panic_syms.extend_from_slice(&["panicking", "panic_fmt", "pad_integral", "Display"]); | ||
panic_syms.extend_from_slice(&[ | ||
sym("panicking"), | ||
sym("panic_fmt"), | ||
sym("pad_integral"), | ||
sym("Display"), | ||
]); | ||
} | ||
|
||
if is_windows_msvc() { | ||
use pdb::FallibleIterator; | ||
|
||
let file = std::fs::File::open("main.pdb").expect("failed to open `main.pdb`"); | ||
let mut pdb = pdb::PDB::open(file).expect("failed to parse `main.pdb`"); | ||
|
||
let symbol_table = pdb.global_symbols().expect("failed to parse PDB global symbols"); | ||
let mut symbols = symbol_table.iter(); | ||
|
||
let mut found_symbols = vec![]; | ||
|
||
while let Some(symbol) = symbols.next().expect("failed to parse symbol") { | ||
match symbol.parse() { | ||
Ok(pdb::SymbolData::Public(data)) => { | ||
found_symbols.push(data.name.to_string()); | ||
} | ||
_ => {} | ||
} | ||
} | ||
|
||
// Make sure we at least have the `main` symbol itself, otherwise even no symbols can | ||
// trivially satisfy the "no panic symbol" assertion. | ||
let main_sym = if is_darwin() { | ||
// Symbols are decorated with an underscore prefix on darwin platforms. | ||
"_main" | ||
} else if target().contains("i686") && is_windows_msvc() { | ||
// `extern "C"` i.e. `__cdecl` on `i686` windows-msvc means that the symbol will be | ||
// decorated with an underscore, but not on `x86_64` windows-msvc. | ||
// See <https://learn.microsoft.com/en-us/cpp/build/reference/decorated-names?view=msvc-170#FormatC>. | ||
"_main" | ||
} else { | ||
"main" | ||
}; | ||
|
||
assert!(found_symbols.iter().any(|sym| sym == main_sym), "expected `main` symbol"); | ||
|
||
for found_symbol in found_symbols { | ||
for panic_symbol in &panic_syms { | ||
assert_ne!( | ||
found_symbol, | ||
panic_symbol.as_str(), | ||
"found unexpected panic machinery symbol" | ||
); | ||
} | ||
} | ||
} else { | ||
let panic_syms = panic_syms.iter().map(String::as_str).collect::<Vec<_>>(); | ||
// Make sure we at least have the `main` symbol itself, otherwise even no symbols can | ||
// trivially satisfy the "no panic symbol" assertion. | ||
assert!(any_symbol_contains(bin_name("main"), &["main"])); | ||
assert!(!any_symbol_contains(bin_name("main"), &panic_syms)); | ||
Comment on lines
+100
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wait, I know this is pre-existing but why is this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's just because the underlying helper uses |
||
} | ||
assert!(!any_symbol_contains(bin_name("main"), &panic_syms)); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.