@@ -10,6 +10,7 @@ use std::collections::HashSet;
1010use std:: env:: split_paths;
1111use std:: ffi:: { OsStr , OsString } ;
1212use std:: path:: { Path , PathBuf } ;
13+ use std:: process:: Command ;
1314use std:: { env, fs, iter} ;
1415
1516use build_helper:: exit;
@@ -2227,7 +2228,13 @@ Please disable assertions with `rust.debug-assertions = false`.
22272228 "-Lnative={}" ,
22282229 builder. test_helpers_out( test_compiler. host) . display( )
22292230 ) ) ;
2230- targetflags. push ( format ! ( "-Lnative={}" , builder. test_helpers_out( target) . display( ) ) ) ;
2231+ let target_helpers = builder. test_helpers_out ( target) ;
2232+ targetflags. push ( format ! ( "-Lnative={}" , target_helpers. display( ) ) ) ;
2233+ if target. is_pauthtest ( ) {
2234+ // For the pauthtest target, embed an rpath to the directory containing the helper
2235+ // dynamic library.
2236+ targetflags. push ( format ! ( "-Clink-arg=-Wl,-rpath,{}" , target_helpers. display( ) ) ) ;
2237+ }
22312238 }
22322239
22332240 for flag in hostflags {
@@ -3858,32 +3865,54 @@ impl Step for TestHelpers {
38583865 } ;
38593866 let dst = builder. test_helpers_out ( target) ;
38603867 let src = builder. src . join ( "tests/auxiliary/rust_test_helpers.c" ) ;
3861- if up_to_date ( & src, & dst. join ( "librust_test_helpers.a" ) ) {
3862- return ;
3863- }
3864-
38653868 let _guard = builder. msg_unstaged ( Kind :: Build , "test helpers" , target) ;
38663869 t ! ( fs:: create_dir_all( & dst) ) ;
3867- let mut cfg = cc:: Build :: new ( ) ;
38683870
3869- // We may have found various cross-compilers a little differently due to our
3870- // extra configuration, so inform cc of these compilers. Note, though, that
3871- // on MSVC we still need cc's detection of env vars (ugh).
3872- if !target. is_msvc ( ) {
3873- if let Some ( ar) = builder. ar ( target) {
3874- cfg. archiver ( ar) ;
3871+ if !up_to_date ( & src, & dst. join ( "librust_test_helpers.a" ) ) {
3872+ let mut cfg = cc:: Build :: new ( ) ;
3873+
3874+ // We may have found various cross-compilers a little differently due to our
3875+ // extra configuration, so inform cc of these compilers. Note, though, that
3876+ // on MSVC we still need cc's detection of env vars (ugh).
3877+ if !target. is_msvc ( ) {
3878+ if let Some ( ar) = builder. ar ( target) {
3879+ cfg. archiver ( ar) ;
3880+ }
3881+ cfg. compiler ( builder. cc ( target) ) ;
3882+ }
3883+ cfg. cargo_metadata ( false )
3884+ . out_dir ( & dst)
3885+ . target ( & target. triple )
3886+ . host ( & builder. config . host_target . triple )
3887+ . opt_level ( 0 )
3888+ . warnings ( false )
3889+ . debug ( false )
3890+ . file ( builder. src . join ( "tests/auxiliary/rust_test_helpers.c" ) )
3891+ . compile ( "rust_test_helpers" ) ;
3892+ }
3893+ if target. is_pauthtest ( ) {
3894+ let so = dst. join ( "librust_test_helpers.so" ) ;
3895+ if up_to_date ( & src, & so) {
3896+ return ;
3897+ }
3898+
3899+ let status = Command :: new ( builder. cc ( target) )
3900+ . arg ( "-target" )
3901+ . arg ( target. triple )
3902+ . arg ( "-march=armv8.3-a+pauth" )
3903+ . arg ( "-fPIC" )
3904+ . arg ( "-shared" )
3905+ . arg ( "-O0" ) // Use O0 to match what static library is compiled at.
3906+ . arg ( "-o" )
3907+ . arg ( & so)
3908+ . arg ( & src)
3909+ . status ( )
3910+ . unwrap_or_else ( |_| panic ! ( "Failed to run clang for {} toolchain" , target. triple) ) ;
3911+
3912+ if !status. success ( ) {
3913+ panic ! ( "Linking of librust_test_helpers.so failed (target: {})" , target. triple) ;
38753914 }
3876- cfg. compiler ( builder. cc ( target) ) ;
38773915 }
3878- cfg. cargo_metadata ( false )
3879- . out_dir ( & dst)
3880- . target ( & target. triple )
3881- . host ( & builder. config . host_target . triple )
3882- . opt_level ( 0 )
3883- . warnings ( false )
3884- . debug ( false )
3885- . file ( builder. src . join ( "tests/auxiliary/rust_test_helpers.c" ) )
3886- . compile ( "rust_test_helpers" ) ;
38873916 }
38883917}
38893918
0 commit comments