Skip to content

Commit

Permalink
[libc][RISCV] Add naked attribute to setjmp/longjmp (#100036)
Browse files Browse the repository at this point in the history
We want to avoid any possibility that the compiler will insert a
prologue/epilogue violating the calling contracts for these special
functions, potentially clobbering registers that must be preserved. To
do that they should be marked naked, as is already the case on ARM.
See #87837 for further context.
  • Loading branch information
ilovepi authored Jul 23, 2024
1 parent 5fc9502 commit 05b586b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions libc/src/setjmp/riscv/longjmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

namespace LIBC_NAMESPACE_DECL {

[[gnu::naked]]
LLVM_LIBC_FUNCTION(void, longjmp, (__jmp_buf * buf, int val)) {
LOAD(ra, buf->__pc);
LOAD(s0, buf->__regs[0]);
Expand Down
1 change: 1 addition & 0 deletions libc/src/setjmp/riscv/setjmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

namespace LIBC_NAMESPACE_DECL {

[[gnu::naked]]
LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) {
STORE(ra, buf->__pc);
STORE(s0, buf->__regs[0]);
Expand Down

0 comments on commit 05b586b

Please sign in to comment.