-
Notifications
You must be signed in to change notification settings - Fork 13.4k
tests: Port extern-fn-reachable
to rmake.rs
#135458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,34 @@ | ||
#![crate_type = "dylib"] | ||
#![allow(dead_code)] | ||
|
||
// `pub` extern fn here is a Rust nameres visibility concept, and should not affect symbol | ||
// visibility in the dylib. | ||
#[no_mangle] | ||
pub extern "C" fn fun1() {} | ||
|
||
// (Lack of) `pub` for the extern fn here is a Rust nameres visibility concept, and should not | ||
// affect symbol visibility in the dylib. | ||
#[no_mangle] | ||
extern "C" fn fun2() {} | ||
|
||
// Modules are a Rust nameres concept, and should not affect symbol visibility in the dylib if the | ||
// extern fn is nested inside a module. | ||
mod foo { | ||
#[no_mangle] | ||
pub extern "C" fn fun3() {} | ||
} | ||
|
||
// Similarly, the Rust visibility of the containing module is a Rust nameres concept, and should not | ||
// affect symbol visibility in the dylib. | ||
pub mod bar { | ||
#[no_mangle] | ||
pub extern "C" fn fun4() {} | ||
} | ||
|
||
// Non-extern `#[no_mangle]` fn should induce a symbol visible in the dylib. | ||
#[no_mangle] | ||
pub fn fun5() {} | ||
|
||
// The Rust visibility of the fn should not affect is symbol visibility in the dylib. | ||
#[no_mangle] | ||
fn fun6() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//! Smoke test to check that that symbols of `extern "C"` functions and `#[no_mangle]` rust | ||
//! functions: | ||
//! | ||
//! 1. Are externally visible in the dylib produced. | ||
//! 2. That the symbol visibility is orthogonal to the Rust nameres visibility of the functions | ||
//! involved. | ||
|
||
//@ ignore-cross-compile | ||
|
||
use std::collections::BTreeSet; | ||
|
||
use run_make_support::object::{self, Object}; | ||
use run_make_support::{dynamic_lib_name, is_darwin, path, rfs, rustc}; | ||
|
||
fn main() { | ||
let dylib = dynamic_lib_name("dylib"); | ||
rustc().input("dylib.rs").output(&dylib).arg("-Cprefer-dynamic").run(); | ||
|
||
let expected_symbols = if is_darwin() { | ||
// Mach-O states that all exported symbols should have an underscore as prefix. At the | ||
// same time dlsym will implicitly add it, so outside of compilers, linkers and people | ||
// writing assembly, nobody needs to be aware of this. | ||
BTreeSet::from(["_fun1", "_fun2", "_fun3", "_fun4", "_fun5", "_fun6"]) | ||
} else { | ||
BTreeSet::from(["fun1", "fun2", "fun3", "fun4", "fun5", "fun6"]) | ||
}; | ||
|
||
let mut found_symbols = BTreeSet::new(); | ||
|
||
let blob = rfs::read(path(dylib)); | ||
let file = object::File::parse(&*blob).unwrap(); | ||
for export in file.exports().unwrap() { | ||
let sym_name = export.name(); | ||
let sym_name = std::str::from_utf8(sym_name).unwrap(); | ||
found_symbols.insert(sym_name); | ||
} | ||
|
||
println!("expected_symbols = {:?}", expected_symbols); | ||
println!("found_symbols = {:?}", found_symbols); | ||
if !found_symbols.is_superset(&expected_symbols) { | ||
for diff in expected_symbols.difference(&found_symbols) { | ||
eprintln!("missing symbol: {}", diff); | ||
} | ||
panic!("missing expected symbols"); | ||
} | ||
Comment on lines
+38
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ |
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.