trapframe-rs icon indicating copy to clipboard operation
trapframe-rs copied to clipboard

fix(riscv): don't split stateful assembly directives across global_asm instances

Open mkroening opened this issue 3 months ago • 2 comments

Relying on stateful directives to persist across inline assembly instances is forbidden: https://doc.rust-lang.org/reference/inline-assembly.html#r-asm.directives.stateful

Without this patch, in some scenarios, trapframe fails to compile, since the macros XLENB, LOAD_SP, and STORE_SP may not be available:

error: operand must be a symbol with %lo/%pcrel_lo/%tprel_lo specifier or an integer in the range [-2048, 2047]
   |
note: instantiated into assembly here
  --> <inline asm>:17:18
   |
17 |     addi sp, sp, -34 * XLENB
   |                  ^

error: unrecognized instruction mnemonic
   |
note: instantiated into assembly here
  --> <inline asm>:21:5
   |
21 |     STORE_SP x1, 1
   |     ^
...
error: could not compile `trapframe` (lib) due to 99 previous errors

mkroening avatar Aug 18 '25 10:08 mkroening

CC: @simonschoening

mkroening avatar Aug 18 '25 10:08 mkroening

This is the same issue as https://github.com/rust-embedded/riscv/issues/321, which was resolved in https://github.com/rust-embedded/riscv/pull/322.

mkroening avatar Sep 09 '25 12:09 mkroening