[libc-commits] [libc] 9ebaa9d - [libc] implement aarch64 sigsetjmp (#136706)

via libc-commits libc-commits at lists.llvm.org
Tue Apr 29 13:37:28 PDT 2025


Author: Schrodinger ZHU Yifan
Date: 2025-04-29T16:37:25-04:00
New Revision: 9ebaa9d483740b1e9a796e9e3b40a2ab70a4efb5

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

LOG: [libc] implement aarch64 sigsetjmp (#136706)

- **[libc][aarch64] implement sigsetjmp**

On top of https://github.com/llvm/llvm-project/pull/136072
See also https://github.com/llvm/llvm-project/issues/137055 for remarks
on naked attributes.

```c++
//===-- Implementation of setjmp ------------------------------------------===//
//
// 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)) {
  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
```

Added: 
    libc/src/setjmp/aarch64/sigsetjmp.cpp

Modified: 
    libc/config/linux/aarch64/entrypoints.txt
    libc/include/llvm-libc-types/jmp_buf.h
    libc/src/setjmp/aarch64/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 1c27f845af8a7..66d7576ffb882 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -933,6 +933,8 @@ if(LLVM_LIBC_FULL_BUILD)
     # setjmp.h entrypoints
     libc.src.setjmp.longjmp
     libc.src.setjmp.setjmp
+    libc.src.setjmp.siglongjmp
+    libc.src.setjmp.sigsetjmp
 
     # stdio.h entrypoints
     libc.src.stdio.clearerr

diff  --git a/libc/include/llvm-libc-types/jmp_buf.h b/libc/include/llvm-libc-types/jmp_buf.h
index d1a13a353d17c..7e7d2da8a932a 100644
--- a/libc/include/llvm-libc-types/jmp_buf.h
+++ b/libc/include/llvm-libc-types/jmp_buf.h
@@ -12,7 +12,7 @@
 // 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__)
+#if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__)
 #define __LIBC_HAS_SIGJMP_BUF
 #endif
 #endif

diff  --git a/libc/src/setjmp/aarch64/CMakeLists.txt b/libc/src/setjmp/aarch64/CMakeLists.txt
index e0e7702c7c4b6..1078af8ce04f3 100644
--- a/libc/src/setjmp/aarch64/CMakeLists.txt
+++ b/libc/src/setjmp/aarch64/CMakeLists.txt
@@ -26,3 +26,17 @@ add_entrypoint_object(
     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
+)

diff  --git a/libc/src/setjmp/aarch64/sigsetjmp.cpp b/libc/src/setjmp/aarch64/sigsetjmp.cpp
new file mode 100644
index 0000000000000..734591b2aca4c
--- /dev/null
+++ b/libc/src/setjmp/aarch64/sigsetjmp.cpp
@@ -0,0 +1,36 @@
+//===-- Implementation of 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)) {
+  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


        


More information about the libc-commits mailing list