-
Notifications
You must be signed in to change notification settings - Fork 13.4k
migrate fmt-write-bloat to rmake #128147
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
Merged
+89
−26
Merged
migrate fmt-write-bloat to rmake #128147
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use std::path::Path; | ||
|
||
use object::{self, Object, ObjectSymbol, SymbolIterator}; | ||
|
||
/// Iterate through the symbols in an object file. | ||
/// | ||
/// Uses a callback because `SymbolIterator` does not own its data. | ||
/// | ||
/// Panics if `path` is not a valid object file readable by the current user. | ||
pub fn with_symbol_iter<P, F, R>(path: P, func: F) -> R | ||
where | ||
P: AsRef<Path>, | ||
F: FnOnce(&mut SymbolIterator<'_, '_>) -> R, | ||
{ | ||
let raw_bytes = crate::fs::read(path); | ||
let f = object::File::parse(raw_bytes.as_slice()).expect("unable to parse file"); | ||
let mut iter = f.symbols(); | ||
func(&mut iter) | ||
} | ||
|
||
/// Check an object file's symbols for substrings. | ||
/// | ||
/// Returns `true` if any of the symbols found in the object file at | ||
/// `path` contain a substring listed in `substrings`. | ||
/// | ||
/// Panics if `path` is not a valid object file readable by the current user. | ||
pub fn any_symbol_contains(path: impl AsRef<Path>, substrings: &[&str]) -> bool { | ||
jieyouxu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
with_symbol_iter(path, |syms| { | ||
for sym in syms { | ||
for substring in substrings { | ||
if sym | ||
.name_bytes() | ||
.unwrap() | ||
.windows(substring.len()) | ||
.any(|x| x == substring.as_bytes()) | ||
{ | ||
eprintln!("{:?} contains {}", sym, substring); | ||
return true; | ||
} | ||
} | ||
} | ||
false | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
jieyouxu marked this conversation as resolved.
Show resolved
Hide resolved
jieyouxu marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//! Before #78122, writing any `fmt::Arguments` would trigger the inclusion of `usize` formatting | ||
//! and padding code in the resulting binary, because indexing used in `fmt::write` would generate | ||
//! code using `panic_bounds_check`, which prints the index and length. | ||
//! | ||
//! These bounds checks are not necessary, as `fmt::Arguments` never contains any out-of-bounds | ||
//! indexes. The test is a `run-make` test, because it needs to check the result after linking. A | ||
//! codegen or assembly test doesn't check the parts that will be pulled in from `core` by the | ||
//! linker. | ||
//! | ||
//! In this test, we try to check that the `usize` formatting and padding code are not present in | ||
//! the final binary by checking that panic symbols such as `panic_bounds_check` are **not** | ||
//! present. | ||
//! | ||
//! Some CI jobs try to run faster by disabling debug assertions (through setting | ||
//! `NO_DEBUG_ASSERTIONS=1`). If debug assertions are disabled, then we can check for the absence of | ||
//! additional `usize` formatting and padding related symbols. | ||
|
||
// Reason: This test is `ignore-windows` because the `no_std` test (using `#[link(name = "c")])` | ||
// doesn't link on windows. | ||
//@ ignore-windows | ||
jieyouxu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//@ ignore-cross-compile | ||
|
||
use run_make_support::env::no_debug_assertions; | ||
use run_make_support::rustc; | ||
use run_make_support::symbols::any_symbol_contains; | ||
|
||
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"]; | ||
if no_debug_assertions() { | ||
// 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"]); | ||
} | ||
assert!(!any_symbol_contains("main", &panic_syms)); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.