Skip to content

[libunwind][RISCV] Make asm statement volatile #130286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2025

Conversation

futog
Copy link
Contributor

@futog futog commented Mar 7, 2025

Compiling with O3, the early-machinelicm pass hoisted the asm statement to a path that has been executed unconditionally during stack unwinding. On hardware without vector extension support, this resulted in reading a nonexistent register.

@futog futog requested a review from a team as a code owner March 7, 2025 13:58
@llvmbot
Copy link
Member

llvmbot commented Mar 7, 2025

@llvm/pr-subscribers-libunwind

Author: Gergely Futo (futog)

Changes

Compiling with O3, the early-machinelicm pass hoisted the asm statement to a path that has been executed unconditionally during stack unwinding. On hardware without vector extension support, this resulted in reading a nonexistent register.


Full diff: https://github.com/llvm/llvm-project/pull/130286.diff

1 Files Affected:

  • (modified) libunwind/src/Registers.hpp (+1-1)
diff --git a/libunwind/src/Registers.hpp b/libunwind/src/Registers.hpp
index 452f46a0d56ea..3b28874c9ae32 100644
--- a/libunwind/src/Registers.hpp
+++ b/libunwind/src/Registers.hpp
@@ -4126,7 +4126,7 @@ inline reg_t Registers_riscv::getRegister(int regNum) const {
     return _registers[regNum];
   if (regNum == UNW_RISCV_VLENB) {
     reg_t vlenb;
-    __asm__("csrr %0, 0xC22" : "=r"(vlenb));
+    __asm__ volatile ("csrr %0, 0xC22" : "=r"(vlenb));
     return vlenb;
   }
   _LIBUNWIND_ABORT("unsupported riscv register");

Copy link

github-actions bot commented Mar 7, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Compiling with `O3`, the `early-machinelicm` pass hoisted the asm
statement to a path that has been executed unconditionally during
stack unwinding. On hardware without vector extension support, this
resulted in reading a nonexistent register.
@futog futog force-pushed the futog/libunwind-volatile-asm branch from c082d6c to ef22b36 Compare March 7, 2025 14:10
@futog futog merged commit 3acfef5 into llvm:main Mar 10, 2025
80 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants