Skip to content

Commit becde6d

Browse files
authored
[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.
1 parent d5d94ba commit becde6d

File tree

18 files changed

+142
-82
lines changed

18 files changed

+142
-82
lines changed

libc/hdr/types/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,15 @@ add_proxy_header_library(
319319
libc.include.setjmp
320320
)
321321

322+
add_proxy_header_library(
323+
sigjmp_buf
324+
HDRS
325+
sigjmp_buf.h
326+
FULL_BUILD_DEPENDS
327+
libc.include.llvm-libc-types.sigjmp_buf
328+
libc.include.setjmp
329+
)
330+
322331
add_proxy_header_library(
323332
struct_msghdr
324333
HDRS

libc/hdr/types/jmp_buf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- Definition of jmp_buf.h ------------------------------------------===//
1+
//===-- Definition of jmp_buf.h -------------------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apahce License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.

libc/hdr/types/sigjmp_buf.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Definition of sigjmp_buf.h ----------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apahce License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_HDR_TYPES_SIGJMP_BUF_H
10+
#define LLVM_LIBC_HDR_TYPES_SIGJMP_BUF_H
11+
12+
#ifdef LIBC_FULL_BUILD
13+
14+
#include "include/llvm-libc-types/sigjmp_buf.h"
15+
16+
#else // overlay mode
17+
18+
#include <setjmp.h>
19+
20+
#endif // LLVM_LIBC_FULL_BUILD
21+
22+
#endif // LLVM_LIBC_HDR_TYPES_SIGJMP_BUF_H

libc/include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ add_header_macro(
215215
DEPENDS
216216
.llvm_libc_common_h
217217
.llvm-libc-types.jmp_buf
218+
.llvm-libc-types.sigjmp_buf
218219
)
219220

220221
add_header_macro(

libc/include/llvm-libc-types/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ add_header(union_sigval HDR union_sigval.h)
8282
add_header(siginfo_t HDR siginfo_t.h DEPENDS .union_sigval .pid_t .uid_t .clock_t)
8383
add_header(sig_atomic_t HDR sig_atomic_t.h)
8484
add_header(sigset_t HDR sigset_t.h DEPENDS libc.include.llvm-libc-macros.signal_macros)
85-
add_header(jmp_buf HDR jmp_buf.h DEPENDS .sigset_t)
85+
add_header(__jmp_buf HDR __jmp_buf.h DEPENDS .sigset_t)
86+
add_header(jmp_buf HDR jmp_buf.h DEPENDS .__jmp_buf)
87+
add_header(sigjmp_buf HDR sigjmp_buf.h DEPENDS .__jmp_buf)
8688
add_header(struct_sigaction HDR struct_sigaction.h DEPENDS .sigset_t .siginfo_t)
8789
add_header(struct_timespec HDR struct_timespec.h DEPENDS .time_t)
8890
add_header(
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//===-- Definition of type __jmp_buf --------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_TYPES___JMP_BUF_H
10+
#define LLVM_LIBC_TYPES___JMP_BUF_H
11+
12+
// TODO: implement sigjmp_buf related functions for other architectures
13+
// Issue: https://github.com/llvm/llvm-project/issues/136358
14+
#if defined(__linux__)
15+
#if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__) || \
16+
defined(__arm__) || defined(__riscv)
17+
#define __LIBC_HAS_SIGJMP_BUF
18+
#endif
19+
#endif
20+
21+
#if defined(__LIBC_HAS_SIGJMP_BUF)
22+
#include "sigset_t.h"
23+
#endif
24+
25+
typedef struct {
26+
#ifdef __x86_64__
27+
__UINT64_TYPE__ rbx;
28+
__UINT64_TYPE__ rbp;
29+
__UINT64_TYPE__ r12;
30+
__UINT64_TYPE__ r13;
31+
__UINT64_TYPE__ r14;
32+
__UINT64_TYPE__ r15;
33+
__UINTPTR_TYPE__ rsp;
34+
__UINTPTR_TYPE__ rip;
35+
#elif defined(__i386__)
36+
long ebx;
37+
long esi;
38+
long edi;
39+
long ebp;
40+
long esp;
41+
long eip;
42+
#elif defined(__riscv)
43+
/* Program counter. */
44+
long int __pc;
45+
/* Callee-saved registers. */
46+
long int __regs[12];
47+
/* Stack pointer. */
48+
long int __sp;
49+
/* Callee-saved floating point registers. */
50+
#if __riscv_float_abi_double
51+
double __fpregs[12];
52+
#elif defined(__riscv_float_abi_single)
53+
#error "__jmp_buf not available for your target architecture."
54+
#endif
55+
#elif defined(__arm__)
56+
// r4, r5, r6, r7, r8, r9, r10, r11, r12, lr
57+
long opaque[10];
58+
#elif defined(__aarch64__)
59+
long opaque[14]; // x19-x29, lr, sp, optional x18
60+
#if __ARM_FP
61+
long fopaque[8]; // d8-d15
62+
#endif
63+
#else
64+
#error "__jmp_buf not available for your target architecture."
65+
#endif
66+
#if defined(__LIBC_HAS_SIGJMP_BUF)
67+
// return address
68+
void *sig_retaddr;
69+
// extra register buffer to avoid indefinite stack growth in sigsetjmp
70+
void *sig_extra;
71+
// signal masks
72+
sigset_t sigmask;
73+
#endif
74+
} __jmp_buf;
75+
76+
#undef __LIBC_HAS_SIGJMP_BUF
77+
78+
#endif // LLVM_LIBC_TYPES___JMP_BUF_H

libc/include/llvm-libc-types/jmp_buf.h

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -9,76 +9,8 @@
99
#ifndef LLVM_LIBC_TYPES_JMP_BUF_H
1010
#define LLVM_LIBC_TYPES_JMP_BUF_H
1111

12-
// TODO: implement sigjmp_buf related functions for other architectures
13-
// Issue: https://github.com/llvm/llvm-project/issues/136358
14-
#if defined(__linux__)
15-
#if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__) || \
16-
defined(__arm__) || defined(__riscv)
17-
#define __LIBC_HAS_SIGJMP_BUF
18-
#endif
19-
#endif
20-
21-
#if defined(__LIBC_HAS_SIGJMP_BUF)
22-
#include "sigset_t.h"
23-
#endif
24-
25-
typedef struct {
26-
#ifdef __x86_64__
27-
__UINT64_TYPE__ rbx;
28-
__UINT64_TYPE__ rbp;
29-
__UINT64_TYPE__ r12;
30-
__UINT64_TYPE__ r13;
31-
__UINT64_TYPE__ r14;
32-
__UINT64_TYPE__ r15;
33-
__UINTPTR_TYPE__ rsp;
34-
__UINTPTR_TYPE__ rip;
35-
#elif defined(__i386__)
36-
long ebx;
37-
long esi;
38-
long edi;
39-
long ebp;
40-
long esp;
41-
long eip;
42-
#elif defined(__riscv)
43-
/* Program counter. */
44-
long int __pc;
45-
/* Callee-saved registers. */
46-
long int __regs[12];
47-
/* Stack pointer. */
48-
long int __sp;
49-
/* Callee-saved floating point registers. */
50-
#if __riscv_float_abi_double
51-
double __fpregs[12];
52-
#elif defined(__riscv_float_abi_single)
53-
#error "__jmp_buf not available for your target architecture."
54-
#endif
55-
#elif defined(__arm__)
56-
// r4, r5, r6, r7, r8, r9, r10, r11, r12, lr
57-
long opaque[10];
58-
#elif defined(__aarch64__)
59-
long opaque[14]; // x19-x29, lr, sp, optional x18
60-
#if __ARM_FP
61-
long fopaque[8]; // d8-d15
62-
#endif
63-
#else
64-
#error "__jmp_buf not available for your target architecture."
65-
#endif
66-
#if defined(__LIBC_HAS_SIGJMP_BUF)
67-
// return address
68-
void *sig_retaddr;
69-
// extra register buffer to avoid indefinite stack growth in sigsetjmp
70-
void *sig_extra;
71-
// signal masks
72-
sigset_t sigmask;
73-
#endif
74-
} __jmp_buf;
12+
#include "__jmp_buf.h"
7513

7614
typedef __jmp_buf jmp_buf[1];
7715

78-
#if defined(__LIBC_HAS_SIGJMP_BUF)
79-
typedef __jmp_buf sigjmp_buf[1];
80-
#endif
81-
82-
#undef __LIBC_HAS_SIGJMP_BUF
83-
8416
#endif // LLVM_LIBC_TYPES_JMP_BUF_H
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//===-- Definition of type sigjmp_buf -------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_TYPES_SIGJMP_BUF_H
10+
#define LLVM_LIBC_TYPES_SIGJMP_BUF_H
11+
12+
#include "__jmp_buf.h"
13+
14+
typedef __jmp_buf sigjmp_buf[1];
15+
16+
#endif // LLVM_LIBC_TYPES_SIGJMP_BUF_H

libc/src/setjmp/aarch64/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ add_entrypoint_object(
3434
HDRS
3535
../sigsetjmp.h
3636
DEPENDS
37-
libc.hdr.types.jmp_buf
37+
libc.hdr.types.sigjmp_buf
3838
libc.hdr.types.sigset_t
3939
libc.hdr.offsetof_macros
4040
libc.src.setjmp.sigsetjmp_epilogue

libc/src/setjmp/arm/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if (TARGET libc.src.setjmp.sigsetjmp_epilogue)
1616
HDRS
1717
../sigsetjmp.h
1818
DEPENDS
19-
libc.hdr.types.jmp_buf
19+
libc.hdr.types.sigjmp_buf
2020
libc.hdr.types.sigset_t
2121
libc.hdr.offsetof_macros
2222
libc.src.setjmp.sigsetjmp_epilogue

0 commit comments

Comments
 (0)