[libc-commits] [libc] 3d7af09 - [libc] Add proxy header for the jmp_buf type (#107712)

via libc-commits libc-commits at lists.llvm.org
Sun Sep 8 17:55:04 PDT 2024


Author: wldfngrs
Date: 2024-09-08T20:55:00-04:00
New Revision: 3d7af093f3d7b5c025e727277b9cc2b899c2d84e

URL: https://github.com/llvm/llvm-project/commit/3d7af093f3d7b5c025e727277b9cc2b899c2d84e
DIFF: https://github.com/llvm/llvm-project/commit/3d7af093f3d7b5c025e727277b9cc2b899c2d84e.diff

LOG: [libc] Add proxy header for the jmp_buf type (#107712)

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

Added: 
    libc/hdr/types/jmp_buf.h

Modified: 
    libc/hdr/types/CMakeLists.txt
    libc/hdr/types/stack_t.h
    libc/src/setjmp/aarch64/CMakeLists.txt
    libc/src/setjmp/aarch64/longjmp.cpp
    libc/src/setjmp/aarch64/setjmp.cpp
    libc/src/setjmp/arm/CMakeLists.txt
    libc/src/setjmp/arm/longjmp.cpp
    libc/src/setjmp/arm/setjmp.cpp
    libc/src/setjmp/longjmp.h
    libc/src/setjmp/riscv/CMakeLists.txt
    libc/src/setjmp/riscv/longjmp.cpp
    libc/src/setjmp/riscv/setjmp.cpp
    libc/src/setjmp/setjmp_impl.h
    libc/src/setjmp/x86_64/CMakeLists.txt
    libc/src/setjmp/x86_64/longjmp.cpp
    libc/src/setjmp/x86_64/setjmp.cpp
    libc/test/src/setjmp/CMakeLists.txt

Removed: 
    


################################################################################
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/CMakeLists.txt b/libc/src/setjmp/aarch64/CMakeLists.txt
index 47eeb1a5c0ea6a..e0e7702c7c4b61 100644
--- a/libc/src/setjmp/aarch64/CMakeLists.txt
+++ b/libc/src/setjmp/aarch64/CMakeLists.txt
@@ -12,7 +12,7 @@ add_entrypoint_object(
   HDRS
     ../setjmp_impl.h
   DEPENDS
-    libc.include.setjmp
+    libc.hdr.types.jmp_buf
   ${setjmp_config_options}
 )
 
@@ -23,6 +23,6 @@ add_entrypoint_object(
   HDRS
     ../longjmp.h
   DEPENDS
-    libc.include.setjmp
+    libc.hdr.types.jmp_buf
   ${setjmp_config_options}
 )

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..8dd1eb342c0973 100644
--- a/libc/src/setjmp/aarch64/setjmp.cpp
+++ b/libc/src/setjmp/aarch64/setjmp.cpp
@@ -12,8 +12,7 @@
 
 namespace LIBC_NAMESPACE_DECL {
 
-[[gnu::naked]] LLVM_LIBC_FUNCTION(int, setjmp,
-                                  ([[maybe_unused]] __jmp_buf * buf)) {
+[[gnu::naked]] LLVM_LIBC_FUNCTION(int, setjmp, ([[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/CMakeLists.txt b/libc/src/setjmp/arm/CMakeLists.txt
index da97b79c9fea01..55c80b0bede0df 100644
--- a/libc/src/setjmp/arm/CMakeLists.txt
+++ b/libc/src/setjmp/arm/CMakeLists.txt
@@ -5,7 +5,7 @@ add_entrypoint_object(
   HDRS
     ../setjmp_impl.h
   DEPENDS
-    libc.include.setjmp
+    libc.hdr.types.jmp_buf
 )
 
 add_entrypoint_object(
@@ -15,5 +15,5 @@ add_entrypoint_object(
   HDRS
     ../longjmp.h
   DEPENDS
-    libc.include.setjmp
+    libc.hdr.types.jmp_buf
 )

diff  --git a/libc/src/setjmp/arm/longjmp.cpp b/libc/src/setjmp/arm/longjmp.cpp
index f36c79df660641..623ca8fc77be6a 100644
--- a/libc/src/setjmp/arm/longjmp.cpp
+++ b/libc/src/setjmp/arm/longjmp.cpp
@@ -15,8 +15,9 @@ 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)) {
+[[gnu::naked, gnu::target("thumb")]] LLVM_LIBC_FUNCTION(void, longjmp,
+                                                        (jmp_buf buf,
+                                                         int val)) {
   asm(R"(
       # Reload r4, r5, r6, r7.
       ldmia r0!, {r4-r7}
@@ -53,8 +54,7 @@ LLVM_LIBC_FUNCTION(void, longjmp, (__jmp_buf * buf, int val)) {
 // TODO(https://github.com/llvm/llvm-project/issues/94061): fp registers
 // (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)) {
+[[gnu::naked]] 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..891ac3016c050e 100644
--- a/libc/src/setjmp/arm/setjmp.cpp
+++ b/libc/src/setjmp/arm/setjmp.cpp
@@ -14,8 +14,8 @@ 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)) {
+[[gnu::naked, gnu::target("thumb")]] LLVM_LIBC_FUNCTION(int, setjmp,
+                                                        (jmp_buf buf)) {
   asm(R"(
       # Store r4, r5, r6, and r7 into buf.
       stmia r0!, {r4-r7}
@@ -44,8 +44,7 @@ LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) {
 // TODO(https://github.com/llvm/llvm-project/issues/94061): fp registers
 // (d0-d16)
 // TODO(https://github.com/llvm/llvm-project/issues/94062): pac+bti
-[[gnu::naked]]
-LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) {
+[[gnu::naked]] 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..7cb12b3392ae16 100644
--- a/libc/src/setjmp/longjmp.h
+++ b/libc/src/setjmp/longjmp.h
@@ -9,12 +9,12 @@
 #ifndef LLVM_LIBC_SRC_SETJMP_LONGJMP_H
 #define LLVM_LIBC_SRC_SETJMP_LONGJMP_H
 
+#include "hdr/types/jmp_buf.h"
 #include "src/__support/macros/config.h"
-#include <setjmp.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/CMakeLists.txt b/libc/src/setjmp/riscv/CMakeLists.txt
index 8c6c8e204abd77..464144758cbbea 100644
--- a/libc/src/setjmp/riscv/CMakeLists.txt
+++ b/libc/src/setjmp/riscv/CMakeLists.txt
@@ -5,7 +5,7 @@ add_entrypoint_object(
   HDRS
     ../setjmp_impl.h
   DEPENDS
-    libc.include.setjmp
+    libc.hdr.types.jmp_buf
   COMPILE_OPTIONS
     -O3
     -fomit-frame-pointer
@@ -18,7 +18,7 @@ add_entrypoint_object(
   HDRS
     ../longjmp.h
   DEPENDS
-    libc.include.setjmp
+    libc.hdr.types.jmp_buf
   COMPILE_OPTIONS
     -O3
     -fomit-frame-pointer

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..4175a7397ae187 100644
--- a/libc/src/setjmp/setjmp_impl.h
+++ b/libc/src/setjmp/setjmp_impl.h
@@ -11,12 +11,12 @@
 
 // This header has the _impl prefix in its name to avoid conflict with the
 // public header setjmp.h which is also included. here.
+#include "hdr/types/jmp_buf.h"
 #include "src/__support/macros/config.h"
-#include <setjmp.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/CMakeLists.txt b/libc/src/setjmp/x86_64/CMakeLists.txt
index ae84322a654010..c789e5def7fe79 100644
--- a/libc/src/setjmp/x86_64/CMakeLists.txt
+++ b/libc/src/setjmp/x86_64/CMakeLists.txt
@@ -5,7 +5,7 @@ add_entrypoint_object(
   HDRS
     ../setjmp_impl.h
   DEPENDS
-    libc.include.setjmp
+    libc.hdr.types.jmp_buf
   COMPILE_OPTIONS
     -O3
     -fno-omit-frame-pointer
@@ -23,7 +23,7 @@ add_entrypoint_object(
   HDRS
     ../longjmp.h
   DEPENDS
-    libc.include.setjmp
+    libc.hdr.types.jmp_buf
   COMPILE_OPTIONS
     -O3
     -fomit-frame-pointer

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");

diff  --git a/libc/test/src/setjmp/CMakeLists.txt b/libc/test/src/setjmp/CMakeLists.txt
index f637842c034257..049df89ba39a6f 100644
--- a/libc/test/src/setjmp/CMakeLists.txt
+++ b/libc/test/src/setjmp/CMakeLists.txt
@@ -12,7 +12,6 @@ add_libc_unittest(
   SRCS
     setjmp_test.cpp
   DEPENDS
-    libc.include.setjmp
     libc.src.setjmp.longjmp
     libc.src.setjmp.setjmp
 )


        


More information about the libc-commits mailing list