Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix backtrace beyond _singtramp on macOS arm64 #7015

Merged
merged 1 commit into from Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 0 additions & 9 deletions addr2line.c
Expand Up @@ -2549,15 +2549,6 @@ rb_dump_backtrace_with_lines(int num_traces, void **traces)
/* 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;
Expand Down
19 changes: 17 additions & 2 deletions vm_dump.c
Expand Up @@ -496,6 +496,7 @@ backtrace(void **trace, int size)

unw_getcontext(&uc);
unw_init_local(&cursor, &uc);
# if defined(__x86_64__)
while (unw_step(&cursor) > 0) {
unw_get_reg(&cursor, UNW_REG_IP, &ip);
trace[n++] = (void *)ip;
Expand All @@ -511,7 +512,6 @@ backtrace(void **trace, int size)
darwin_sigtramp:
/* darwin's bundled libunwind doesn't support signal trampoline */
{
#if defined(__x86_64__)
ucontext_t *uctx;
char vec[1];
int r;
Expand Down Expand Up @@ -572,7 +572,6 @@ backtrace(void **trace, int size)
trace[n++] = (void *)ip;
ip = *(unw_word_t*)uctx->uc_mcontext->MCTX_SS_REG(rsp);
}
#endif

trace[n++] = (void *)ip;
unw_set_reg(&cursor, UNW_REG_IP, ip);
Expand All @@ -582,6 +581,22 @@ backtrace(void **trace, int size)
trace[n++] = (void *)ip;
}
return n;

# else /* defined(__arm64__) */
/* Since Darwin arm64's _sigtramp is implemented as normal function,
* unwind can unwind frames without special code.
* https://github.com/apple/darwin-libplatform/blob/215b09856ab5765b7462a91be7076183076600df/src/setjmp/generic/sigtramp.c
*/
while (unw_step(&cursor) > 0) {
unw_get_reg(&cursor, UNW_REG_IP, &ip);
// Strip Arm64's pointer authentication.
// https://developer.apple.com/documentation/security/preparing_your_app_to_work_with_pointer_authentication
// I wish I could use "ptrauth_strip()" but I get an error:
// "this target does not support pointer authentication"
trace[n++] = (void *)(ip & 0x7fffffffffffull);
}
return n;
# endif
}
# elif defined(BROKEN_BACKTRACE)
# undef USE_BACKTRACE
Expand Down