Skip to content

Commit

Permalink
Migrate static-pie scripts to rmake
Browse files Browse the repository at this point in the history
  • Loading branch information
Rejyr committed Jun 22, 2024
1 parent f90d4e4 commit c69770d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 42 deletions.
20 changes: 0 additions & 20 deletions tests/run-make/static-pie/check_clang_version.sh

This file was deleted.

20 changes: 0 additions & 20 deletions tests/run-make/static-pie/check_gcc_version.sh

This file was deleted.

31 changes: 29 additions & 2 deletions tests/run-make/static-pie/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,40 @@
use std::process::Command;

use run_make_support::llvm_readobj;
use run_make_support::regex::Regex;
use run_make_support::rustc;
use run_make_support::{cmd, run_with_args, 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 (trigger, version_threshold) = match compiler {
"clang" => ("__clang_major__", CLANG_VERSION),
"gcc" => ("__GNUC__", GCC_VERSION),
other => panic!("unexpected compiler '{other}', expected 'clang' or 'gcc'"),
};

if Command::new(compiler).spawn().is_err() {
eprintln!("No {compiler} version detected");
return false;
}

Command::new(check_file).status().is_ok_and(|status| status.success())
let compiler_output =
cmd(compiler).stdin(trigger).arg("-").arg("-E").arg("-x").arg("c").run().stdout_utf8();
let re = Regex::new(r"(?m)^(\d+)").unwrap();
let version: u32 =
re.captures(&compiler_output).unwrap().get(1).unwrap().as_str().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) {
Expand Down

0 comments on commit c69770d

Please sign in to comment.