Skip to content

Commit 59cbc52

Browse files
authored
Merge pull request #176 from rust-embedded/llvm-error
Avoid spurious errors from LLVM
2 parents 3cfade5 + aa088e8 commit 59cbc52

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

riscv-rt/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Patch in assembly code to avoid spurious errors from LLVM
1013

1114
## [v0.12.0] - 2024-01-14
1215

riscv-rt/build.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ fn parse_target(target: &str, cargo_flags: &str) -> (u32, HashSet<char>) {
3434
.unwrap();
3535

3636
let mut extensions: HashSet<char> = arch.chars().skip_while(|c| c.is_ascii_digit()).collect();
37-
// get rid of the 'g' shorthand extension
38-
if extensions.remove(&'g') {
37+
// expand the 'g' shorthand extension
38+
if extensions.contains(&'g') {
3939
extensions.insert('i');
4040
extensions.insert('m');
4141
extensions.insert('a');

riscv-rt/src/asm.rs

+20
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,26 @@ macro_rules! cfg_global_asm {
1919
};
2020
}
2121

22+
// Provisional patch to avoid LLVM spurious errors when compiling in release mode.
23+
// This patch is somewhat hardcoded and relies on the fact that the rustc compiler
24+
// only supports a limited combination of ISA extensions. This patch should be
25+
// removed when LLVM fixes the issue. Alternatively, it must be updated when rustc
26+
// supports more ISA extension combinations.
27+
//
28+
// Related issues:
29+
// - https://github.com/rust-embedded/riscv/issues/175
30+
// - https://github.com/rust-lang/rust/issues/80608
31+
// - https://github.com/llvm/llvm-project/issues/61991
32+
cfg_global_asm!(
33+
"// Provisional patch to avoid LLVM spurious errors when compiling in release mode.",
34+
#[cfg(all(riscv32, riscvm))]
35+
".attribute arch, \"rv32im\"",
36+
#[cfg(all(riscv64, riscvm, not(riscvg)))]
37+
".attribute arch, \"rv64im\"",
38+
#[cfg(all(riscv64, riscvg))]
39+
".attribute arch, \"rv64g\"",
40+
);
41+
2242
// Entry point of all programs (_start). It initializes DWARF call frame information,
2343
// the stack pointer, the frame pointer (needed for closures to work in start_rust)
2444
// and the global pointer. Then it calls _start_rust.

0 commit comments

Comments
 (0)