@@ -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;
@@ -2197,7 +2198,12 @@ Please disable assertions with `rust.debug-assertions = false`.
21972198 "-Lnative={}" ,
21982199 builder. test_helpers_out( test_compiler. host) . display( )
21992200 ) ) ;
2200- targetflags. push ( format ! ( "-Lnative={}" , builder. test_helpers_out( target) . display( ) ) ) ;
2201+ let target_helpers = builder. test_helpers_out ( target) ;
2202+ targetflags. push ( format ! ( "-Lnative={}" , target_helpers. display( ) ) ) ;
2203+ if target. triple . contains ( "pauthtest" ) {
2204+ // Embed rpath to the shared object
2205+ targetflags. push ( format ! ( "-Clink-arg=-Wl,-rpath,{}" , target_helpers. display( ) ) ) ;
2206+ }
22012207 }
22022208
22032209 for flag in hostflags {
@@ -3812,32 +3818,58 @@ impl Step for TestHelpers {
38123818 } ;
38133819 let dst = builder. test_helpers_out ( target) ;
38143820 let src = builder. src . join ( "tests/auxiliary/rust_test_helpers.c" ) ;
3815- if up_to_date ( & src, & dst. join ( "librust_test_helpers.a" ) ) {
3816- return ;
3817- }
3818-
38193821 let _guard = builder. msg_unstaged ( Kind :: Build , "test helpers" , target) ;
38203822 t ! ( fs:: create_dir_all( & dst) ) ;
3821- let mut cfg = cc:: Build :: new ( ) ;
38223823
3823- // We may have found various cross-compilers a little differently due to our
3824- // extra configuration, so inform cc of these compilers. Note, though, that
3825- // on MSVC we still need cc's detection of env vars (ugh).
3826- if !target. is_msvc ( ) {
3827- if let Some ( ar) = builder. ar ( target) {
3828- cfg. archiver ( ar) ;
3824+ if !up_to_date ( & src, & dst. join ( "librust_test_helpers.a" ) ) {
3825+ let mut cfg = cc:: Build :: new ( ) ;
3826+
3827+ // We may have found various cross-compilers a little differently due to our
3828+ // extra configuration, so inform cc of these compilers. Note, though, that
3829+ // on MSVC we still need cc's detection of env vars (ugh).
3830+ if !target. is_msvc ( ) {
3831+ if let Some ( ar) = builder. ar ( target) {
3832+ cfg. archiver ( ar) ;
3833+ }
3834+ cfg. compiler ( builder. cc ( target) ) ;
3835+ }
3836+ cfg. cargo_metadata ( false )
3837+ . out_dir ( & dst)
3838+ . target ( & target. triple )
3839+ . host ( & builder. config . host_target . triple )
3840+ . opt_level ( 0 )
3841+ . warnings ( false )
3842+ . debug ( false )
3843+ . file ( builder. src . join ( "tests/auxiliary/rust_test_helpers.c" ) )
3844+ . compile ( "rust_test_helpers" ) ;
3845+ }
3846+ if target. triple . contains ( "pauthtest" ) {
3847+ let so = dst. join ( "librust_test_helpers.so" ) ;
3848+ if up_to_date ( & src, & so) {
3849+ return ;
3850+ }
3851+
3852+ let pauthtest_sysroot = std:: env:: var ( "PAUTHTEST_SYSROOT" ) . unwrap_or_default ( ) ;
3853+ let status = Command :: new ( "clang" )
3854+ . arg ( "-target" )
3855+ . arg ( target. triple )
3856+ . arg ( "-fuse-ld=lld" )
3857+ . arg ( format ! ( "--sysroot={}" , pauthtest_sysroot) )
3858+ . arg ( "-nostdlib" )
3859+ . arg ( "-march=armv8.3-a" )
3860+ . arg ( "-fPIC" )
3861+ . arg ( "-shared" )
3862+ . arg ( "-O0" ) // Use O0 to match what static library is compiled at.
3863+ . arg ( "-o" )
3864+ . arg ( & so)
3865+ . arg ( & src)
3866+ . status ( )
3867+ . expect ( "Failed to run pauthtest clang for librust_test_helpers.so" ) ;
3868+
3869+ if !status. success ( ) {
3870+ panic ! ( "Linking of pauthtest librust_test_helpers.so failed" ) ;
38293871 }
3830- cfg. compiler ( builder. cc ( target) ) ;
38313872 }
3832- cfg. cargo_metadata ( false )
3833- . out_dir ( & dst)
3834- . target ( & target. triple )
3835- . host ( & builder. config . host_target . triple )
3836- . opt_level ( 0 )
3837- . warnings ( false )
3838- . debug ( false )
3839- . file ( builder. src . join ( "tests/auxiliary/rust_test_helpers.c" ) )
3840- . compile ( "rust_test_helpers" ) ;
38413873 }
38423874}
38433875
0 commit comments