[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.
This commit is contained in:
William Huynh 2025-07-24 19:50:50 +01:00 committed by GitHub
parent d5d94ba8bc
commit becde6d62e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 142 additions and 82 deletions

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -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(

View File

@ -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(

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
)

View File

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

View File

@ -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
)

View File

@ -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).

View File

@ -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

View File

@ -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"

View File

@ -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

View File

@ -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