@@ -11,10 +11,40 @@ use run_make_support::llvm_readobj;
1111use run_make_support:: rustc;
1212use run_make_support:: { cmd, run_with_args, target} ;
1313
14+ // Minimum major versions supporting -static-pie
15+ const GCC_VERSION : u32 = 8 ;
16+ const CLANG_VERSION : u32 = 9 ;
17+
18+ // Return `true` if the `compiler` version supports `-static-pie`.
1419fn ok_compiler_version ( compiler : & str ) -> bool {
15- let check_file = format ! ( "check_{compiler}_version.sh" ) ;
20+ let version_threshold = match compiler {
21+ "clang" => CLANG_VERSION ,
22+ "gcc" => GCC_VERSION ,
23+ other => panic ! ( "unexpected compiler '{other}', expected 'clang' or 'gcc'" ) ,
24+ } ;
1625
17- Command :: new ( check_file) . status ( ) . is_ok_and ( |status| status. success ( ) )
26+ if Command :: new ( compiler) . spawn ( ) . is_err ( ) {
27+ eprintln ! ( "No {compiler} version detected" ) ;
28+ return false ;
29+ }
30+ // 'major.minor.patch', 'major.minor', or 'major'
31+ let version: u32 = cmd ( compiler)
32+ . arg ( "-dumpversion" )
33+ . run ( )
34+ . stdout_utf8 ( )
35+ . split ( "." )
36+ . next ( )
37+ . unwrap ( )
38+ . parse ( )
39+ . unwrap ( ) ;
40+
41+ if version >= version_threshold {
42+ eprintln ! ( "{compiler} supports -static-pie" ) ;
43+ true
44+ } else {
45+ eprintln ! ( "{compiler} too old to support -static-pie, skipping test" ) ;
46+ false
47+ }
1848}
1949
2050fn test ( compiler : & str ) {
0 commit comments