|
5 | 5 | //@ only-linux
|
6 | 6 | //@ ignore-32bit
|
7 | 7 |
|
8 |
| -use std::process::Command; |
9 |
| - |
10 | 8 | use run_make_support::llvm_readobj;
|
11 | 9 | use run_make_support::rustc;
|
12 | 10 | use run_make_support::{cmd, target};
|
13 | 11 |
|
| 12 | +// Minimum major versions supporting -static-pie |
| 13 | +const GCC_VERSION: u32 = 8; |
| 14 | +const CLANG_VERSION: u32 = 9; |
| 15 | + |
| 16 | +// Return `true` if the `compiler` version supports `-static-pie`. |
14 | 17 | fn ok_compiler_version(compiler: &str) -> bool {
|
15 |
| - let check_file = format!("check_{compiler}_version.sh"); |
| 18 | + let version_threshold = match compiler { |
| 19 | + "clang" => CLANG_VERSION, |
| 20 | + "gcc" => GCC_VERSION, |
| 21 | + other => panic!("unexpected compiler '{other}', expected 'clang' or 'gcc'"), |
| 22 | + }; |
16 | 23 |
|
17 |
| - Command::new(check_file).status().is_ok_and(|status| status.success()) |
| 24 | + let process = cmd(compiler).arg("-dumpversion").run_unchecked(); |
| 25 | + if !process.status().success() { |
| 26 | + eprintln!("No {compiler} version detected"); |
| 27 | + return false; |
| 28 | + } |
| 29 | + // 'major.minor.patch', 'major.minor', or 'major' |
| 30 | + let version: u32 = process.stdout_utf8().split(".").next().unwrap().parse().unwrap(); |
| 31 | + |
| 32 | + if version >= version_threshold { |
| 33 | + eprintln!("{compiler} supports -static-pie"); |
| 34 | + true |
| 35 | + } else { |
| 36 | + eprintln!("{compiler} too old to support -static-pie, skipping test"); |
| 37 | + false |
| 38 | + } |
18 | 39 | }
|
19 | 40 |
|
20 | 41 | fn test(compiler: &str) {
|
|
0 commit comments