Convert tests/run-make/cross-lang-lto-riscv-abi to rmake
This commit is contained in:
parent
f19c48e7a8
commit
adec1a2e84
@ -819,6 +819,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
|
||||
"needs-dynamic-linking",
|
||||
"needs-git-hash",
|
||||
"needs-llvm-components",
|
||||
"needs-matching-clang",
|
||||
"needs-profiler-support",
|
||||
"needs-relocation-model-pic",
|
||||
"needs-run-enabled",
|
||||
|
@ -86,6 +86,18 @@ impl Rustc {
|
||||
self
|
||||
}
|
||||
|
||||
/// This flag defers LTO optimizations to the linker.
|
||||
pub fn linker_plugin_lto(&mut self, option: &str) -> &mut Self {
|
||||
self.cmd.arg(format!("-Clinker-plugin-lto={option}"));
|
||||
self
|
||||
}
|
||||
|
||||
/// Specify what happens when the code panics.
|
||||
pub fn panic(&mut self, option: &str) -> &mut Self {
|
||||
self.cmd.arg(format!("-Cpanic={option}"));
|
||||
self
|
||||
}
|
||||
|
||||
/// Specify number of codegen units
|
||||
pub fn codegen_units(&mut self, units: usize) -> &mut Self {
|
||||
self.cmd.arg(format!("-Ccodegen-units={units}"));
|
||||
|
@ -36,7 +36,6 @@ run-make/crate-hash-rustc-version/Makefile
|
||||
run-make/crate-name-priority/Makefile
|
||||
run-make/cross-lang-lto-clang/Makefile
|
||||
run-make/cross-lang-lto-pgo-smoketest/Makefile
|
||||
run-make/cross-lang-lto-riscv-abi/Makefile
|
||||
run-make/cross-lang-lto-upstream-rlibs/Makefile
|
||||
run-make/cross-lang-lto/Makefile
|
||||
run-make/debug-assertions/Makefile
|
||||
|
@ -1,24 +0,0 @@
|
||||
# needs-matching-clang
|
||||
|
||||
# This test makes sure that cross-language LTO works on riscv targets
|
||||
|
||||
include ../tools.mk
|
||||
|
||||
all: riscv64gc-unknown-linux-gnu riscv32imac-unknown-none-elf riscv32gc-unknown-linux-gnu
|
||||
|
||||
define check-target =
|
||||
@echo "Testing target $(1)"
|
||||
$(RUSTC) --target $(1) -Clinker-plugin-lto=on -Cpanic=abort --crate-type=rlib -o $(TMPDIR)/libriscv-xlto.a ./riscv-xlto.rs
|
||||
$(CLANG) -target $(2) -march=$(3) -mabi=$(4) -flto=thin -fuse-ld=lld -L $(TMPDIR) -lriscv-xlto -nostdlib -o $(TMPDIR)/riscv-xlto ./cstart.c
|
||||
file $(TMPDIR)/riscv-xlto | $(CGREP) "$(5)"
|
||||
endef
|
||||
|
||||
|
||||
riscv64gc-unknown-linux-gnu:
|
||||
@$(call check-target,$@,riscv64-linux-gnu,rv64gc,lp64d,double-float ABI)
|
||||
|
||||
riscv32imac-unknown-none-elf:
|
||||
@$(call check-target,$@,riscv32-unknown-elf,rv32imac,ilp32,soft-float ABI)
|
||||
|
||||
riscv32gc-unknown-linux-gnu:
|
||||
@$(call check-target,$@,riscv32-linux-gnu,rv32gc,ilp32d,double-float ABI)
|
74
tests/run-make/cross-lang-lto-riscv-abi/rmake.rs
Normal file
74
tests/run-make/cross-lang-lto-riscv-abi/rmake.rs
Normal file
@ -0,0 +1,74 @@
|
||||
//! Make sure that cross-language LTO works on riscv targets,
|
||||
//! which requires extra abi metadata to be emitted.
|
||||
//@ needs-matching-clang
|
||||
//@ needs-llvm-components riscv
|
||||
extern crate run_make_support;
|
||||
|
||||
use run_make_support::{bin_name, rustc, tmp_dir};
|
||||
use std::{
|
||||
env,
|
||||
path::PathBuf,
|
||||
process::{Command, Output},
|
||||
str,
|
||||
};
|
||||
|
||||
fn handle_failed_output(output: Output) {
|
||||
eprintln!("output status: `{}`", output.status);
|
||||
eprintln!("=== STDOUT ===\n{}\n\n", String::from_utf8(output.stdout).unwrap());
|
||||
eprintln!("=== STDERR ===\n{}\n\n", String::from_utf8(output.stderr).unwrap());
|
||||
std::process::exit(1)
|
||||
}
|
||||
|
||||
fn check_target(target: &str, clang_target: &str, carch: &str, is_double_float: bool) {
|
||||
eprintln!("Checking target {target}");
|
||||
// Rust part
|
||||
rustc()
|
||||
.input("riscv-xlto.rs")
|
||||
.crate_type("rlib")
|
||||
.target(target)
|
||||
.panic("abort")
|
||||
.linker_plugin_lto("on")
|
||||
.run();
|
||||
// C part
|
||||
let clang = env::var("CLANG").unwrap();
|
||||
let mut cmd = Command::new(clang);
|
||||
let executable = tmp_dir().join("riscv-xlto");
|
||||
cmd.arg("-target")
|
||||
.arg(clang_target)
|
||||
.arg(format!("-march={carch}"))
|
||||
.arg(format!("-flto=thin"))
|
||||
.arg(format!("-fuse-ld=lld"))
|
||||
.arg("-nostdlib")
|
||||
.arg("-o")
|
||||
.arg(&executable)
|
||||
.arg("cstart.c")
|
||||
.arg(tmp_dir().join("libriscv_xlto.rlib"));
|
||||
eprintln!("{cmd:?}");
|
||||
let output = cmd.output().unwrap();
|
||||
if !output.status.success() {
|
||||
handle_failed_output(output);
|
||||
}
|
||||
// Check that the built binary has correct float abi
|
||||
let llvm_readobj =
|
||||
PathBuf::from(env::var("LLVM_BIN_DIR").unwrap()).join(bin_name("llvm-readobj"));
|
||||
let mut cmd = Command::new(llvm_readobj);
|
||||
cmd.arg("--file-header").arg(executable);
|
||||
eprintln!("{cmd:?}");
|
||||
let output = cmd.output().unwrap();
|
||||
if output.status.success() {
|
||||
assert!(
|
||||
!(is_double_float
|
||||
^ dbg!(str::from_utf8(&output.stdout).unwrap())
|
||||
.contains("EF_RISCV_FLOAT_ABI_DOUBLE"))
|
||||
)
|
||||
} else {
|
||||
handle_failed_output(output);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
check_target("riscv64gc-unknown-linux-gnu", "riscv64-linux-gnu", "rv64gc", true);
|
||||
check_target("riscv64imac-unknown-none-elf", "riscv64-unknown-elf", "rv64imac", false);
|
||||
check_target("riscv32imac-unknown-none-elf", "riscv32-unknown-elf", "rv32imac", false);
|
||||
check_target("riscv32gc-unknown-linux-gnu", "riscv32-linux-gnu", "rv32gc", true);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user