66
77//@ ignore-windows-msvc
88
9- use run_make_support:: { bin_name, dynamic_lib_name, is_windows, llvm_readobj, regex, rustc} ;
9+ //FIXME(Oneirical): This currently uses llvm-nm for symbol detection. However,
10+ // the custom Rust-based solution of #128314 may prove to be an interesting alternative.
11+
12+ use run_make_support:: { bin_name, dynamic_lib_name, is_darwin, is_windows, llvm_nm, regex, rustc} ;
1013
1114fn main ( ) {
12- let mut cdylib_name = dynamic_lib_name ( "a_cdylib" ) ;
13- let mut rdylib_name = dynamic_lib_name ( "a_rust_dylib" ) ;
15+ let cdylib_name = dynamic_lib_name ( "a_cdylib" ) ;
16+ let rdylib_name = dynamic_lib_name ( "a_rust_dylib" ) ;
1417 let exe_name = bin_name ( "an_executable" ) ;
15- let mut combined_cdylib_name = dynamic_lib_name ( "combined_rlib_dylib" ) ;
18+ let combined_cdylib_name = dynamic_lib_name ( "combined_rlib_dylib" ) ;
1619 rustc ( ) . arg ( "-Zshare-generics=no" ) . input ( "an_rlib.rs" ) . run ( ) ;
1720 rustc ( ) . arg ( "-Zshare-generics=no" ) . input ( "a_cdylib.rs" ) . run ( ) ;
1821 rustc ( ) . arg ( "-Zshare-generics=no" ) . input ( "a_rust_dylib.rs" ) . run ( ) ;
@@ -74,13 +77,13 @@ fn main() {
7477
7578 // Check the combined case, where we generate a cdylib and an rlib in the same
7679 // compilation session:
77- // Check that a cdylib exports its public // [no_mangle] functions
80+ // Check that a cdylib exports its public # [no_mangle] functions
7881 symbols_check (
7982 & combined_cdylib_name,
8083 SymbolCheckType :: StrSymbol ( "public_c_function_from_cdylib" ) ,
8184 true ,
8285 ) ;
83- // Check that a cdylib exports the public // [no_mangle] functions of dependencies
86+ // Check that a cdylib exports the public # [no_mangle] functions of dependencies
8487 symbols_check (
8588 & combined_cdylib_name,
8689 SymbolCheckType :: StrSymbol ( "public_c_function_from_rlib" ) ,
@@ -94,9 +97,9 @@ fn main() {
9497 rustc ( ) . arg ( "-Zshare-generics=yes" ) . input ( "a_rust_dylib.rs" ) . run ( ) ;
9598 rustc ( ) . arg ( "-Zshare-generics=yes" ) . input ( "an_executable.rs" ) . run ( ) ;
9699
97- // Check that a cdylib exports its public // [no_mangle] functions
100+ // Check that a cdylib exports its public # [no_mangle] functions
98101 symbols_check ( & cdylib_name, SymbolCheckType :: StrSymbol ( "public_c_function_from_cdylib" ) , true ) ;
99- // Check that a cdylib exports the public // [no_mangle] functions of dependencies
102+ // Check that a cdylib exports the public # [no_mangle] functions of dependencies
100103 symbols_check ( & cdylib_name, SymbolCheckType :: StrSymbol ( "public_c_function_from_rlib" ) , true ) ;
101104 // Check that a cdylib DOES NOT export any public Rust functions
102105 symbols_check ( & cdylib_name, SymbolCheckType :: AnyRustSymbol , false ) ;
@@ -142,7 +145,15 @@ fn main() {
142145
143146#[ track_caller]
144147fn symbols_check ( path : & str , symbol_check_type : SymbolCheckType , exists_once : bool ) {
145- let out = llvm_readobj ( ) . arg ( "--dyn-symbols" ) . input ( path) . run ( ) . invalid_stdout_utf8 ( ) ;
148+ let mut nm = llvm_nm ( ) ;
149+ if is_windows ( ) {
150+ nm. arg ( "--extern-only" ) ;
151+ } else if is_darwin ( ) {
152+ nm. arg ( "--extern-only" ) . arg ( "--defined-only" ) ;
153+ } else {
154+ nm. arg ( "--dynamic" ) ;
155+ }
156+ let out = nm. input ( path) . run ( ) . stdout_utf8 ( ) ;
146157 assert_eq ! (
147158 out. lines( )
148159 . filter( |& line| !line. contains( "__imp_" ) && has_symbol( line, symbol_check_type) )
0 commit comments