From 65920cfc40b47e9e037e0536b2b7de8f0cf30fc3 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Mon, 19 Dec 2022 17:15:31 +0900 Subject: addr2line.c: Strip pointer authentication We need to manually strip pointer authentication bits on M1 mac because libunwind leaks them out. Co-Authored-By: NARUSE, Yui Co-Authored-By: Yuta Saito --- addr2line.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'addr2line.c') diff --git a/addr2line.c b/addr2line.c index 00f542261e..77538f6eb9 100644 --- a/addr2line.c +++ b/addr2line.c @@ -2548,6 +2548,16 @@ rb_dump_backtrace_with_lines(int num_traces, void **traces) obj_info_t *obj = NULL; /* 2 is NULL + main executable */ void **dladdr_fbases = (void **)calloc(num_traces+2, sizeof(void *)); + +#if defined(__APPLE__) && defined(__aarch64__) + // Strip Arm64's pointer authentication. + for (i = 0; i < num_traces; i++) { + // I wish I could use "ptrauth_strip()" but I get an error: + // "this target does not support pointer authentication" + traces[i] = (void*)(((uint64_t)traces[i]) & 0x7fffffffffffull); + } +#endif + #ifdef HAVE_MAIN_EXE_PATH char *main_path = NULL; /* used on printing backtrace */ ssize_t len; -- cgit v1.2.3