[libc-commits] [libc] Implement `sigsetjmp` and `siglongjmp` for darwin/aarch64 (PR #139555)

Aly ElAshram via libc-commits libc-commits at lists.llvm.org
Mon May 26 16:51:33 PDT 2025


https://github.com/AlyElashram updated https://github.com/llvm/llvm-project/pull/139555

>From 9edb551fe776d5eee5be746636d06a5a0a87d8f5 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Mon, 26 May 2025 20:11:34 +0300
Subject: [PATCH 01/20] Update architecture matching for arm64 and remove todo

---
 libc/cmake/modules/LLVMLibCArchitectures.cmake | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/libc/cmake/modules/LLVMLibCArchitectures.cmake b/libc/cmake/modules/LLVMLibCArchitectures.cmake
index 62f3a2e3bdb59..c94a407d974df 100644
--- a/libc/cmake/modules/LLVMLibCArchitectures.cmake
+++ b/libc/cmake/modules/LLVMLibCArchitectures.cmake
@@ -33,12 +33,10 @@ function(get_arch_and_system_from_triple triple arch_var sys_var)
   # value.
   if(target_arch MATCHES "^mips")
     set(target_arch "mips")
+  elseif(target_arch MATCHES "^aarch64|^arm64")
+    set(target_arch "aarch64")
   elseif(target_arch MATCHES "^arm")
-    # TODO(lntue): Shall we separate `arm64`?  It is currently recognized as
-    # `arm` here.
     set(target_arch "arm")
-  elseif(target_arch MATCHES "^aarch64")
-    set(target_arch "aarch64")
   elseif(target_arch MATCHES "(x86_64)|(AMD64|amd64)")
     set(target_arch "x86_64")
   elseif(target_arch MATCHES "(^i.86$)")

>From b9841bf8c43f7935bbef2c458b4228f2c15bb186 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Mon, 26 May 2025 20:11:57 +0300
Subject: [PATCH 02/20] Update directory name from arm to aarch64 in darwin
 config

---
 libc/config/darwin/{arm => aarch64}/entrypoints.txt              | 0
 libc/config/darwin/{arm => aarch64}/headers.txt                  | 0
 libc/src/__support/OSUtil/darwin/{arm => aarch64}/CMakeLists.txt | 0
 3 files changed, 0 insertions(+), 0 deletions(-)
 rename libc/config/darwin/{arm => aarch64}/entrypoints.txt (100%)
 rename libc/config/darwin/{arm => aarch64}/headers.txt (100%)
 rename libc/src/__support/OSUtil/darwin/{arm => aarch64}/CMakeLists.txt (100%)

diff --git a/libc/config/darwin/arm/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
similarity index 100%
rename from libc/config/darwin/arm/entrypoints.txt
rename to libc/config/darwin/aarch64/entrypoints.txt
diff --git a/libc/config/darwin/arm/headers.txt b/libc/config/darwin/aarch64/headers.txt
similarity index 100%
rename from libc/config/darwin/arm/headers.txt
rename to libc/config/darwin/aarch64/headers.txt
diff --git a/libc/src/__support/OSUtil/darwin/arm/CMakeLists.txt b/libc/src/__support/OSUtil/darwin/aarch64/CMakeLists.txt
similarity index 100%
rename from libc/src/__support/OSUtil/darwin/arm/CMakeLists.txt
rename to libc/src/__support/OSUtil/darwin/aarch64/CMakeLists.txt

>From 83c16d4bbd385cdf61afc7f499c7fa7659590d67 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Mon, 26 May 2025 20:12:14 +0300
Subject: [PATCH 03/20] Update syscall util to use aarch64 instead of arm name

---
 libc/src/__support/OSUtil/darwin/{arm => aarch64}/syscall.h | 0
 libc/src/__support/OSUtil/darwin/syscall.h                  | 2 +-
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename libc/src/__support/OSUtil/darwin/{arm => aarch64}/syscall.h (100%)

diff --git a/libc/src/__support/OSUtil/darwin/arm/syscall.h b/libc/src/__support/OSUtil/darwin/aarch64/syscall.h
similarity index 100%
rename from libc/src/__support/OSUtil/darwin/arm/syscall.h
rename to libc/src/__support/OSUtil/darwin/aarch64/syscall.h
diff --git a/libc/src/__support/OSUtil/darwin/syscall.h b/libc/src/__support/OSUtil/darwin/syscall.h
index eab96366a21a3..463407dbe19ef 100644
--- a/libc/src/__support/OSUtil/darwin/syscall.h
+++ b/libc/src/__support/OSUtil/darwin/syscall.h
@@ -15,7 +15,7 @@
 #include "src/__support/macros/properties/architectures.h"
 
 #ifdef LIBC_TARGET_ARCH_IS_ANY_ARM
-#include "arm/syscall.h"
+#include "aarch64/syscall.h"
 #else
 #error "Unsupported architecture"
 #endif

>From 72af87403209f0f66d150d7375ac76fdbc3fc073 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Mon, 12 May 2025 16:52:21 +0300
Subject: [PATCH 04/20] Add setjmp longjmp and sigsetjmp.cpp

---
 libc/src/setjmp/darwin/aarch64/longjmp.cpp   | 87 +++++++++++++++++++
 libc/src/setjmp/darwin/aarch64/setjmp.cpp    | 89 ++++++++++++++++++++
 libc/src/setjmp/darwin/aarch64/sigsetjmp.cpp | 40 +++++++++
 3 files changed, 216 insertions(+)
 create mode 100644 libc/src/setjmp/darwin/aarch64/longjmp.cpp
 create mode 100644 libc/src/setjmp/darwin/aarch64/setjmp.cpp
 create mode 100644 libc/src/setjmp/darwin/aarch64/sigsetjmp.cpp

diff --git a/libc/src/setjmp/darwin/aarch64/longjmp.cpp b/libc/src/setjmp/darwin/aarch64/longjmp.cpp
new file mode 100644
index 0000000000000..eca4303f58034
--- /dev/null
+++ b/libc/src/setjmp/darwin/aarch64/longjmp.cpp
@@ -0,0 +1,87 @@
+//===-- Implementation of longjmp for AArch64 -----------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/setjmp/longjmp.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+// TODO: if MTE stack tagging is in use (-fsanitize=memtag-stack), we need to
+// iterate over the region between the old and new values of sp, using STG or
+// ST2G instructions to clear the memory tags on the invalidated region of the
+// stack. But this requires a means of finding out that we're in that mode, and
+// as far as I can see there isn't currently a predefined macro for that.
+//
+// (__ARM_FEATURE_MEMORY_TAGGING only indicates whether the target architecture
+// supports the MTE instructions, not whether the compiler is configured to use
+// them.)
+
+[[gnu::naked]] LLVM_LIBC_FUNCTION(void, longjmp,
+                                  ([[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.
+
+  // If PAC branch protection is in use, there's no need to sign the return
+  // address at the start of longjmp, because we're not going to use it anyway!
+
+  asm(
+      // Reload the callee-saved GPRs, including fp and lr.
+      R"(
+        ldp x19, x20, [x0,  #0*16]
+        ldp x21, x22, [x0,  #1*16]
+        ldp x23, x24, [x0,  #2*16]
+        ldp x25, x26, [x0,  #3*16]
+        ldp x27, x28, [x0,  #4*16]
+        ldp x29, x30, [x0,  #5*16]
+      )"
+      // We would usually reload the platform register x18 here
+      // but due to the apple ABI we are not allowed to use the x18 register
+      // so we reload the stack pointer only.
+      // https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms#Respect-the-purpose-of-specific-CPU-registers
+      R"(
+        ldr x2,       [x0,  #6*16]
+        mov sp, x2
+      )"
+
+#if __ARM_FP
+      // Reload the callee-saved FP registers.
+      R"(
+        ldp d8,  d9,  [x0,  #7*16]
+        ldp d10, d11, [x0,  #8*16]
+        ldp d12, d13, [x0,  #9*16]
+        ldp d14, d15, [x0, #10*16]
+      )"
+#endif
+
+      // Calculate the return value.
+      R"(
+        cmp w1, #0
+        cinc w0, w1, eq
+      )"
+
+#if (__ARM_FEATURE_PAC_DEFAULT & 7) == 5
+      // Authenticate the return address using the PAC A key, since the
+      // compilation options ask for PAC protection even on leaf functions.
+      R"(
+        autiasp
+      )"
+#elif (__ARM_FEATURE_PAC_DEFAULT & 7) == 6
+      // Same, but using the PAC B key.
+      R"(
+        autibsp
+      )"
+#endif
+
+      R"(
+        ret
+      )");
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/setjmp/darwin/aarch64/setjmp.cpp b/libc/src/setjmp/darwin/aarch64/setjmp.cpp
new file mode 100644
index 0000000000000..678203996b6d8
--- /dev/null
+++ b/libc/src/setjmp/darwin/aarch64/setjmp.cpp
@@ -0,0 +1,89 @@
+//===-- Implementation of setjmp for darwin AArch64 -----------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/setjmp/setjmp_impl.h"
+
+
+
+namespace LIBC_NAMESPACE_DECL {
+
+[[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.
+
+  asm(
+#if __ARM_FEATURE_PAC_DEFAULT & 1
+      // Sign the return address using the PAC A key.
+      R"(
+        paciasp
+      )"
+#elif __ARM_FEATURE_PAC_DEFAULT & 2
+      // Sign the return address using the PAC B key.
+      R"(
+        pacibsp
+      )"
+#endif
+
+      // Store all the callee-saved GPRs, including fp (x29) and also lr (x30).
+      // Of course lr isn't normally callee-saved (the call instruction itself
+      // can't help clobbering it), but we certainly need to save it for this
+      // purpose.
+      R"(
+        stp x19, x20, [x0,  #0*16]
+        stp x21, x22, [x0,  #1*16]
+        stp x23, x24, [x0,  #2*16]
+        stp x25, x26, [x0,  #3*16]
+        stp x27, x28, [x0,  #4*16]
+        stp x29, x30, [x0,  #5*16]
+      )"
+
+      // While we usually store the platform register x18
+      // the darwin ABI inhibts usage of it
+      // Store just the stack pointer.
+      R"(
+        add x1, sp, #0
+        str x1,       [x0,  #6*16]
+      )"
+
+#if __ARM_FP
+      // Store the callee-saved FP registers. AAPCS64 only requires the low 64
+      // bits of v8-v15 to be preserved, i.e. each of d8,...,d15.
+      R"(
+        stp d8,  d9,  [x0,  #7*16]
+        stp d10, d11, [x0,  #8*16]
+        stp d12, d13, [x0,  #9*16]
+        stp d14, d15, [x0, #10*16]
+      )"
+#endif
+
+      // Set up return value of zero.
+      R"(
+        mov x0, #0
+      )"
+
+#if (__ARM_FEATURE_PAC_DEFAULT & 7) == 5
+      // Authenticate the return address using the PAC A key, since the
+      // compilation options ask for PAC protection even on leaf functions.
+      R"(
+        autiasp
+      )"
+#elif (__ARM_FEATURE_PAC_DEFAULT & 7) == 6
+      // Same, but using the PAC B key.
+      R"(
+        autibsp
+      )"
+#endif
+
+      R"(
+        ret
+      )");
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/setjmp/darwin/aarch64/sigsetjmp.cpp b/libc/src/setjmp/darwin/aarch64/sigsetjmp.cpp
new file mode 100644
index 0000000000000..88b5a28e1105d
--- /dev/null
+++ b/libc/src/setjmp/darwin/aarch64/sigsetjmp.cpp
@@ -0,0 +1,40 @@
+//===-- Implementation of darwin/aarch64 sigsetjmp ------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/setjmp/sigsetjmp.h"
+#include "hdr/offsetof_macros.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/setjmp/setjmp_impl.h"
+#include "src/setjmp/sigsetjmp_epilogue.h"
+
+namespace LIBC_NAMESPACE_DECL {
+[[gnu::naked]]
+LLVM_LIBC_FUNCTION(int, sigsetjmp, (sigjmp_buf, int)) {
+
+  // The difference between sigsetjmp and setjmp is storing the signal mask of
+  // the calling thread
+
+  asm(R"(
+      cbz w1, %c[setjmp]
+
+      str x30, [x0, %c[retaddr]]
+      str x19, [x0, %c[extra]]
+      mov x19, x0
+      bl %c[setjmp]
+
+      mov w1, w0
+      mov x0, x19
+      ldr x30, [x0, %c[retaddr]]
+      ldr x19, [x0, %c[extra]]
+      b %c[epilogue])" ::[retaddr] "i"(offsetof(__jmp_buf, sig_retaddr)),
+      [extra] "i"(offsetof(__jmp_buf, sig_extra)), [setjmp] "i"(setjmp),
+      [epilogue] "i"(sigsetjmp_epilogue)
+      : "x0", "x1", "x19", "x30");
+}
+} // namespace LIBC_NAMESPACE_DECL

>From aa04110026cddf2573c9af66dcc2f8a4d224ff41 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Mon, 12 May 2025 16:52:46 +0300
Subject: [PATCH 05/20] Add setjmp to entrypoints and headers in darwin

---
 libc/config/darwin/aarch64/entrypoints.txt | 4 ++++
 libc/config/darwin/aarch64/headers.txt     | 1 +
 2 files changed, 5 insertions(+)

diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index 308fc49d681d7..07199db6d1ae6 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -20,6 +20,10 @@ set(TARGET_LIBC_ENTRYPOINTS
     # errno.h entrypoints
     libc.src.errno.errno
 
+    # setjmp.h entrypoints
+    libc.src.setjmp
+
+
     # string.h entrypoints
     libc.src.string.memccpy
     libc.src.string.memchr
diff --git a/libc/config/darwin/aarch64/headers.txt b/libc/config/darwin/aarch64/headers.txt
index 86e7145972324..8f3d6029c9b6a 100644
--- a/libc/config/darwin/aarch64/headers.txt
+++ b/libc/config/darwin/aarch64/headers.txt
@@ -7,6 +7,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.inttypes
     libc.include.limits
     libc.include.math
+    libc.include.setjmp
     libc.include.stdlib
     libc.include.string
     libc.include.strings

>From 018e3be33b895e1cdda1493196d26d5349128952 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Mon, 12 May 2025 17:25:04 +0300
Subject: [PATCH 06/20] Add the sigsetjmp epilogue for darwin aarch64

---
 .../darwin/aarch64/sigsetjmp_epilogue.cpp     | 21 +++++++++++++++++++
 1 file changed, 21 insertions(+)
 create mode 100644 libc/src/setjmp/darwin/aarch64/sigsetjmp_epilogue.cpp

diff --git a/libc/src/setjmp/darwin/aarch64/sigsetjmp_epilogue.cpp b/libc/src/setjmp/darwin/aarch64/sigsetjmp_epilogue.cpp
new file mode 100644
index 0000000000000..b2ca4d99ed82b
--- /dev/null
+++ b/libc/src/setjmp/darwin/aarch64/sigsetjmp_epilogue.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of sigsetjmp_epilogue ------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/setjmp/sigsetjmp_epilogue.h"
+#include "src/__support/OSUtil/syscall.h"
+#include "src/__support/common.h"
+#include "src/signal/sigprocmask.h"
+
+namespace LIBC_NAMESPACE_DECL {
+[[gnu::returns_twice]] int sigsetjmp_epilogue(jmp_buf buffer, int retval) {
+  syscall_impl<long>(sigprocmask, SIG_SETMASK,
+                     /* set= */ retval ? &buffer->sigmask : nullptr,
+                     /* old_set= */ retval ? nullptr : &buffer->sigmask);
+  return retval;
+}
+} // namespace LIBC_NAMESPACE_DECL

>From fed8f55b867661f75b6795cb8577e13864ff60be Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Mon, 12 May 2025 17:31:47 +0300
Subject: [PATCH 07/20] Formatting

---
 libc/src/setjmp/darwin/aarch64/setjmp.cpp | 2 --
 1 file changed, 2 deletions(-)

diff --git a/libc/src/setjmp/darwin/aarch64/setjmp.cpp b/libc/src/setjmp/darwin/aarch64/setjmp.cpp
index 678203996b6d8..2842590850217 100644
--- a/libc/src/setjmp/darwin/aarch64/setjmp.cpp
+++ b/libc/src/setjmp/darwin/aarch64/setjmp.cpp
@@ -10,8 +10,6 @@
 #include "src/__support/macros/config.h"
 #include "src/setjmp/setjmp_impl.h"
 
-
-
 namespace LIBC_NAMESPACE_DECL {
 
 [[gnu::naked]] LLVM_LIBC_FUNCTION(int, setjmp, ([[maybe_unused]] jmp_buf buf)) {

>From 1a36c455f0f3a39421ce62f98abb2c8af476067f Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Mon, 12 May 2025 17:32:56 +0300
Subject: [PATCH 08/20] cmake file for darwin aarch64

---
 libc/src/setjmp/darwin/aarch64/CMakeLists.txt | 51 +++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 libc/src/setjmp/darwin/aarch64/CMakeLists.txt

diff --git a/libc/src/setjmp/darwin/aarch64/CMakeLists.txt b/libc/src/setjmp/darwin/aarch64/CMakeLists.txt
new file mode 100644
index 0000000000000..6f9d865ede7cc
--- /dev/null
+++ b/libc/src/setjmp/darwin/aarch64/CMakeLists.txt
@@ -0,0 +1,51 @@
+if(setjmp_config_options)
+    list(PREPEND setjmp_config_options "COMPILE_OPTIONS")
+endif()
+
+add_entrypoint_object(
+  setjmp
+  SRCS
+    setjmp.cpp
+  HDRS
+    ../../setjmp_impl.h
+  DEPENDS
+    libc.hdr.types.jmp_buf
+  ${setjmp_config_options}
+)
+
+add_entrypoint_object(
+        longjmp
+        SRCS
+        longjmp.cpp
+        HDRS
+        ../../longjmp.h
+        DEPENDS
+        libc.hdr.types.jmp_buf
+        ${setjmp_config_options}
+)
+
+add_entrypoint_object(
+        sigsetjmp
+        SRCS
+        sigsetjmp.cpp
+        HDRS
+        ../../sigsetjmp.h
+        DEPENDS
+        libc.hdr.types.jmp_buf
+        libc.hdr.types.sigset_t
+        libc.hdr.offsetof_macros
+        libc.src.setjmp.sigsetjmp_epilogue
+        libc.src.setjmp.setjmp
+)
+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.jmp_buf
+        libc.hdr.types.sigset_t
+)
\ No newline at end of file

>From 734602beb4c6d2d0502f443b28184de19b31c77e Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Mon, 12 May 2025 17:36:58 +0300
Subject: [PATCH 09/20] cmake file formatting

---
 libc/src/setjmp/darwin/aarch64/CMakeLists.txt | 58 +++++++++----------
 1 file changed, 29 insertions(+), 29 deletions(-)

diff --git a/libc/src/setjmp/darwin/aarch64/CMakeLists.txt b/libc/src/setjmp/darwin/aarch64/CMakeLists.txt
index 6f9d865ede7cc..37058e9fb905e 100644
--- a/libc/src/setjmp/darwin/aarch64/CMakeLists.txt
+++ b/libc/src/setjmp/darwin/aarch64/CMakeLists.txt
@@ -14,38 +14,38 @@ add_entrypoint_object(
 )
 
 add_entrypoint_object(
-        longjmp
-        SRCS
-        longjmp.cpp
-        HDRS
-        ../../longjmp.h
-        DEPENDS
-        libc.hdr.types.jmp_buf
-        ${setjmp_config_options}
+  longjmp
+  SRCS
+    longjmp.cpp
+  HDRS
+    ../../longjmp.h
+  DEPENDS
+    libc.hdr.types.jmp_buf
+  ${setjmp_config_options}
 )
 
 add_entrypoint_object(
-        sigsetjmp
-        SRCS
-        sigsetjmp.cpp
-        HDRS
-        ../../sigsetjmp.h
-        DEPENDS
-        libc.hdr.types.jmp_buf
-        libc.hdr.types.sigset_t
-        libc.hdr.offsetof_macros
-        libc.src.setjmp.sigsetjmp_epilogue
-        libc.src.setjmp.setjmp
+  sigsetjmp
+  SRCS
+    sigsetjmp.cpp
+  HDRS
+    ../../sigsetjmp.h
+  DEPENDS
+    libc.hdr.types.jmp_buf
+    libc.hdr.types.sigset_t
+    libc.hdr.offsetof_macros
+    libc.src.setjmp.sigsetjmp_epilogue
+    libc.src.setjmp.setjmp
 )
 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.jmp_buf
-        libc.hdr.types.sigset_t
+  sigsetjmp_epilogue
+  HDRS
+  ../../sigsetjmp_epilogue.h
+  SRCS
+    sigsetjmp_epilogue.cpp
+  DEPENDS
+    libc.src.__support.common
+    libc.src.__support.OSUtil.osutil
+    libc.hdr.types.jmp_buf
+    libc.hdr.types.sigset_t
 )
\ No newline at end of file

>From 49fc4c03a6be932e0ff4e4f72fa262fea1077d09 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 16 May 2025 17:37:55 +0300
Subject: [PATCH 10/20] Remove setjmp and longjmp ,and reuse the aarch64
 implementation with a new config.json

---
 libc/config/darwin/aarch64/config.json     |  8 ++
 libc/src/setjmp/darwin/aarch64/longjmp.cpp | 87 ----------------------
 libc/src/setjmp/darwin/aarch64/setjmp.cpp  | 87 ----------------------
 3 files changed, 8 insertions(+), 174 deletions(-)
 create mode 100644 libc/config/darwin/aarch64/config.json
 delete mode 100644 libc/src/setjmp/darwin/aarch64/longjmp.cpp
 delete mode 100644 libc/src/setjmp/darwin/aarch64/setjmp.cpp

diff --git a/libc/config/darwin/aarch64/config.json b/libc/config/darwin/aarch64/config.json
new file mode 100644
index 0000000000000..e7d186e8ba64a
--- /dev/null
+++ b/libc/config/darwin/aarch64/config.json
@@ -0,0 +1,8 @@
+{
+  "setjmp": {
+    "LIBC_CONF_SETJMP_AARCH64_RESTORE_PLATFORM_REGISTER": {
+      "value": false,
+      "doc": "Avoid setjmp saving the value of x18, and longjmp restoring it. The Apple AArch64 ABI specifies that this register is reserved and should not be used"
+    }
+  }
+}
\ No newline at end of file
diff --git a/libc/src/setjmp/darwin/aarch64/longjmp.cpp b/libc/src/setjmp/darwin/aarch64/longjmp.cpp
deleted file mode 100644
index eca4303f58034..0000000000000
--- a/libc/src/setjmp/darwin/aarch64/longjmp.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-//===-- Implementation of longjmp for AArch64 -----------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "src/setjmp/longjmp.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-// TODO: if MTE stack tagging is in use (-fsanitize=memtag-stack), we need to
-// iterate over the region between the old and new values of sp, using STG or
-// ST2G instructions to clear the memory tags on the invalidated region of the
-// stack. But this requires a means of finding out that we're in that mode, and
-// as far as I can see there isn't currently a predefined macro for that.
-//
-// (__ARM_FEATURE_MEMORY_TAGGING only indicates whether the target architecture
-// supports the MTE instructions, not whether the compiler is configured to use
-// them.)
-
-[[gnu::naked]] LLVM_LIBC_FUNCTION(void, longjmp,
-                                  ([[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.
-
-  // If PAC branch protection is in use, there's no need to sign the return
-  // address at the start of longjmp, because we're not going to use it anyway!
-
-  asm(
-      // Reload the callee-saved GPRs, including fp and lr.
-      R"(
-        ldp x19, x20, [x0,  #0*16]
-        ldp x21, x22, [x0,  #1*16]
-        ldp x23, x24, [x0,  #2*16]
-        ldp x25, x26, [x0,  #3*16]
-        ldp x27, x28, [x0,  #4*16]
-        ldp x29, x30, [x0,  #5*16]
-      )"
-      // We would usually reload the platform register x18 here
-      // but due to the apple ABI we are not allowed to use the x18 register
-      // so we reload the stack pointer only.
-      // https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms#Respect-the-purpose-of-specific-CPU-registers
-      R"(
-        ldr x2,       [x0,  #6*16]
-        mov sp, x2
-      )"
-
-#if __ARM_FP
-      // Reload the callee-saved FP registers.
-      R"(
-        ldp d8,  d9,  [x0,  #7*16]
-        ldp d10, d11, [x0,  #8*16]
-        ldp d12, d13, [x0,  #9*16]
-        ldp d14, d15, [x0, #10*16]
-      )"
-#endif
-
-      // Calculate the return value.
-      R"(
-        cmp w1, #0
-        cinc w0, w1, eq
-      )"
-
-#if (__ARM_FEATURE_PAC_DEFAULT & 7) == 5
-      // Authenticate the return address using the PAC A key, since the
-      // compilation options ask for PAC protection even on leaf functions.
-      R"(
-        autiasp
-      )"
-#elif (__ARM_FEATURE_PAC_DEFAULT & 7) == 6
-      // Same, but using the PAC B key.
-      R"(
-        autibsp
-      )"
-#endif
-
-      R"(
-        ret
-      )");
-}
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/setjmp/darwin/aarch64/setjmp.cpp b/libc/src/setjmp/darwin/aarch64/setjmp.cpp
deleted file mode 100644
index 2842590850217..0000000000000
--- a/libc/src/setjmp/darwin/aarch64/setjmp.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-//===-- Implementation of setjmp for darwin AArch64 -----------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-#include "src/setjmp/setjmp_impl.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-[[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.
-
-  asm(
-#if __ARM_FEATURE_PAC_DEFAULT & 1
-      // Sign the return address using the PAC A key.
-      R"(
-        paciasp
-      )"
-#elif __ARM_FEATURE_PAC_DEFAULT & 2
-      // Sign the return address using the PAC B key.
-      R"(
-        pacibsp
-      )"
-#endif
-
-      // Store all the callee-saved GPRs, including fp (x29) and also lr (x30).
-      // Of course lr isn't normally callee-saved (the call instruction itself
-      // can't help clobbering it), but we certainly need to save it for this
-      // purpose.
-      R"(
-        stp x19, x20, [x0,  #0*16]
-        stp x21, x22, [x0,  #1*16]
-        stp x23, x24, [x0,  #2*16]
-        stp x25, x26, [x0,  #3*16]
-        stp x27, x28, [x0,  #4*16]
-        stp x29, x30, [x0,  #5*16]
-      )"
-
-      // While we usually store the platform register x18
-      // the darwin ABI inhibts usage of it
-      // Store just the stack pointer.
-      R"(
-        add x1, sp, #0
-        str x1,       [x0,  #6*16]
-      )"
-
-#if __ARM_FP
-      // Store the callee-saved FP registers. AAPCS64 only requires the low 64
-      // bits of v8-v15 to be preserved, i.e. each of d8,...,d15.
-      R"(
-        stp d8,  d9,  [x0,  #7*16]
-        stp d10, d11, [x0,  #8*16]
-        stp d12, d13, [x0,  #9*16]
-        stp d14, d15, [x0, #10*16]
-      )"
-#endif
-
-      // Set up return value of zero.
-      R"(
-        mov x0, #0
-      )"
-
-#if (__ARM_FEATURE_PAC_DEFAULT & 7) == 5
-      // Authenticate the return address using the PAC A key, since the
-      // compilation options ask for PAC protection even on leaf functions.
-      R"(
-        autiasp
-      )"
-#elif (__ARM_FEATURE_PAC_DEFAULT & 7) == 6
-      // Same, but using the PAC B key.
-      R"(
-        autibsp
-      )"
-#endif
-
-      R"(
-        ret
-      )");
-}
-
-} // namespace LIBC_NAMESPACE_DECL

>From 6e9ef06884506ced7b2c37a5201ce3b97bca63b3 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 16 May 2025 17:38:21 +0300
Subject: [PATCH 11/20] Update CMakeLists.txt to include the darwin/aarch64
 directory.

---
 libc/src/setjmp/CMakeLists.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libc/src/setjmp/CMakeLists.txt b/libc/src/setjmp/CMakeLists.txt
index 239254fa57dc6..958960796940d 100644
--- a/libc/src/setjmp/CMakeLists.txt
+++ b/libc/src/setjmp/CMakeLists.txt
@@ -1,3 +1,4 @@
+add_subdirectory(darwin/aarch64)
 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
   add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
   add_object_library(

>From e36fd7e4b40f4f2ad22096eae42e447a6a924c1f Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 16 May 2025 17:38:50 +0300
Subject: [PATCH 12/20] Reuse the aarch64 implementation when building setjmp
 for darwin aarch64

---
 libc/src/setjmp/darwin/aarch64/CMakeLists.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libc/src/setjmp/darwin/aarch64/CMakeLists.txt b/libc/src/setjmp/darwin/aarch64/CMakeLists.txt
index 37058e9fb905e..7a15922124413 100644
--- a/libc/src/setjmp/darwin/aarch64/CMakeLists.txt
+++ b/libc/src/setjmp/darwin/aarch64/CMakeLists.txt
@@ -5,7 +5,7 @@ endif()
 add_entrypoint_object(
   setjmp
   SRCS
-    setjmp.cpp
+    ../../aarch64/setjmp.cpp
   HDRS
     ../../setjmp_impl.h
   DEPENDS
@@ -16,7 +16,7 @@ add_entrypoint_object(
 add_entrypoint_object(
   longjmp
   SRCS
-    longjmp.cpp
+    ../../aarch64/longjmp.cpp
   HDRS
     ../../longjmp.h
   DEPENDS

>From 4e06421f5ce9b8ba7b0dae714050bc213a9ff4a5 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 16 May 2025 17:47:16 +0300
Subject: [PATCH 13/20] Update adding the subdirectory for darwin/aarch64

---
 libc/src/setjmp/CMakeLists.txt | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libc/src/setjmp/CMakeLists.txt b/libc/src/setjmp/CMakeLists.txt
index 958960796940d..21f1be967234f 100644
--- a/libc/src/setjmp/CMakeLists.txt
+++ b/libc/src/setjmp/CMakeLists.txt
@@ -1,4 +1,3 @@
-add_subdirectory(darwin/aarch64)
 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
   add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
   add_object_library(
@@ -13,6 +12,10 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE})
   add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE})
 endif()
 
+if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE})
+  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE})
+endif()
+
 add_entrypoint_object(
   setjmp
   ALIAS

>From 3b6ce01c5110d9621b526c55f335ee2f406584df Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Sun, 18 May 2025 16:32:45 +0300
Subject: [PATCH 14/20] Update Cmake Lists

---
 libc/src/setjmp/darwin/CMakeLists.txt         | 12 ++++++++++++
 libc/src/setjmp/darwin/aarch64/CMakeLists.txt | 12 ------------
 2 files changed, 12 insertions(+), 12 deletions(-)
 create mode 100644 libc/src/setjmp/darwin/CMakeLists.txt

diff --git a/libc/src/setjmp/darwin/CMakeLists.txt b/libc/src/setjmp/darwin/CMakeLists.txt
new file mode 100644
index 0000000000000..63cfc11115488
--- /dev/null
+++ b/libc/src/setjmp/darwin/CMakeLists.txt
@@ -0,0 +1,12 @@
+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.jmp_buf
+    libc.hdr.types.sigset_t
+)
\ No newline at end of file
diff --git a/libc/src/setjmp/darwin/aarch64/CMakeLists.txt b/libc/src/setjmp/darwin/aarch64/CMakeLists.txt
index 7a15922124413..fee6196c1f302 100644
--- a/libc/src/setjmp/darwin/aarch64/CMakeLists.txt
+++ b/libc/src/setjmp/darwin/aarch64/CMakeLists.txt
@@ -36,16 +36,4 @@ add_entrypoint_object(
     libc.hdr.offsetof_macros
     libc.src.setjmp.sigsetjmp_epilogue
     libc.src.setjmp.setjmp
-)
-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.jmp_buf
-    libc.hdr.types.sigset_t
 )
\ No newline at end of file

>From 6b50b31db6fad1e4b08a83ac860761b91a3cd50b Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 23 May 2025 01:34:31 +0300
Subject: [PATCH 15/20] Update Cmake and remove sigsetjmp as it's not needed

---
 libc/config/darwin/aarch64/entrypoints.txt    |  5 ++-
 libc/src/setjmp/darwin/CMakeLists.txt         | 12 ------
 libc/src/setjmp/darwin/aarch64/CMakeLists.txt | 41 ++++---------------
 libc/src/setjmp/darwin/aarch64/sigsetjmp.cpp  | 40 ------------------
 4 files changed, 11 insertions(+), 87 deletions(-)
 delete mode 100644 libc/src/setjmp/darwin/CMakeLists.txt
 delete mode 100644 libc/src/setjmp/darwin/aarch64/sigsetjmp.cpp

diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index 07199db6d1ae6..65ad0d933e032 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -21,7 +21,10 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.errno.errno
 
     # setjmp.h entrypoints
-    libc.src.setjmp
+    libc.src.setjmp.longjmp
+    libc.src.setjmp.setjmp
+    libc.src.setjmp.siglongjmp
+    libc.src.setjmp.sigsetjmp
 
 
     # string.h entrypoints
diff --git a/libc/src/setjmp/darwin/CMakeLists.txt b/libc/src/setjmp/darwin/CMakeLists.txt
deleted file mode 100644
index 63cfc11115488..0000000000000
--- a/libc/src/setjmp/darwin/CMakeLists.txt
+++ /dev/null
@@ -1,12 +0,0 @@
-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.jmp_buf
-    libc.hdr.types.sigset_t
-)
\ No newline at end of file
diff --git a/libc/src/setjmp/darwin/aarch64/CMakeLists.txt b/libc/src/setjmp/darwin/aarch64/CMakeLists.txt
index fee6196c1f302..e088223a0139b 100644
--- a/libc/src/setjmp/darwin/aarch64/CMakeLists.txt
+++ b/libc/src/setjmp/darwin/aarch64/CMakeLists.txt
@@ -1,39 +1,12 @@
-if(setjmp_config_options)
-    list(PREPEND setjmp_config_options "COMPILE_OPTIONS")
-endif()
-
-add_entrypoint_object(
-  setjmp
-  SRCS
-    ../../aarch64/setjmp.cpp
+add_object_library(
+    sigsetjmp_epilogue
   HDRS
-    ../../setjmp_impl.h
-  DEPENDS
-    libc.hdr.types.jmp_buf
-  ${setjmp_config_options}
-)
-
-add_entrypoint_object(
-  longjmp
+    ../../sigsetjmp_epilogue.h
   SRCS
-    ../../aarch64/longjmp.cpp
-  HDRS
-    ../../longjmp.h
-  DEPENDS
-    libc.hdr.types.jmp_buf
-  ${setjmp_config_options}
-)
-
-add_entrypoint_object(
-  sigsetjmp
-  SRCS
-    sigsetjmp.cpp
-  HDRS
-    ../../sigsetjmp.h
+    sigsetjmp_epilogue.cpp
   DEPENDS
+    libc.src.__support.common
+    libc.src.__support.OSUtil.osutil
     libc.hdr.types.jmp_buf
     libc.hdr.types.sigset_t
-    libc.hdr.offsetof_macros
-    libc.src.setjmp.sigsetjmp_epilogue
-    libc.src.setjmp.setjmp
-)
\ No newline at end of file
+)
diff --git a/libc/src/setjmp/darwin/aarch64/sigsetjmp.cpp b/libc/src/setjmp/darwin/aarch64/sigsetjmp.cpp
deleted file mode 100644
index 88b5a28e1105d..0000000000000
--- a/libc/src/setjmp/darwin/aarch64/sigsetjmp.cpp
+++ /dev/null
@@ -1,40 +0,0 @@
-//===-- Implementation of darwin/aarch64 sigsetjmp ------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "src/setjmp/sigsetjmp.h"
-#include "hdr/offsetof_macros.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-#include "src/setjmp/setjmp_impl.h"
-#include "src/setjmp/sigsetjmp_epilogue.h"
-
-namespace LIBC_NAMESPACE_DECL {
-[[gnu::naked]]
-LLVM_LIBC_FUNCTION(int, sigsetjmp, (sigjmp_buf, int)) {
-
-  // The difference between sigsetjmp and setjmp is storing the signal mask of
-  // the calling thread
-
-  asm(R"(
-      cbz w1, %c[setjmp]
-
-      str x30, [x0, %c[retaddr]]
-      str x19, [x0, %c[extra]]
-      mov x19, x0
-      bl %c[setjmp]
-
-      mov w1, w0
-      mov x0, x19
-      ldr x30, [x0, %c[retaddr]]
-      ldr x19, [x0, %c[extra]]
-      b %c[epilogue])" ::[retaddr] "i"(offsetof(__jmp_buf, sig_retaddr)),
-      [extra] "i"(offsetof(__jmp_buf, sig_extra)), [setjmp] "i"(setjmp),
-      [epilogue] "i"(sigsetjmp_epilogue)
-      : "x0", "x1", "x19", "x30");
-}
-} // namespace LIBC_NAMESPACE_DECL

>From 38e256097ca4700a3ab7b1b50f0bb730b5b8863a Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 23 May 2025 01:39:59 +0300
Subject: [PATCH 16/20] Update CMake and remove the aarch64 directory

---
 libc/src/setjmp/CMakeLists.txt                              | 3 ---
 libc/src/setjmp/darwin/{aarch64 => }/CMakeLists.txt         | 0
 libc/src/setjmp/darwin/{aarch64 => }/sigsetjmp_epilogue.cpp | 0
 3 files changed, 3 deletions(-)
 rename libc/src/setjmp/darwin/{aarch64 => }/CMakeLists.txt (100%)
 rename libc/src/setjmp/darwin/{aarch64 => }/sigsetjmp_epilogue.cpp (100%)

diff --git a/libc/src/setjmp/CMakeLists.txt b/libc/src/setjmp/CMakeLists.txt
index 21f1be967234f..9fabe162dffe9 100644
--- a/libc/src/setjmp/CMakeLists.txt
+++ b/libc/src/setjmp/CMakeLists.txt
@@ -12,9 +12,6 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE})
   add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE})
 endif()
 
-if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE})
-  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE})
-endif()
 
 add_entrypoint_object(
   setjmp
diff --git a/libc/src/setjmp/darwin/aarch64/CMakeLists.txt b/libc/src/setjmp/darwin/CMakeLists.txt
similarity index 100%
rename from libc/src/setjmp/darwin/aarch64/CMakeLists.txt
rename to libc/src/setjmp/darwin/CMakeLists.txt
diff --git a/libc/src/setjmp/darwin/aarch64/sigsetjmp_epilogue.cpp b/libc/src/setjmp/darwin/sigsetjmp_epilogue.cpp
similarity index 100%
rename from libc/src/setjmp/darwin/aarch64/sigsetjmp_epilogue.cpp
rename to libc/src/setjmp/darwin/sigsetjmp_epilogue.cpp

>From 9587e21d79dd3bdc24eeb5dc3b9eba4ff7832811 Mon Sep 17 00:00:00 2001
From: AlyElashram <alyahelashram at gmail.com>
Date: Fri, 23 May 2025 02:12:06 +0300
Subject: [PATCH 17/20] Update CMake formatting and hdr path

---
 libc/src/setjmp/darwin/CMakeLists.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libc/src/setjmp/darwin/CMakeLists.txt b/libc/src/setjmp/darwin/CMakeLists.txt
index e088223a0139b..b844c8c5ee55a 100644
--- a/libc/src/setjmp/darwin/CMakeLists.txt
+++ b/libc/src/setjmp/darwin/CMakeLists.txt
@@ -1,7 +1,7 @@
 add_object_library(
-    sigsetjmp_epilogue
+  sigsetjmp_epilogue
   HDRS
-    ../../sigsetjmp_epilogue.h
+    ../sigsetjmp_epilogue.h
   SRCS
     sigsetjmp_epilogue.cpp
   DEPENDS

>From 12ec4ca13e4343227934b6e4e7c1eb51cb1e9acf Mon Sep 17 00:00:00 2001
From: alyelashram <alyahelashram at gmail.com>
Date: Tue, 27 May 2025 02:35:32 +0300
Subject: [PATCH 18/20] Process AArch64 first before target os

---
 libc/src/setjmp/CMakeLists.txt | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/libc/src/setjmp/CMakeLists.txt b/libc/src/setjmp/CMakeLists.txt
index 9fabe162dffe9..ef964210468d0 100644
--- a/libc/src/setjmp/CMakeLists.txt
+++ b/libc/src/setjmp/CMakeLists.txt
@@ -1,3 +1,9 @@
+# Process architecture-specific subdirectory FIRST to avoid missing targets.
+if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE})
+  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE})
+endif()
+
+# 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(
@@ -8,10 +14,7 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
   )
 endif()
 
-if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE})
-  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE})
-endif()
-
+message(STATUS "Target arch is ${LIBC_TARGET_ARCHITECTURE}")
 
 add_entrypoint_object(
   setjmp
@@ -44,4 +47,4 @@ if (TARGET libc.src.setjmp.sigsetjmp_epilogue)
     DEPENDS
       .${LIBC_TARGET_ARCHITECTURE}.sigsetjmp
   )
-endif()
+endif()
\ No newline at end of file

>From 1730c2d9e5b5985b280a8015d8e4dd147eef0c83 Mon Sep 17 00:00:00 2001
From: alyelashram <alyahelashram at gmail.com>
Date: Tue, 27 May 2025 02:40:11 +0300
Subject: [PATCH 19/20] Only add targets if the full build flag is on.

---
 libc/config/darwin/aarch64/entrypoints.txt | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index 65ad0d933e032..7b5747eab8a2b 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -20,11 +20,6 @@ set(TARGET_LIBC_ENTRYPOINTS
     # errno.h entrypoints
     libc.src.errno.errno
 
-    # setjmp.h entrypoints
-    libc.src.setjmp.longjmp
-    libc.src.setjmp.setjmp
-    libc.src.setjmp.siglongjmp
-    libc.src.setjmp.sigsetjmp
 
 
     # string.h entrypoints
@@ -108,6 +103,17 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.stdlib.free
 )
 
+if(LLVM_LIBC_FULL_BUILD)
+  list(APPEND TARGET_LIBC_ENTRYPOINTS
+    # setjmp.h entrypoints
+    libc.src.setjmp.longjmp
+    libc.src.setjmp.setjmp
+    libc.src.setjmp.siglongjmp
+    libc.src.setjmp.sigsetjmp
+  )
+endif()
+
+
 set(TARGET_LIBM_ENTRYPOINTS
     # complex.h entrypoints
     libc.src.complex.creal

>From deedbb850a2f58c62636ff41515453a3983e6d47 Mon Sep 17 00:00:00 2001
From: alyelashram <alyahelashram at gmail.com>
Date: Tue, 27 May 2025 02:51:12 +0300
Subject: [PATCH 20/20] Formatting changes

---
 libc/config/darwin/aarch64/config.json     | 2 +-
 libc/config/darwin/aarch64/entrypoints.txt | 2 --
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/libc/config/darwin/aarch64/config.json b/libc/config/darwin/aarch64/config.json
index e7d186e8ba64a..c82f13e5cbf79 100644
--- a/libc/config/darwin/aarch64/config.json
+++ b/libc/config/darwin/aarch64/config.json
@@ -5,4 +5,4 @@
       "doc": "Avoid setjmp saving the value of x18, and longjmp restoring it. The Apple AArch64 ABI specifies that this register is reserved and should not be used"
     }
   }
-}
\ No newline at end of file
+}
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index 7b5747eab8a2b..437eca79a76f6 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -20,8 +20,6 @@ set(TARGET_LIBC_ENTRYPOINTS
     # errno.h entrypoints
     libc.src.errno.errno
 
-
-
     # string.h entrypoints
     libc.src.string.memccpy
     libc.src.string.memchr



More information about the libc-commits mailing list