-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[libc][RISCV] Add naked attribute to setjmp/longjmp #100036
[libc][RISCV] Add naked attribute to setjmp/longjmp #100036
Conversation
Created using spr 1.3.4
@llvm/pr-subscribers-libc Author: Paul Kirth (ilovepi) ChangesWe want to avoid any possibility that the compiler will insert a Full diff: https://github.com/llvm/llvm-project/pull/100036.diff 2 Files Affected:
diff --git a/libc/src/setjmp/riscv/longjmp.cpp b/libc/src/setjmp/riscv/longjmp.cpp
index 0f9537ccc4151..b14f636659ac3 100644
--- a/libc/src/setjmp/riscv/longjmp.cpp
+++ b/libc/src/setjmp/riscv/longjmp.cpp
@@ -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]);
diff --git a/libc/src/setjmp/riscv/setjmp.cpp b/libc/src/setjmp/riscv/setjmp.cpp
index 12def578b56f3..92982cc9d74d4 100644
--- a/libc/src/setjmp/riscv/setjmp.cpp
+++ b/libc/src/setjmp/riscv/setjmp.cpp
@@ -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]);
|
LGTM but please wait for @michaelrj-google @lntue or @petrhosek to give the go-ahead. There were some discussions about these functions in the past so better to double-check with them first. |
Happy to wait, but |
From the previous discussion and experiment by @nickdesaulniers , naked attribute + inline asm seems to be the cleanest: #87837 (comment) |
Reverts #100036 This caused a failure on bots: https://lab.llvm.org/buildbot/#/builders/183/builds/1799 We likely need to discuss the particulars here a bit more deeply before either relanding or choosing an alternate solution.
Summary: 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. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251407
Summary: Reverts #100036 This caused a failure on bots: https://lab.llvm.org/buildbot/#/builders/183/builds/1799 We likely need to discuss the particulars here a bit more deeply before either relanding or choosing an alternate solution. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251135
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.