Skip to content

Commit 4f2bb41

Browse files
Improve libunwind support on macos and test in ci (#315)
1 parent 9a56f9e commit 4f2bb41

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

ci/test-all-configs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ def run_macos_matrix(compilers: list, shared: bool):
393393
"unwind": [
394394
"CPPTRACE_UNWIND_WITH_EXECINFO",
395395
"CPPTRACE_UNWIND_WITH_UNWIND",
396+
"CPPTRACE_UNWIND_WITH_LIBUNWIND",
396397
#"CPPTRACE_UNWIND_WITH_NOTHING",
397398
],
398399
"symbols": [

src/unwind/unwind_with_libunwind.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@
1212

1313
#include <libunwind.h>
1414

15+
namespace {
16+
// Strip pointer authentication code from an instruction address.
17+
// Apple's unw_get_reg(UNW_REG_IP) may return PAC-signed addresses with signature bits in
18+
// the upper bytes.
19+
inline uintptr_t depaci(uintptr_t pc) {
20+
#if defined(__APPLE__) && (defined(__arm64__) || defined(__aarch64__))
21+
__asm__ volatile("xpaci %0" : "+r"(pc));
22+
#endif
23+
return pc;
24+
}
25+
}
26+
1527
CPPTRACE_BEGIN_NAMESPACE
1628
namespace detail {
1729
CPPTRACE_FORCE_NO_INLINE
@@ -26,6 +38,7 @@ namespace detail {
2638
unw_word_t pc;
2739
unw_word_t sp;
2840
unw_get_reg(&cursor, UNW_REG_IP, &pc);
41+
pc = depaci(pc);
2942
unw_get_reg(&cursor, UNW_REG_SP, &sp);
3043
if(skip) {
3144
skip--;
@@ -53,6 +66,7 @@ namespace detail {
5366
unw_word_t sp;
5467
// thread and signal-safe https://www.nongnu.org/libunwind/man/unw_get_reg(3).html
5568
unw_get_reg(&cursor, UNW_REG_IP, &pc);
69+
pc = depaci(pc);
5670
unw_get_reg(&cursor, UNW_REG_SP, &sp);
5771
if(skip) {
5872
skip--;

0 commit comments

Comments
 (0)