[libunwind] [libunwind][PAC] Defang ptrauth's PC in valid CFI range abort (PR #184041)
Anatoly Trosinenko via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 11 03:59:41 PDT 2026
================
@@ -0,0 +1,91 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: target={{(aarch64|s390x|x86_64|arm64e)-.+}}
+// UNSUPPORTED: target={{.*-windows.*}}
+
+// *SAN does not like our clearly nonsense personality and handler functions
+// which is the correct response for them, but alas we have to allow it for JITs
+// because they tend to use a shared handler rather than having the handler
+// within the function bounds.
+// UNSUPPORTED: asan
+// UNSUPPORTED: msan
+
+#include <libunwind.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <unwind.h>
+
+extern "C" void exit(int);
+
+struct alignas(16) AlignmentTester {
+ __attribute__((noinline)) void testAlignment() {
+ uintptr_t thisValue = (uintptr_t)this;
+ if (thisValue % 16 != 0) {
+ fprintf(stderr, "Test bug: unaligned handler frame\n");
+ __builtin_trap();
+ }
+ }
+};
+
+#if defined(__x86_64__)
+// Use an intermediary function on x86_64 as the handlers are dispatched with
+// the expectation that they will perform some stack correction, most notably
+// planting down a restored base pointer
+extern "C" int randomUnrelatedFunctionImpl();
+__attribute__((naked)) int randomUnrelatedFunction() {
+ asm("pushq %rbp \n\t"
+ "movq %rsp, %rbp\n\t"
+ "jmp _randomUnrelatedFunctionImpl\n\t");
+}
+extern "C" __attribute__((noinline)) int randomUnrelatedFunctionImpl() {
+#else
+static int randomUnrelatedFunction() {
----------------
atrosinenko wrote:
The `extern "C" __attribute__((noinline))` variant could probably be used in both cases for uniformity.
https://github.com/llvm/llvm-project/pull/184041
More information about the cfe-commits
mailing list