Skip to content

Commit 0c7c510

Browse files
committed
refactor symbol searching logic into any_symbol_contains
1 parent 2acf31a commit 0c7c510

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::path::Path;
22
use std::fs;
3-
use object::{self, Object, SymbolIterator};
3+
use object::{self, Object, SymbolIterator, ObjectSymbol};
44

55
/// iterate through the symbols in an object file.
66
///
@@ -16,3 +16,19 @@ pub fn with_symbol_iter<P, F, R>(path: P, func: F) -> R where
1616
let mut iter = f.symbols();
1717
func(&mut iter)
1818
}
19+
20+
pub fn any_symbol_contains(path: impl AsRef<Path>, substrings: &[&str]) -> bool {
21+
with_symbol_iter(path, |syms| {
22+
for sym in syms {
23+
for substring in substrings {
24+
if sym.name_bytes().unwrap().windows(substring.len())
25+
.any(|x| x == substring.as_bytes())
26+
{
27+
eprintln!("{:?} contains {}", sym, substring);
28+
return true;
29+
}
30+
}
31+
}
32+
false
33+
})
34+
}
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ ignore-windows
22
//@ ignore-cross-compile
33

4-
use run_make_support::{rustc, symbols::with_symbol_iter, object::ObjectSymbol};
4+
use run_make_support::{rustc, symbols::any_symbol_contains};
55

66
fn main() {
77
rustc().input("main.rs").run();
@@ -12,12 +12,5 @@ fn main() {
1212
// otherwise, add them to the list of symbols to deny.
1313
panic_syms.extend_from_slice(&["panicking", "panic_fmt", "pad_integral", "Display"]);
1414
}
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-
});
15+
assert!(!any_symbol_contains("main", &panic_syms));
2316
}

0 commit comments

Comments
 (0)