[libc-commits] [libc] becde6d - [libc] Fix issue with sigjmp_buf.h not being found (#150439)

via libc-commits libc-commits at lists.llvm.org
Thu Jul 24 11:50:53 PDT 2025


Author: William Huynh
Date: 2025-07-24T19:50:50+01:00
New Revision: becde6d62e469f2ef11bafd7b0d2ca0c4d72818a

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

LOG: [libc] Fix issue with sigjmp_buf.h not being found (#150439)

When trying to use <setjmp.h>, it will try to include
llvm-libc-types/sigjmp_buf.h due to the way that headergen works. This
commit creates a dummy file, as the real implementation is found in
llvm-libc-types/jmp_buf.h.

Added: 
    libc/hdr/types/sigjmp_buf.h
    libc/include/llvm-libc-types/__jmp_buf.h
    libc/include/llvm-libc-types/sigjmp_buf.h

Modified: 
    libc/hdr/types/CMakeLists.txt
    libc/hdr/types/jmp_buf.h
    libc/include/CMakeLists.txt
    libc/include/llvm-libc-types/CMakeLists.txt
    libc/include/llvm-libc-types/jmp_buf.h
    libc/src/setjmp/aarch64/CMakeLists.txt
    libc/src/setjmp/arm/CMakeLists.txt
    libc/src/setjmp/darwin/CMakeLists.txt
    libc/src/setjmp/darwin/sigsetjmp_epilogue.cpp
    libc/src/setjmp/linux/CMakeLists.txt
    libc/src/setjmp/linux/sigsetjmp_epilogue.cpp
    libc/src/setjmp/riscv/CMakeLists.txt
    libc/src/setjmp/sigsetjmp.h
    libc/src/setjmp/sigsetjmp_epilogue.h
    libc/src/setjmp/x86_64/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/libc/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt
index bf85bf69425e9..c21236307a91d 100644
--- a/libc/hdr/types/CMakeLists.txt
+++ b/libc/hdr/types/CMakeLists.txt
@@ -319,6 +319,15 @@ add_proxy_header_library(
     libc.include.setjmp
 )
 
+add_proxy_header_library(
+  sigjmp_buf
+  HDRS
+    sigjmp_buf.h
+  FULL_BUILD_DEPENDS
+    libc.include.llvm-libc-types.sigjmp_buf
+    libc.include.setjmp
+)
+
 add_proxy_header_library(
   struct_msghdr
   HDRS

diff  --git a/libc/hdr/types/jmp_buf.h b/libc/hdr/types/jmp_buf.h
index 3fa1de816d703..b242f84f221f9 100644
--- a/libc/hdr/types/jmp_buf.h
+++ b/libc/hdr/types/jmp_buf.h
@@ -1,4 +1,4 @@
-//===-- Definition of jmp_buf.h ------------------------------------------===//
+//===-- 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.

diff  --git a/libc/hdr/types/sigjmp_buf.h b/libc/hdr/types/sigjmp_buf.h
new file mode 100644
index 0000000000000..5da52435dcb63
--- /dev/null
+++ b/libc/hdr/types/sigjmp_buf.h
@@ -0,0 +1,22 @@
+//===-- Definition of sigjmp_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_TYPES_SIGJMP_BUF_H
+#define LLVM_LIBC_HDR_TYPES_SIGJMP_BUF_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-types/sigjmp_buf.h"
+
+#else // overlay mode
+
+#include <setjmp.h>
+
+#endif // LLVM_LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_TYPES_SIGJMP_BUF_H

diff  --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index fafc1377926c5..120f3850b5cee 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -215,6 +215,7 @@ add_header_macro(
   DEPENDS
     .llvm_libc_common_h
     .llvm-libc-types.jmp_buf
+    .llvm-libc-types.sigjmp_buf
 )
 
 add_header_macro(

diff  --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index b24c97301668a..4ccdde619a39e 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -82,7 +82,9 @@ add_header(union_sigval HDR union_sigval.h)
 add_header(siginfo_t HDR siginfo_t.h DEPENDS .union_sigval .pid_t .uid_t .clock_t)
 add_header(sig_atomic_t HDR sig_atomic_t.h)
 add_header(sigset_t HDR sigset_t.h DEPENDS libc.include.llvm-libc-macros.signal_macros)
-add_header(jmp_buf HDR jmp_buf.h DEPENDS .sigset_t)
+add_header(__jmp_buf HDR __jmp_buf.h DEPENDS .sigset_t)
+add_header(jmp_buf HDR jmp_buf.h DEPENDS .__jmp_buf)
+add_header(sigjmp_buf HDR sigjmp_buf.h DEPENDS .__jmp_buf)
 add_header(struct_sigaction HDR struct_sigaction.h DEPENDS .sigset_t .siginfo_t)
 add_header(struct_timespec HDR struct_timespec.h DEPENDS .time_t)
 add_header(

diff  --git a/libc/include/llvm-libc-types/__jmp_buf.h b/libc/include/llvm-libc-types/__jmp_buf.h
new file mode 100644
index 0000000000000..a80afa2e6b815
--- /dev/null
+++ b/libc/include/llvm-libc-types/__jmp_buf.h
@@ -0,0 +1,78 @@
+//===-- Definition of type __jmp_buf --------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache 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_TYPES___JMP_BUF_H
+#define LLVM_LIBC_TYPES___JMP_BUF_H
+
+// TODO: implement sigjmp_buf related functions for other architectures
+// Issue: https://github.com/llvm/llvm-project/issues/136358
+#if defined(__linux__)
+#if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__) ||        \
+    defined(__arm__) || defined(__riscv)
+#define __LIBC_HAS_SIGJMP_BUF
+#endif
+#endif
+
+#if defined(__LIBC_HAS_SIGJMP_BUF)
+#include "sigset_t.h"
+#endif
+
+typedef struct {
+#ifdef __x86_64__
+  __UINT64_TYPE__ rbx;
+  __UINT64_TYPE__ rbp;
+  __UINT64_TYPE__ r12;
+  __UINT64_TYPE__ r13;
+  __UINT64_TYPE__ r14;
+  __UINT64_TYPE__ r15;
+  __UINTPTR_TYPE__ rsp;
+  __UINTPTR_TYPE__ rip;
+#elif defined(__i386__)
+  long ebx;
+  long esi;
+  long edi;
+  long ebp;
+  long esp;
+  long eip;
+#elif defined(__riscv)
+  /* Program counter.  */
+  long int __pc;
+  /* Callee-saved registers.  */
+  long int __regs[12];
+  /* Stack pointer.  */
+  long int __sp;
+  /* Callee-saved floating point registers.  */
+#if __riscv_float_abi_double
+  double __fpregs[12];
+#elif defined(__riscv_float_abi_single)
+#error "__jmp_buf not available for your target architecture."
+#endif
+#elif defined(__arm__)
+  // r4, r5, r6, r7, r8, r9, r10, r11, r12, lr
+  long opaque[10];
+#elif defined(__aarch64__)
+  long opaque[14]; // x19-x29, lr, sp, optional x18
+#if __ARM_FP
+  long fopaque[8]; // d8-d15
+#endif
+#else
+#error "__jmp_buf not available for your target architecture."
+#endif
+#if defined(__LIBC_HAS_SIGJMP_BUF)
+  // return address
+  void *sig_retaddr;
+  // extra register buffer to avoid indefinite stack growth in sigsetjmp
+  void *sig_extra;
+  // signal masks
+  sigset_t sigmask;
+#endif
+} __jmp_buf;
+
+#undef __LIBC_HAS_SIGJMP_BUF
+
+#endif // LLVM_LIBC_TYPES___JMP_BUF_H

diff  --git a/libc/include/llvm-libc-types/jmp_buf.h b/libc/include/llvm-libc-types/jmp_buf.h
index 8a7d2839e21d4..599310f95b3ca 100644
--- a/libc/include/llvm-libc-types/jmp_buf.h
+++ b/libc/include/llvm-libc-types/jmp_buf.h
@@ -9,76 +9,8 @@
 #ifndef LLVM_LIBC_TYPES_JMP_BUF_H
 #define LLVM_LIBC_TYPES_JMP_BUF_H
 
-// TODO: implement sigjmp_buf related functions for other architectures
-// Issue: https://github.com/llvm/llvm-project/issues/136358
-#if defined(__linux__)
-#if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__) ||        \
-    defined(__arm__) || defined(__riscv)
-#define __LIBC_HAS_SIGJMP_BUF
-#endif
-#endif
-
-#if defined(__LIBC_HAS_SIGJMP_BUF)
-#include "sigset_t.h"
-#endif
-
-typedef struct {
-#ifdef __x86_64__
-  __UINT64_TYPE__ rbx;
-  __UINT64_TYPE__ rbp;
-  __UINT64_TYPE__ r12;
-  __UINT64_TYPE__ r13;
-  __UINT64_TYPE__ r14;
-  __UINT64_TYPE__ r15;
-  __UINTPTR_TYPE__ rsp;
-  __UINTPTR_TYPE__ rip;
-#elif defined(__i386__)
-  long ebx;
-  long esi;
-  long edi;
-  long ebp;
-  long esp;
-  long eip;
-#elif defined(__riscv)
-  /* Program counter.  */
-  long int __pc;
-  /* Callee-saved registers.  */
-  long int __regs[12];
-  /* Stack pointer.  */
-  long int __sp;
-  /* Callee-saved floating point registers.  */
-#if __riscv_float_abi_double
-  double __fpregs[12];
-#elif defined(__riscv_float_abi_single)
-#error "__jmp_buf not available for your target architecture."
-#endif
-#elif defined(__arm__)
-  // r4, r5, r6, r7, r8, r9, r10, r11, r12, lr
-  long opaque[10];
-#elif defined(__aarch64__)
-  long opaque[14]; // x19-x29, lr, sp, optional x18
-#if __ARM_FP
-  long fopaque[8]; // d8-d15
-#endif
-#else
-#error "__jmp_buf not available for your target architecture."
-#endif
-#if defined(__LIBC_HAS_SIGJMP_BUF)
-  // return address
-  void *sig_retaddr;
-  // extra register buffer to avoid indefinite stack growth in sigsetjmp
-  void *sig_extra;
-  // signal masks
-  sigset_t sigmask;
-#endif
-} __jmp_buf;
+#include "__jmp_buf.h"
 
 typedef __jmp_buf jmp_buf[1];
 
-#if defined(__LIBC_HAS_SIGJMP_BUF)
-typedef __jmp_buf sigjmp_buf[1];
-#endif
-
-#undef __LIBC_HAS_SIGJMP_BUF
-
 #endif // LLVM_LIBC_TYPES_JMP_BUF_H

diff  --git a/libc/include/llvm-libc-types/sigjmp_buf.h b/libc/include/llvm-libc-types/sigjmp_buf.h
new file mode 100644
index 0000000000000..ae9028b188f12
--- /dev/null
+++ b/libc/include/llvm-libc-types/sigjmp_buf.h
@@ -0,0 +1,16 @@
+//===-- Definition of type sigjmp_buf -------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache 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_TYPES_SIGJMP_BUF_H
+#define LLVM_LIBC_TYPES_SIGJMP_BUF_H
+
+#include "__jmp_buf.h"
+
+typedef __jmp_buf sigjmp_buf[1];
+
+#endif // LLVM_LIBC_TYPES_SIGJMP_BUF_H

diff  --git a/libc/src/setjmp/aarch64/CMakeLists.txt b/libc/src/setjmp/aarch64/CMakeLists.txt
index 1078af8ce04f3..12991101b0fdd 100644
--- a/libc/src/setjmp/aarch64/CMakeLists.txt
+++ b/libc/src/setjmp/aarch64/CMakeLists.txt
@@ -34,7 +34,7 @@ add_entrypoint_object(
   HDRS
     ../sigsetjmp.h
   DEPENDS
-    libc.hdr.types.jmp_buf
+    libc.hdr.types.sigjmp_buf
     libc.hdr.types.sigset_t
     libc.hdr.offsetof_macros
     libc.src.setjmp.sigsetjmp_epilogue

diff  --git a/libc/src/setjmp/arm/CMakeLists.txt b/libc/src/setjmp/arm/CMakeLists.txt
index 77f8471c06bb8..7a48da3d29e0e 100644
--- a/libc/src/setjmp/arm/CMakeLists.txt
+++ b/libc/src/setjmp/arm/CMakeLists.txt
@@ -16,7 +16,7 @@ if (TARGET libc.src.setjmp.sigsetjmp_epilogue)
     HDRS
       ../sigsetjmp.h
     DEPENDS
-      libc.hdr.types.jmp_buf
+      libc.hdr.types.sigjmp_buf
       libc.hdr.types.sigset_t
       libc.hdr.offsetof_macros
       libc.src.setjmp.sigsetjmp_epilogue

diff  --git a/libc/src/setjmp/darwin/CMakeLists.txt b/libc/src/setjmp/darwin/CMakeLists.txt
index b844c8c5ee55a..62acec0fa7fdb 100644
--- a/libc/src/setjmp/darwin/CMakeLists.txt
+++ b/libc/src/setjmp/darwin/CMakeLists.txt
@@ -7,6 +7,6 @@ add_object_library(
   DEPENDS
     libc.src.__support.common
     libc.src.__support.OSUtil.osutil
-    libc.hdr.types.jmp_buf
+    libc.hdr.types.sigjmp_buf
     libc.hdr.types.sigset_t
 )

diff  --git a/libc/src/setjmp/darwin/sigsetjmp_epilogue.cpp b/libc/src/setjmp/darwin/sigsetjmp_epilogue.cpp
index b2ca4d99ed82b..568545a20c50c 100644
--- a/libc/src/setjmp/darwin/sigsetjmp_epilogue.cpp
+++ b/libc/src/setjmp/darwin/sigsetjmp_epilogue.cpp
@@ -12,7 +12,7 @@
 #include "src/signal/sigprocmask.h"
 
 namespace LIBC_NAMESPACE_DECL {
-[[gnu::returns_twice]] int sigsetjmp_epilogue(jmp_buf buffer, int retval) {
+[[gnu::returns_twice]] int sigsetjmp_epilogue(sigjmp_buf buffer, int retval) {
   syscall_impl<long>(sigprocmask, SIG_SETMASK,
                      /* set= */ retval ? &buffer->sigmask : nullptr,
                      /* old_set= */ retval ? nullptr : &buffer->sigmask);

diff  --git a/libc/src/setjmp/linux/CMakeLists.txt b/libc/src/setjmp/linux/CMakeLists.txt
index b844c8c5ee55a..62acec0fa7fdb 100644
--- a/libc/src/setjmp/linux/CMakeLists.txt
+++ b/libc/src/setjmp/linux/CMakeLists.txt
@@ -7,6 +7,6 @@ add_object_library(
   DEPENDS
     libc.src.__support.common
     libc.src.__support.OSUtil.osutil
-    libc.hdr.types.jmp_buf
+    libc.hdr.types.sigjmp_buf
     libc.hdr.types.sigset_t
 )

diff  --git a/libc/src/setjmp/linux/sigsetjmp_epilogue.cpp b/libc/src/setjmp/linux/sigsetjmp_epilogue.cpp
index 4718623c488ec..7e14312297450 100644
--- a/libc/src/setjmp/linux/sigsetjmp_epilogue.cpp
+++ b/libc/src/setjmp/linux/sigsetjmp_epilogue.cpp
@@ -12,7 +12,7 @@
 #include <sys/syscall.h> // For syscall numbers.
 
 namespace LIBC_NAMESPACE_DECL {
-[[gnu::returns_twice]] int sigsetjmp_epilogue(jmp_buf buffer, int retval) {
+[[gnu::returns_twice]] int sigsetjmp_epilogue(sigjmp_buf buffer, int retval) {
   // If set is NULL, then the signal mask is unchanged (i.e., how is
   // ignored), but the current value of the signal mask is nevertheless
   // returned in oldset (if it is not NULL).

diff  --git a/libc/src/setjmp/riscv/CMakeLists.txt b/libc/src/setjmp/riscv/CMakeLists.txt
index 1959e9c905e23..ee3ea28c47a0a 100644
--- a/libc/src/setjmp/riscv/CMakeLists.txt
+++ b/libc/src/setjmp/riscv/CMakeLists.txt
@@ -19,7 +19,7 @@ if (TARGET libc.src.setjmp.sigsetjmp_epilogue)
     HDRS
       ../sigsetjmp.h
     DEPENDS
-      libc.hdr.types.jmp_buf
+      libc.hdr.types.sigjmp_buf
       libc.hdr.types.sigset_t
       libc.hdr.offsetof_macros
       libc.src.setjmp.sigsetjmp_epilogue

diff  --git a/libc/src/setjmp/sigsetjmp.h b/libc/src/setjmp/sigsetjmp.h
index ef060c8b344a6..6e08bd6a11e88 100644
--- a/libc/src/setjmp/sigsetjmp.h
+++ b/libc/src/setjmp/sigsetjmp.h
@@ -9,7 +9,7 @@
 #ifndef LLVM_LIBC_SRC_SETJMP_SIGSETJMP_H
 #define LLVM_LIBC_SRC_SETJMP_SIGSETJMP_H
 
-#include "hdr/types/jmp_buf.h"
+#include "hdr/types/sigjmp_buf.h"
 #include "src/__support/macros/config.h"
 #include "src/__support/macros/properties/compiler.h"
 

diff  --git a/libc/src/setjmp/sigsetjmp_epilogue.h b/libc/src/setjmp/sigsetjmp_epilogue.h
index 88702b743940f..7508d4a1ec030 100644
--- a/libc/src/setjmp/sigsetjmp_epilogue.h
+++ b/libc/src/setjmp/sigsetjmp_epilogue.h
@@ -9,11 +9,11 @@
 #ifndef LLVM_LIBC_SRC_SETJMP_SIGSETJMP_EPILOGUE_H
 #define LLVM_LIBC_SRC_SETJMP_SIGSETJMP_EPILOGUE_H
 
-#include "hdr/types/jmp_buf.h"
+#include "hdr/types/sigjmp_buf.h"
 #include "src/__support/common.h"
 
 namespace LIBC_NAMESPACE_DECL {
-[[gnu::returns_twice]] int sigsetjmp_epilogue(jmp_buf buffer, int retval);
+[[gnu::returns_twice]] int sigsetjmp_epilogue(sigjmp_buf buffer, int retval);
 } // namespace LIBC_NAMESPACE_DECL
 
 #endif // LLVM_LIBC_SRC_SETJMP_SIGSETJMP_EPILOGUE_H

diff  --git a/libc/src/setjmp/x86_64/CMakeLists.txt b/libc/src/setjmp/x86_64/CMakeLists.txt
index 03ed5fb647084..5f87bc6cbbbfb 100644
--- a/libc/src/setjmp/x86_64/CMakeLists.txt
+++ b/libc/src/setjmp/x86_64/CMakeLists.txt
@@ -16,7 +16,7 @@ if (TARGET libc.src.setjmp.sigsetjmp_epilogue)
     HDRS
       ../sigsetjmp.h
     DEPENDS
-      libc.hdr.types.jmp_buf
+      libc.hdr.types.sigjmp_buf
       libc.hdr.types.sigset_t
       libc.hdr.offsetof_macros
       libc.src.setjmp.sigsetjmp_epilogue


        


More information about the libc-commits mailing list