Skip to content

Commit ee70647

Browse files
committed
port tests/run-make/extern-fn-reachable to rmake
uses helper functions added in #128147, must not be merged before that PR.
1 parent 3c9d245 commit ee70647

File tree

4 files changed

+38
-26
lines changed

4 files changed

+38
-26
lines changed

src/tools/run-make-support/src/external_deps/rustc.rs

+5
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ impl Rustc {
193193
self
194194
}
195195

196+
/// Make `rustc` prefere dynamic linking
197+
pub fn prefer_dynamic(&mut self) -> &mut Self {
198+
self.arg("-Cprefer-dynamic")
199+
}
200+
196201
/// Specify directory path used for profile generation
197202
pub fn profile_generate<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
198203
let mut arg = OsString::new();

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

+26
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,29 @@ pub fn any_symbol_contains(path: impl AsRef<Path>, substrings: &[&str]) -> bool
4141
false
4242
})
4343
}
44+
45+
/// Check if an object file contains *all* of the given symbols.
46+
///
47+
/// The symbol names must match exactly.
48+
///
49+
/// Panics if `path` is not a valid object file readable by the current user.
50+
pub fn contains_exact_symbols(path: impl AsRef<Path>, symbol_names: &[&str]) -> bool {
51+
let mut found = vec![false; symbol_names.len()];
52+
with_symbol_iter(path, |syms| {
53+
for sym in syms {
54+
for (i, symbol_name) in symbol_names.iter().enumerate() {
55+
found[i] |= sym.name_bytes().unwrap() == symbol_name.as_bytes();
56+
}
57+
}
58+
});
59+
let result = found.iter().all(|x| *x);
60+
if !result {
61+
eprintln!("does not contain symbol(s): ");
62+
for i in 0..found.len() {
63+
if !found[i] {
64+
eprintln!("* {}", symbol_names[i]);
65+
}
66+
}
67+
}
68+
result
69+
}

tests/run-make/extern-fn-reachable/Makefile

-26
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//@ ignore-cross-compile
2+
use run_make_support::{rustc, symbols::contains_exact_symbols};
3+
4+
fn main() {
5+
rustc().input("dylib.rs").output("dylib.so").prefer_dynamic().run();
6+
assert!(contains_exact_symbols("dylib.so", &["fun1", "fun2", "fun3", "fun4", "fun5"]));
7+
}

0 commit comments

Comments
 (0)