-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add rmake test for naked function visibility
- Loading branch information
1 parent
10169de
commit 6783e26
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,52 @@ | ||
#![feature(naked_functions, asm_const)] | ||
#![crate_type = "dylib"] | ||
|
||
use std::arch::asm; | ||
|
||
pub trait TraitWithConst { | ||
const COUNT: u32; | ||
} | ||
|
||
struct Test; | ||
|
||
impl TraitWithConst for Test { | ||
const COUNT: u32 = 1; | ||
} | ||
|
||
#[no_mangle] | ||
fn entry() { | ||
private_vanilla_rust_function_from_rust_dylib(); | ||
private_naked_rust_function_from_rust_dylib(); | ||
|
||
public_vanilla_generic_function_from_rust_dylib::<Test>(); | ||
public_naked_generic_function_from_rust_dylib::<Test>(); | ||
} | ||
|
||
extern "C" fn private_vanilla_rust_function_from_rust_dylib() -> u32 { | ||
42 | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn public_vanilla_rust_function_from_rust_dylib() -> u32 { | ||
42 | ||
} | ||
|
||
pub extern "C" fn public_vanilla_generic_function_from_rust_dylib<T: TraitWithConst>() -> u32 { | ||
T::COUNT | ||
} | ||
|
||
#[naked] | ||
extern "C" fn private_naked_rust_function_from_rust_dylib() -> u32 { | ||
unsafe { asm!("mov rax, 42", "ret", options(noreturn)) } | ||
} | ||
|
||
#[naked] | ||
#[no_mangle] | ||
pub extern "C" fn public_naked_rust_function_from_rust_dylib() -> u32 { | ||
unsafe { asm!("mov rax, 42", "ret", options(noreturn)) } | ||
} | ||
|
||
#[naked] | ||
pub extern "C" fn public_naked_generic_function_from_rust_dylib<T: TraitWithConst>() -> u32 { | ||
unsafe { asm!("mov rax, {}", "ret", const T::COUNT, options(noreturn)) } | ||
} |
This file contains 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,37 @@ | ||
// @only-x86_64 | ||
use run_make_support::{dynamic_lib_name, llvm_readobj, regex, rustc}; | ||
|
||
fn main() { | ||
let rdylib_name = dynamic_lib_name("a_rust_dylib"); | ||
rustc().arg("-Zshare-generics=no").input("a_rust_dylib.rs").run(); | ||
|
||
// check vanilla symbols | ||
not_dynamic_symbol(&rdylib_name, "private_vanilla_rust_function_from_rust_dylib"); | ||
dynamic_symbol(&rdylib_name, "public_vanilla_rust_function_from_rust_dylib"); | ||
not_dynamic_symbol(&rdylib_name, "public_vanilla_generic_function_from_rust_dylib"); | ||
|
||
// naked should mirror vanilla | ||
not_dynamic_symbol(&rdylib_name, "private_naked_rust_function_from_rust_dylib"); | ||
dynamic_symbol(&rdylib_name, "public_naked_rust_function_from_rust_dylib"); | ||
not_dynamic_symbol(&rdylib_name, "public_naked_generic_function_from_rust_dylib"); | ||
|
||
// share generics should expose the generic functions | ||
rustc().arg("-Zshare-generics=yes").input("a_rust_dylib.rs").run(); | ||
dynamic_symbol(&rdylib_name, "public_vanilla_generic_function_from_rust_dylib"); | ||
dynamic_symbol(&rdylib_name, "public_naked_generic_function_from_rust_dylib"); | ||
} | ||
|
||
#[track_caller] | ||
fn dynamic_symbol(path: &str, symbol_name: &str) { | ||
assert_eq!(find_dynamic_symbol(path, symbol_name), 1) | ||
} | ||
|
||
#[track_caller] | ||
fn not_dynamic_symbol(path: &str, symbol_name: &str) { | ||
assert_eq!(find_dynamic_symbol(path, symbol_name), 0) | ||
} | ||
|
||
fn find_dynamic_symbol(path: &str, symbol_name: &str) -> usize { | ||
let out = llvm_readobj().arg("--dyn-symbols").input(path).run().stdout_utf8(); | ||
out.lines().filter(|&line| !line.contains("__imp_") && line.contains(symbol_name)).count() | ||
} |