[libc-commits] [libc] [llvm] Get libc building on Mac OS. (PR #217677)
Niall Douglas via libc-commits
libc-commits at lists.llvm.org
Thu Aug 20 09:01:34 PDT 2026
https://github.com/ned14 created https://github.com/llvm/llvm-project/pull/217677
None
>From 78b9d2624c52522ca361a3efc86bee7459aa469c Mon Sep 17 00:00:00 2001
From: "Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com)"
<spamtrap at nedprod.com>
Date: Thu, 20 Aug 2026 15:10:38 +0100
Subject: [PATCH] Get libc building on Mac OS.
---
.gitmodules | 3 +++
libc/config/darwin/aarch64/entrypoints.txt | 2 --
libc/include/llvm-libc-types/fenv_t.h | 7 +++++++
.../FPUtil/aarch64/fenv_darwin_impl.h | 18 ++++++++++++++++++
libc/src/setjmp/CMakeLists.txt | 14 ++++++++------
libc/src/setjmp/darwin/CMakeLists.txt | 18 ++++++------------
libc/src/signal/wg14 | 1 +
7 files changed, 43 insertions(+), 20 deletions(-)
create mode 100644 .gitmodules
create mode 160000 libc/src/signal/wg14
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000000000..4a55f123fd2fb
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "libc/src/signal/wg14"]
+ path = libc/src/signal/wg14
+ url = https://github.com/ned14/wg14_signals.git
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index 3321475658754..2e81ee1b86458 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -123,8 +123,6 @@ if(LLVM_LIBC_FULL_BUILD)
# setjmp.h entrypoints
libc.src.setjmp.longjmp
libc.src.setjmp.setjmp
- libc.src.setjmp.siglongjmp
- libc.src.setjmp.sigsetjmp
libc.src.stdlib._Exit
)
endif()
diff --git a/libc/include/llvm-libc-types/fenv_t.h b/libc/include/llvm-libc-types/fenv_t.h
index 2cfeff7b8a9f8..0201e1bf26d96 100644
--- a/libc/include/llvm-libc-types/fenv_t.h
+++ b/libc/include/llvm-libc-types/fenv_t.h
@@ -10,10 +10,17 @@
#define LLVM_LIBC_TYPES_FENV_T_H
#ifdef __aarch64__
+#if defined(__APPLE__)
+typedef struct {
+ unsigned long long __fpsr;
+ unsigned long long __fpcr;
+} fenv_t;
+#else
typedef struct {
unsigned char __control_word[4];
unsigned char __status_word[4];
} fenv_t;
+#endif
#elif defined(__x86_64__)
typedef struct {
unsigned char __x86_status[28];
diff --git a/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h b/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h
index a2066d1025f63..c5de6e5911646 100644
--- a/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h
+++ b/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h
@@ -24,6 +24,24 @@
#include "hdr/types/fenv_t.h"
#include "src/__support/FPUtil/FPBits.h"
+// The full build compiles with -nostdinc against LLVM-libc's generated
+// <fenv.h>, which does not expose Apple's private __fpcr_* control-word bit
+// masks or the Apple-only FE_FLUSHTOZERO status bit. Provide the same values
+// as the macOS SDK's <fenv.h> so this file compiles in the full build.
+#ifndef __fpcr_trap_invalid
+#define __fpcr_trap_invalid 0x00000100u
+#define __fpcr_trap_divbyzero 0x00000200u
+#define __fpcr_trap_overflow 0x00000400u
+#define __fpcr_trap_underflow 0x00000800u
+#define __fpcr_trap_inexact 0x00001000u
+#define __fpcr_trap_denormal 0x00008000u
+#define __fpcr_flush_to_zero 0x01000000u
+#endif
+
+#ifndef FE_FLUSHTOZERO
+#define FE_FLUSHTOZERO 0x80u
+#endif
+
namespace LIBC_NAMESPACE_DECL {
namespace fputil {
diff --git a/libc/src/setjmp/CMakeLists.txt b/libc/src/setjmp/CMakeLists.txt
index f703c69293e5a..b949b9ddb9764 100644
--- a/libc/src/setjmp/CMakeLists.txt
+++ b/libc/src/setjmp/CMakeLists.txt
@@ -3,12 +3,14 @@
# Then process OS-specific subdirectory
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
- add_object_library(
- sigsetjmp_epilogue
- ALIAS
- DEPENDS
- .${LIBC_TARGET_OS}.sigsetjmp_epilogue
- )
+ if(TARGET libc.src.setjmp.${LIBC_TARGET_OS}.sigsetjmp_epilogue)
+ add_object_library(
+ sigsetjmp_epilogue
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}.sigsetjmp_epilogue
+ )
+ endif()
endif()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE})
diff --git a/libc/src/setjmp/darwin/CMakeLists.txt b/libc/src/setjmp/darwin/CMakeLists.txt
index 62acec0fa7fdb..807099fba8f01 100644
--- a/libc/src/setjmp/darwin/CMakeLists.txt
+++ b/libc/src/setjmp/darwin/CMakeLists.txt
@@ -1,12 +1,6 @@
-add_object_library(
- sigsetjmp_epilogue
- HDRS
- ../sigsetjmp_epilogue.h
- SRCS
- sigsetjmp_epilogue.cpp
- DEPENDS
- libc.src.__support.common
- libc.src.__support.OSUtil.osutil
- libc.hdr.types.sigjmp_buf
- libc.hdr.types.sigset_t
-)
+# The Darwin sigsetjmp epilogue is disabled: the upstream implementation
+# (sigsetjmp_epilogue.cpp) is incomplete on Darwin - it relies on a
+# "sigprocmask" syscall and on __jmp_buf.sigmask, neither of which exists on
+# Darwin (there is no libc/src/signal/darwin/ implementation either). Building
+# it fails, so sigsetjmp/siglongjmp are not provided on Darwin until upstream
+# implements the Darwin signal-mask machinery.
diff --git a/libc/src/signal/wg14 b/libc/src/signal/wg14
new file mode 160000
index 0000000000000..50042dad4eb37
--- /dev/null
+++ b/libc/src/signal/wg14
@@ -0,0 +1 @@
+Subproject commit 50042dad4eb376bc88f6d21568007e72c615f3a8
More information about the libc-commits
mailing list