diff --git a/tests/run-make/static-pie/check_clang_version.sh b/tests/run-make/static-pie/check_clang_version.sh deleted file mode 100755 index b8e97c3da7d7..000000000000 --- a/tests/run-make/static-pie/check_clang_version.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -if command -v clang > /dev/null -then - CLANG_VERSION=$(echo __clang_major__ | clang -E -x c - | grep -v -e '^#' ) - echo "clang version $CLANG_VERSION detected" - if (( $CLANG_VERSION >= 9 )) - then - echo "clang supports -static-pie" - exit 0 - else - echo "clang too old to support -static-pie, skipping test" - exit 1 - fi -else - echo "No clang version detected" - exit 2 -fi diff --git a/tests/run-make/static-pie/check_gcc_version.sh b/tests/run-make/static-pie/check_gcc_version.sh deleted file mode 100755 index d07e1d151dfb..000000000000 --- a/tests/run-make/static-pie/check_gcc_version.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -if command -v gcc > /dev/null -then - GCC_VERSION=$(echo __GNUC__ | gcc -E -x c - | grep -v -e '^#' ) - echo "gcc version $GCC_VERSION detected" - if (( $GCC_VERSION >= 8 )) - then - echo "gcc supports -static-pie" - exit 0 - else - echo "gcc too old to support -static-pie, skipping test" - exit 1 - fi -else - echo "No gcc version detected" - exit 2 -fi diff --git a/tests/run-make/static-pie/rmake.rs b/tests/run-make/static-pie/rmake.rs index 8b1c74d8822b..62febc9e8454 100644 --- a/tests/run-make/static-pie/rmake.rs +++ b/tests/run-make/static-pie/rmake.rs @@ -5,16 +5,37 @@ //@ only-linux //@ ignore-32bit -use std::process::Command; - use run_make_support::llvm_readobj; use run_make_support::rustc; use run_make_support::{cmd, target}; +// Minimum major versions supporting -static-pie +const GCC_VERSION: u32 = 8; +const CLANG_VERSION: u32 = 9; + +// Return `true` if the `compiler` version supports `-static-pie`. fn ok_compiler_version(compiler: &str) -> bool { - let check_file = format!("check_{compiler}_version.sh"); + let version_threshold = match compiler { + "clang" => CLANG_VERSION, + "gcc" => GCC_VERSION, + other => panic!("unexpected compiler '{other}', expected 'clang' or 'gcc'"), + }; - Command::new(check_file).status().is_ok_and(|status| status.success()) + let process = cmd(compiler).arg("-dumpversion").run_unchecked(); + if !process.status().success() { + eprintln!("No {compiler} version detected"); + return false; + } + // 'major.minor.patch', 'major.minor', or 'major' + let version: u32 = process.stdout_utf8().split(".").next().unwrap().parse().unwrap(); + + if version >= version_threshold { + eprintln!("{compiler} supports -static-pie"); + true + } else { + eprintln!("{compiler} too old to support -static-pie, skipping test"); + false + } } fn test(compiler: &str) {