[libc-commits] [libc] [libc][AArch64] Add an AArch64 setjmp/longjmp. (PR #101177)

Simon Tatham via libc-commits libc-commits at lists.llvm.org
Wed Jul 31 02:00:39 PDT 2024


================
@@ -0,0 +1,93 @@
+//===-- Implementation of setjmp 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/__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, (__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"(
+        hint #25 // PACIASP
----------------
statham-arm wrote:

So you can! I assumed that if you were compiling for an AArch64 architecture without those instructions, you'd have to refer to them by the hint names. But no, clang accepts the PAC mnemonics even at plain `armv8a`. Thanks.

https://github.com/llvm/llvm-project/pull/101177


More information about the libc-commits mailing list