Skip to content

Commit 2acf31a

Browse files
committed
migrate fmt-write-bloat to rmake
1 parent 2ccafed commit 2acf31a

File tree

4 files changed

+42
-26
lines changed

4 files changed

+42
-26
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub mod run;
2121
pub mod scoped_run;
2222
pub mod string;
2323
pub mod targets;
24-
24+
pub mod symbols;
2525
// Internally we call our fs-related support module as `fs`, but re-export its content as `rfs`
2626
// to tests to avoid colliding with commonly used `use std::fs;`.
2727
mod fs;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use std::path::Path;
2+
use std::fs;
3+
use object::{self, Object, SymbolIterator};
4+
5+
/// iterate through the symbols in an object file.
6+
///
7+
/// uses a callback because SymbolIterator does not own its data
8+
pub fn with_symbol_iter<P, F, R>(path: P, func: F) -> R where
9+
P: AsRef<Path>,
10+
//I: Iterator + 'a,
11+
F: FnOnce(&mut SymbolIterator<'_, '_>) -> R,
12+
{
13+
let raw_bytes = fs::read(path).expect("unable to read file");
14+
let f = object::File::parse(raw_bytes.as_slice())
15+
.expect("unable to parse file");
16+
let mut iter = f.symbols();
17+
func(&mut iter)
18+
}

tests/run-make/fmt-write-bloat/Makefile

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//@ ignore-windows
2+
//@ ignore-cross-compile
3+
4+
use run_make_support::{rustc, symbols::with_symbol_iter, object::ObjectSymbol};
5+
6+
fn main() {
7+
rustc().input("main.rs").run();
8+
// panic machinery identifiers, these should not appear in the final binary
9+
let mut panic_syms = vec!["panic_bounds_check", "Debug"];
10+
if !cfg!(debug_assertions) {
11+
// if debug assertions are allowed, we need to allow these,
12+
// otherwise, add them to the list of symbols to deny.
13+
panic_syms.extend_from_slice(&["panicking", "panic_fmt", "pad_integral", "Display"]);
14+
}
15+
with_symbol_iter("main", |syms| for sym in syms {
16+
dbg!(&sym);
17+
for panic_sym in &panic_syms {
18+
if sym.name().unwrap().contains(panic_sym) {
19+
panic!("{:?} contains {}", sym, panic_sym);
20+
}
21+
}
22+
});
23+
}

0 commit comments

Comments
 (0)