Skip to content

Commit

Permalink
Auto merge of rust-lang#128314 - lolbinarycat:extern-fn-reachable-rma…
Browse files Browse the repository at this point in the history
…ke, 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
  • Loading branch information
bors committed Aug 7, 2024
2 parents 0ddead3 + c1d8892 commit b5490c8
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 28 deletions.
5 changes: 5 additions & 0 deletions src/tools/run-make-support/src/external_deps/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ impl Rustc {
self
}

/// Make `rustc` prefere dynamic linking
pub fn prefer_dynamic(&mut self) -> &mut Self {
self.arg("-Cprefer-dynamic")
}

/// Specify directory path used for profile generation
pub fn profile_generate<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
let mut arg = OsString::new();
Expand Down
45 changes: 44 additions & 1 deletion src/tools/run-make-support/src/symbols.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::Path;

use object::{self, Object, ObjectSymbol, SymbolIterator};
use object::{self, Object, ObjectSymbol, Symbol, SymbolIterator};

/// Iterate through the symbols in an object file.
///
Expand Down Expand Up @@ -42,3 +42,46 @@ pub fn any_symbol_contains(path: impl AsRef<Path>, substrings: &[&str]) -> bool
false
})
}

/// Get a list of symbols that are in `symbol_names` but not the final binary.
///
/// The symbols must also match `pred`.
///
/// The symbol names must match exactly.
///
/// Panics if `path` is not a valid object file readable by the current user.
pub fn missing_exact_symbols<'a>(
path: impl AsRef<Path>,
symbol_names: &[&'a str],
pred: impl Fn(&Symbol<'_, '_>) -> bool,
) -> Vec<&'a str> {
let mut found = vec![false; symbol_names.len()];
with_symbol_iter(path, |syms| {
for sym in syms.filter(&pred) {
for (i, symbol_name) in symbol_names.iter().enumerate() {
found[i] |= sym.name_bytes().unwrap() == symbol_name.as_bytes();
}
}
});
return found
.iter()
.enumerate()
.filter_map(|(i, found)| if !*found { Some(symbol_names[i]) } else { None })
.collect();
}

/// Assert that the symbol file contains all of the listed symbols and they all match the given predicate
pub fn assert_contains_exact_symbols(
path: impl AsRef<Path>,
symbol_names: &[&str],
pred: impl Fn(&Symbol<'_, '_>) -> bool,
) {
let missing = missing_exact_symbols(path.as_ref(), symbol_names, pred);
if missing.len() > 0 {
eprintln!("{} does not contain symbol(s): ", path.as_ref().display());
for sn in missing {
eprintln!("* {}", sn);
}
panic!("missing symbols");
}
}
1 change: 0 additions & 1 deletion src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ run-make/dep-info-doesnt-run-much/Makefile
run-make/dep-info-spaces/Makefile
run-make/dep-info/Makefile
run-make/emit-to-stdout/Makefile
run-make/extern-fn-reachable/Makefile
run-make/incr-add-rust-src-component/Makefile
run-make/issue-84395-lto-embed-bitcode/Makefile
run-make/jobserver-error/Makefile
Expand Down
26 changes: 0 additions & 26 deletions tests/run-make/extern-fn-reachable/Makefile

This file was deleted.

10 changes: 10 additions & 0 deletions tests/run-make/extern-fn-reachable/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@ ignore-cross-compile
use run_make_support::object::ObjectSymbol;
use run_make_support::rustc;
use run_make_support::symbols::assert_contains_exact_symbols;
fn main() {
rustc().input("dylib.rs").output("dylib.so").prefer_dynamic().run();
assert_contains_exact_symbols("dylib.so", &["fun1", "fun2", "fun3", "fun4", "fun5"], |sym| {
dbg!(dbg!(sym).is_global()) && !dbg!(sym.is_undefined())
});
}

0 comments on commit b5490c8

Please sign in to comment.