Skip to content

Commit 05b586b

Browse files
authored
[libc][RISCV] Add naked attribute to setjmp/longjmp (#100036)
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.
1 parent 5fc9502 commit 05b586b

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

libc/src/setjmp/riscv/longjmp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
namespace LIBC_NAMESPACE_DECL {
3232

33+
[[gnu::naked]]
3334
LLVM_LIBC_FUNCTION(void, longjmp, (__jmp_buf * buf, int val)) {
3435
LOAD(ra, buf->__pc);
3536
LOAD(s0, buf->__regs[0]);

libc/src/setjmp/riscv/setjmp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
namespace LIBC_NAMESPACE_DECL {
3131

32+
[[gnu::naked]]
3233
LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) {
3334
STORE(ra, buf->__pc);
3435
STORE(s0, buf->__regs[0]);

0 commit comments

Comments
 (0)