forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#128147 - lolbinarycat:fmt-write-bloat-rmake, …
…r=<try> migrate fmt-write-bloat to rmake try-job: aarch64-apple try-job: x86_64-gnu-llvm-18 try-job: dist-x86_64-linux
- Loading branch information
Showing
6 changed files
with
61 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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 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 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 @@ | ||
use object::{self, Object, ObjectSymbol, SymbolIterator}; | ||
use std::fs; | ||
use std::path::Path; | ||
|
||
/// iterate through the symbols in an object file. | ||
/// | ||
/// uses a callback because SymbolIterator does not own its data | ||
pub fn with_symbol_iter<P, F, R>(path: P, func: F) -> R | ||
where | ||
P: AsRef<Path>, | ||
//I: Iterator + 'a, | ||
F: FnOnce(&mut SymbolIterator<'_, '_>) -> R, | ||
{ | ||
let raw_bytes = fs::read(path).expect("unable to read file"); | ||
let f = object::File::parse(raw_bytes.as_slice()).expect("unable to parse file"); | ||
let mut iter = f.symbols(); | ||
func(&mut iter) | ||
} | ||
|
||
pub fn any_symbol_contains(path: impl AsRef<Path>, substrings: &[&str]) -> bool { | ||
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 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.
This file contains 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,16 @@ | ||
//@ ignore-windows | ||
//@ ignore-cross-compile | ||
|
||
use run_make_support::{env::no_debug_assertions, rustc, symbols::any_symbol_contains}; | ||
|
||
fn main() { | ||
rustc().input("main.rs").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)); | ||
} |