-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc] Add proxy header for the jmp_buf type #107712
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
Conversation
…from to the typedef alias , fixed the link to LLVM in description
@llvm/pr-subscribers-libc Author: wldfngrs (wldfngrs) ChangesAdded proxy header for the jmp_buf type and changed all use instances from __jmp_buf * to the typedef alias jmp_buf , fixed the link to LLVM in stack_t.h description Full diff: https://github.com/llvm/llvm-project/pull/107712.diff 13 Files Affected:
diff --git a/libc/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt
index 8789e0c7870263..12641c4d93ffe8 100644
--- a/libc/hdr/types/CMakeLists.txt
+++ b/libc/hdr/types/CMakeLists.txt
@@ -190,3 +190,12 @@ add_proxy_header_library(
libc.include.signal
)
+add_proxy_header_library(
+ jmp_buf
+ HDRS
+ jmp_buf.h
+ FULL_BUILD_DEPENDS
+ libc.include.llvm-libc-types.jmp_buf
+ libc.include.setjmp
+)
+
diff --git a/libc/hdr/types/jmp_buf.h b/libc/hdr/types/jmp_buf.h
new file mode 100644
index 00000000000000..943764739f69a7
--- /dev/null
+++ b/libc/hdr/types/jmp_buf.h
@@ -0,0 +1,22 @@
+//===-- Definition of jmp_buf.h ------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apahce License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_HDR_JMP_BUF_H
+#define LLVM_LIBC_HDR_JMP_BUF_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-types/jmp_buf.h"
+
+#else // overlay mode
+
+#include <setjmp.h>
+
+#endif // LLVM_LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_TYPES_JMP_BUF_H
diff --git a/libc/hdr/types/stack_t.h b/libc/hdr/types/stack_t.h
index 8c7c37a5d814ee..9c0f707a7f6d9f 100644
--- a/libc/hdr/types/stack_t.h
+++ b/libc/hdr/types/stack_t.h
@@ -1,7 +1,7 @@
//===-- Definition of stack_t.h -------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https:llvm.or/LICENSE.txt for license information.
+// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//
diff --git a/libc/src/setjmp/aarch64/longjmp.cpp b/libc/src/setjmp/aarch64/longjmp.cpp
index fbb86524e39516..80c97c721cc4f6 100644
--- a/libc/src/setjmp/aarch64/longjmp.cpp
+++ b/libc/src/setjmp/aarch64/longjmp.cpp
@@ -23,7 +23,7 @@ namespace LIBC_NAMESPACE_DECL {
// them.)
[[gnu::naked]] LLVM_LIBC_FUNCTION(void, longjmp,
- ([[maybe_unused]] __jmp_buf * buf,
+ ([[maybe_unused]] jmp_buf buf,
[[maybe_unused]] int val)) {
// If BTI branch protection is in use, the compiler will automatically insert
// a BTI here, so we don't need to make any extra effort to do so.
diff --git a/libc/src/setjmp/aarch64/setjmp.cpp b/libc/src/setjmp/aarch64/setjmp.cpp
index 90e49be49a8fcc..fac249a93da07b 100644
--- a/libc/src/setjmp/aarch64/setjmp.cpp
+++ b/libc/src/setjmp/aarch64/setjmp.cpp
@@ -13,7 +13,7 @@
namespace LIBC_NAMESPACE_DECL {
[[gnu::naked]] LLVM_LIBC_FUNCTION(int, setjmp,
- ([[maybe_unused]] __jmp_buf * buf)) {
+ ([[maybe_unused]] jmp_buf buf)) {
// If BTI branch protection is in use, the compiler will automatically insert
// a BTI here, so we don't need to make any extra effort to do so.
diff --git a/libc/src/setjmp/arm/longjmp.cpp b/libc/src/setjmp/arm/longjmp.cpp
index f36c79df660641..5b8d03b167be7d 100644
--- a/libc/src/setjmp/arm/longjmp.cpp
+++ b/libc/src/setjmp/arm/longjmp.cpp
@@ -16,7 +16,7 @@ namespace LIBC_NAMESPACE_DECL {
#if defined(__thumb__) && __ARM_ARCH_ISA_THUMB == 1
[[gnu::naked, gnu::target("thumb")]]
-LLVM_LIBC_FUNCTION(void, longjmp, (__jmp_buf * buf, int val)) {
+LLVM_LIBC_FUNCTION(void, longjmp, (jmp_buf buf, int val)) {
asm(R"(
# Reload r4, r5, r6, r7.
ldmia r0!, {r4-r7}
@@ -54,7 +54,7 @@ LLVM_LIBC_FUNCTION(void, longjmp, (__jmp_buf * buf, int val)) {
// (d0-d16)
// TODO(https://github.com/llvm/llvm-project/issues/94062): pac+bti
[[gnu::naked]]
-LLVM_LIBC_FUNCTION(void, longjmp, (__jmp_buf * buf, int val)) {
+LLVM_LIBC_FUNCTION(void, longjmp, (jmp_buf buf, int val)) {
asm(R"(
# While sp may appear in a register list for ARM mode, it may not for
# Thumb2 mode. Just load the previous value of sp into r12 then move it
diff --git a/libc/src/setjmp/arm/setjmp.cpp b/libc/src/setjmp/arm/setjmp.cpp
index dc4252a3505096..ab8a980dd2f298 100644
--- a/libc/src/setjmp/arm/setjmp.cpp
+++ b/libc/src/setjmp/arm/setjmp.cpp
@@ -15,7 +15,7 @@ namespace LIBC_NAMESPACE_DECL {
#if defined(__thumb__) && __ARM_ARCH_ISA_THUMB == 1
[[gnu::naked, gnu::target("thumb")]]
-LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) {
+LLVM_LIBC_FUNCTION(int, setjmp, (jmp_buf buf)) {
asm(R"(
# Store r4, r5, r6, and r7 into buf.
stmia r0!, {r4-r7}
@@ -45,7 +45,7 @@ LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) {
// (d0-d16)
// TODO(https://github.com/llvm/llvm-project/issues/94062): pac+bti
[[gnu::naked]]
-LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) {
+LLVM_LIBC_FUNCTION(int, setjmp, (jmp_buf buf)) {
asm(R"(
# While sp may appear in a register list for ARM mode, it may not for
# Thumb2 mode. Just move it into r12 then stm that, so that this code
diff --git a/libc/src/setjmp/longjmp.h b/libc/src/setjmp/longjmp.h
index 29c5c9e1fbc929..9f2f7ddaf06d06 100644
--- a/libc/src/setjmp/longjmp.h
+++ b/libc/src/setjmp/longjmp.h
@@ -10,11 +10,11 @@
#define LLVM_LIBC_SRC_SETJMP_LONGJMP_H
#include "src/__support/macros/config.h"
-#include <setjmp.h>
+#include "hdr/types/jmp_buf.h"
namespace LIBC_NAMESPACE_DECL {
-void longjmp(__jmp_buf *buf, int val);
+void longjmp(jmp_buf buf, int val);
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/setjmp/riscv/longjmp.cpp b/libc/src/setjmp/riscv/longjmp.cpp
index 0f9537ccc41510..16526a45e193e7 100644
--- a/libc/src/setjmp/riscv/longjmp.cpp
+++ b/libc/src/setjmp/riscv/longjmp.cpp
@@ -11,8 +11,6 @@
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/architectures.h"
-#include <setjmp.h>
-
#if !defined(LIBC_TARGET_ARCH_IS_ANY_RISCV)
#error "Invalid file include"
#endif
@@ -30,7 +28,7 @@
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(void, longjmp, (__jmp_buf * buf, int val)) {
+LLVM_LIBC_FUNCTION(void, longjmp, (jmp_buf buf, int val)) {
LOAD(ra, buf->__pc);
LOAD(s0, buf->__regs[0]);
LOAD(s1, buf->__regs[1]);
diff --git a/libc/src/setjmp/riscv/setjmp.cpp b/libc/src/setjmp/riscv/setjmp.cpp
index 12def578b56f34..13cb42e94867c1 100644
--- a/libc/src/setjmp/riscv/setjmp.cpp
+++ b/libc/src/setjmp/riscv/setjmp.cpp
@@ -10,8 +10,6 @@
#include "src/__support/macros/config.h"
#include "src/setjmp/setjmp_impl.h"
-#include <setjmp.h>
-
#if !defined(LIBC_TARGET_ARCH_IS_ANY_RISCV)
#error "Invalid file include"
#endif
@@ -29,7 +27,7 @@
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) {
+LLVM_LIBC_FUNCTION(int, setjmp, (jmp_buf buf)) {
STORE(ra, buf->__pc);
STORE(s0, buf->__regs[0]);
STORE(s1, buf->__regs[1]);
diff --git a/libc/src/setjmp/setjmp_impl.h b/libc/src/setjmp/setjmp_impl.h
index 50d7a6b44503b7..f2304277fe4842 100644
--- a/libc/src/setjmp/setjmp_impl.h
+++ b/libc/src/setjmp/setjmp_impl.h
@@ -12,11 +12,11 @@
// This header has the _impl prefix in its name to avoid conflict with the
// public header setjmp.h which is also included. here.
#include "src/__support/macros/config.h"
-#include <setjmp.h>
+#include "hdr/types/jmp_buf.h"
namespace LIBC_NAMESPACE_DECL {
-int setjmp(__jmp_buf *buf);
+int setjmp(jmp_buf buf);
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/setjmp/x86_64/longjmp.cpp b/libc/src/setjmp/x86_64/longjmp.cpp
index f479c7bc96c977..d4b55565cb2187 100644
--- a/libc/src/setjmp/x86_64/longjmp.cpp
+++ b/libc/src/setjmp/x86_64/longjmp.cpp
@@ -16,7 +16,7 @@
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(void, longjmp, (__jmp_buf * buf, int val)) {
+LLVM_LIBC_FUNCTION(void, longjmp, (jmp_buf buf, int val)) {
register __UINT64_TYPE__ rbx __asm__("rbx");
register __UINT64_TYPE__ rbp __asm__("rbp");
register __UINT64_TYPE__ r12 __asm__("r12");
diff --git a/libc/src/setjmp/x86_64/setjmp.cpp b/libc/src/setjmp/x86_64/setjmp.cpp
index 6a1cc7a83936a5..62d9c13c68e4b6 100644
--- a/libc/src/setjmp/x86_64/setjmp.cpp
+++ b/libc/src/setjmp/x86_64/setjmp.cpp
@@ -16,7 +16,7 @@
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) {
+LLVM_LIBC_FUNCTION(int, setjmp, (jmp_buf buf)) {
register __UINT64_TYPE__ rbx __asm__("rbx");
register __UINT64_TYPE__ r12 __asm__("r12");
register __UINT64_TYPE__ r13 __asm__("r13");
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
@lntue, please review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also remove libc.include.setjmp
in the dependency list in libc/test/src/setjmp/CMakeLists.txt
?
updated for the latest review, @lntue ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
Added proxy header for the jmp_buf type and changed all use instances from __jmp_buf * to the typedef alias jmp_buf , fixed the link to LLVM in stack_t.h description