Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b5490c8

Browse files
committedAug 7, 2024
Auto merge of rust-lang#128314 - lolbinarycat:extern-fn-reachable-rmake, r=<try>
port tests/run-make/extern-fn-reachable to rmake uses helper functions added in rust-lang#128147, must not be merged before that PR. try-job: aarch64-apple try-job: armhf-gnu try-job: test-various try-job: x86_64-msvc try-job: x86_64-mingw try-job: i686-msvc try-job: i686-mingw try-job: x86_64-gnu-llvm-17
2 parents 0ddead3 + c1d8892 commit b5490c8

File tree

5 files changed

+59
-28
lines changed

5 files changed

+59
-28
lines changed
 

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

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

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

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

+44-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::path::Path;
22

3-
use object::{self, Object, ObjectSymbol, SymbolIterator};
3+
use object::{self, Object, ObjectSymbol, Symbol, SymbolIterator};
44

55
/// Iterate through the symbols in an object file.
66
///
@@ -42,3 +42,46 @@ pub fn any_symbol_contains(path: impl AsRef<Path>, substrings: &[&str]) -> bool
4242
false
4343
})
4444
}
45+
46+
/// Get a list of symbols that are in `symbol_names` but not the final binary.
47+
///
48+
/// The symbols must also match `pred`.
49+
///
50+
/// The symbol names must match exactly.
51+
///
52+
/// Panics if `path` is not a valid object file readable by the current user.
53+
pub fn missing_exact_symbols<'a>(
54+
path: impl AsRef<Path>,
55+
symbol_names: &[&'a str],
56+
pred: impl Fn(&Symbol<'_, '_>) -> bool,
57+
) -> Vec<&'a str> {
58+
let mut found = vec![false; symbol_names.len()];
59+
with_symbol_iter(path, |syms| {
60+
for sym in syms.filter(&pred) {
61+
for (i, symbol_name) in symbol_names.iter().enumerate() {
62+
found[i] |= sym.name_bytes().unwrap() == symbol_name.as_bytes();
63+
}
64+
}
65+
});
66+
return found
67+
.iter()
68+
.enumerate()
69+
.filter_map(|(i, found)| if !*found { Some(symbol_names[i]) } else { None })
70+
.collect();
71+
}
72+
73+
/// Assert that the symbol file contains all of the listed symbols and they all match the given predicate
74+
pub fn assert_contains_exact_symbols(
75+
path: impl AsRef<Path>,
76+
symbol_names: &[&str],
77+
pred: impl Fn(&Symbol<'_, '_>) -> bool,
78+
) {
79+
let missing = missing_exact_symbols(path.as_ref(), symbol_names, pred);
80+
if missing.len() > 0 {
81+
eprintln!("{} does not contain symbol(s): ", path.as_ref().display());
82+
for sn in missing {
83+
eprintln!("* {}", sn);
84+
}
85+
panic!("missing symbols");
86+
}
87+
}

‎src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ run-make/dep-info-doesnt-run-much/Makefile
55
run-make/dep-info-spaces/Makefile
66
run-make/dep-info/Makefile
77
run-make/emit-to-stdout/Makefile
8-
run-make/extern-fn-reachable/Makefile
98
run-make/incr-add-rust-src-component/Makefile
109
run-make/issue-84395-lto-embed-bitcode/Makefile
1110
run-make/jobserver-error/Makefile

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

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

0 commit comments

Comments
 (0)
Failed to load comments.