Skip to content

Commit

Permalink
avoid spurious errors from LLVM
Browse files Browse the repository at this point in the history
  • Loading branch information
romancardenas committed Jan 23, 2024
1 parent 3cfade5 commit 95292c8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
3 changes: 3 additions & 0 deletions riscv-rt/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added

- Patch in assembly code to avoid spurious errors from LLVM

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

Expand Down
4 changes: 2 additions & 2 deletions riscv-rt/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ fn parse_target(target: &str, cargo_flags: &str) -> (u32, HashSet<char>) {
.unwrap();

let mut extensions: HashSet<char> = arch.chars().skip_while(|c| c.is_ascii_digit()).collect();
// get rid of the 'g' shorthand extension
if extensions.remove(&'g') {
// expand the 'g' shorthand extension
if extensions.contains(&'g') {
extensions.insert('i');
extensions.insert('m');
extensions.insert('a');
Expand Down
19 changes: 19 additions & 0 deletions riscv-rt/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ macro_rules! cfg_global_asm {
};
}

// Provisional patch to avoid LLVM spurious errors when compiling in release mode.
// This patch is somewhat hardcoded and relies on the fact that the rustc compiler
// only supports a limited combination of ISA extensions. This patch should be
// removed when LLVM fixes the issue. Alternatively, it must be updated when rustc
// supports more ISA extension combinations.
//
// Related issues:
// - https://github.com/rust-embedded/riscv/issues/175
// - https://github.com/rust-lang/rust/issues/80608
// - https://github.com/llvm/llvm-project/issues/61991
cfg_global_asm!(
#[cfg(all(riscv32, riscvm))]
".attribute arch, \"rv32im\"",
#[cfg(all(riscv64, riscvm, not(riscvg)))]
".attribute arch, \"rv64im\"",
#[cfg(all(riscv64, riscvg))]
".attribute arch, \"rv64g\"",
);

// Entry point of all programs (_start). It initializes DWARF call frame information,
// the stack pointer, the frame pointer (needed for closures to work in start_rust)
// and the global pointer. Then it calls _start_rust.
Expand Down

0 comments on commit 95292c8

Please sign in to comment.