Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit adec1a2

Browse files
committed
Convert tests/run-make/cross-lang-lto-riscv-abi to rmake
1 parent f19c48e commit adec1a2

File tree

5 files changed

+87
-25
lines changed

5 files changed

+87
-25
lines changed

src/tools/compiletest/src/header.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
819819
"needs-dynamic-linking",
820820
"needs-git-hash",
821821
"needs-llvm-components",
822+
"needs-matching-clang",
822823
"needs-profiler-support",
823824
"needs-relocation-model-pic",
824825
"needs-run-enabled",

src/tools/run-make-support/src/rustc.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ impl Rustc {
8686
self
8787
}
8888

89+
/// This flag defers LTO optimizations to the linker.
90+
pub fn linker_plugin_lto(&mut self, option: &str) -> &mut Self {
91+
self.cmd.arg(format!("-Clinker-plugin-lto={option}"));
92+
self
93+
}
94+
95+
/// Specify what happens when the code panics.
96+
pub fn panic(&mut self, option: &str) -> &mut Self {
97+
self.cmd.arg(format!("-Cpanic={option}"));
98+
self
99+
}
100+
89101
/// Specify number of codegen units
90102
pub fn codegen_units(&mut self, units: usize) -> &mut Self {
91103
self.cmd.arg(format!("-Ccodegen-units={units}"));

src/tools/tidy/src/allowed_run_make_makefiles.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ run-make/crate-hash-rustc-version/Makefile
3636
run-make/crate-name-priority/Makefile
3737
run-make/cross-lang-lto-clang/Makefile
3838
run-make/cross-lang-lto-pgo-smoketest/Makefile
39-
run-make/cross-lang-lto-riscv-abi/Makefile
4039
run-make/cross-lang-lto-upstream-rlibs/Makefile
4140
run-make/cross-lang-lto/Makefile
4241
run-make/debug-assertions/Makefile

tests/run-make/cross-lang-lto-riscv-abi/Makefile

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//! Make sure that cross-language LTO works on riscv targets,
2+
//! which requires extra abi metadata to be emitted.
3+
//@ needs-matching-clang
4+
//@ needs-llvm-components riscv
5+
extern crate run_make_support;
6+
7+
use run_make_support::{bin_name, rustc, tmp_dir};
8+
use std::{
9+
env,
10+
path::PathBuf,
11+
process::{Command, Output},
12+
str,
13+
};
14+
15+
fn handle_failed_output(output: Output) {
16+
eprintln!("output status: `{}`", output.status);
17+
eprintln!("=== STDOUT ===\n{}\n\n", String::from_utf8(output.stdout).unwrap());
18+
eprintln!("=== STDERR ===\n{}\n\n", String::from_utf8(output.stderr).unwrap());
19+
std::process::exit(1)
20+
}
21+
22+
fn check_target(target: &str, clang_target: &str, carch: &str, is_double_float: bool) {
23+
eprintln!("Checking target {target}");
24+
// Rust part
25+
rustc()
26+
.input("riscv-xlto.rs")
27+
.crate_type("rlib")
28+
.target(target)
29+
.panic("abort")
30+
.linker_plugin_lto("on")
31+
.run();
32+
// C part
33+
let clang = env::var("CLANG").unwrap();
34+
let mut cmd = Command::new(clang);
35+
let executable = tmp_dir().join("riscv-xlto");
36+
cmd.arg("-target")
37+
.arg(clang_target)
38+
.arg(format!("-march={carch}"))
39+
.arg(format!("-flto=thin"))
40+
.arg(format!("-fuse-ld=lld"))
41+
.arg("-nostdlib")
42+
.arg("-o")
43+
.arg(&executable)
44+
.arg("cstart.c")
45+
.arg(tmp_dir().join("libriscv_xlto.rlib"));
46+
eprintln!("{cmd:?}");
47+
let output = cmd.output().unwrap();
48+
if !output.status.success() {
49+
handle_failed_output(output);
50+
}
51+
// Check that the built binary has correct float abi
52+
let llvm_readobj =
53+
PathBuf::from(env::var("LLVM_BIN_DIR").unwrap()).join(bin_name("llvm-readobj"));
54+
let mut cmd = Command::new(llvm_readobj);
55+
cmd.arg("--file-header").arg(executable);
56+
eprintln!("{cmd:?}");
57+
let output = cmd.output().unwrap();
58+
if output.status.success() {
59+
assert!(
60+
!(is_double_float
61+
^ dbg!(str::from_utf8(&output.stdout).unwrap())
62+
.contains("EF_RISCV_FLOAT_ABI_DOUBLE"))
63+
)
64+
} else {
65+
handle_failed_output(output);
66+
}
67+
}
68+
69+
fn main() {
70+
check_target("riscv64gc-unknown-linux-gnu", "riscv64-linux-gnu", "rv64gc", true);
71+
check_target("riscv64imac-unknown-none-elf", "riscv64-unknown-elf", "rv64imac", false);
72+
check_target("riscv32imac-unknown-none-elf", "riscv32-unknown-elf", "rv32imac", false);
73+
check_target("riscv32gc-unknown-linux-gnu", "riscv32-linux-gnu", "rv32gc", true);
74+
}

0 commit comments

Comments
 (0)