Skip to content

Commit 1bc57b5

Browse files
committed
[Bug #21150] macOS: Temporary workaround at unwinding coroutine
On arm64 macOS, libunwind (both of system library and homebrew llvm-18) seems not to handle our coroutine switching code.
1 parent d97884a commit 1bc57b5

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

addr2line.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,11 @@ fill_filename(int file, uint8_t format, uint16_t version, const char *include_di
296296
for (i = 1; i <= file; i++) {
297297
filename = p;
298298
if (!*p) {
299+
#ifndef __APPLE__
299300
/* Need to output binary file name? */
300301
kprintf("Unexpected file number %d in %s at %tx\n",
301302
file, binary_filename, filenames - obj->mapped);
303+
#endif
302304
return;
303305
}
304306
while (*p) p++;

thread_pthread_mn.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,12 @@ native_thread_check_and_create_shared(rb_vm_t *vm)
429429
}
430430
}
431431

432-
static COROUTINE
432+
#ifdef __APPLE__
433+
# define co_start ruby_coroutine_start
434+
#else
435+
static
436+
#endif
437+
COROUTINE
433438
co_start(struct coroutine_context *from, struct coroutine_context *self)
434439
{
435440
#ifdef RUBY_ASAN_ENABLED

vm_dump.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,15 @@ rb_vmdebug_thread_dump_state(FILE *errout, VALUE self)
510510
# include <libunwind.h>
511511
# include <sys/mman.h>
512512
# undef backtrace
513+
514+
static bool
515+
is_coroutine_start(unw_word_t ip)
516+
{
517+
struct coroutine_context;
518+
extern void ruby_coroutine_start(struct coroutine_context *, struct coroutine_context *);
519+
return ((void *)(ip) == (void *)ruby_coroutine_start);
520+
}
521+
513522
int
514523
backtrace(void **trace, int size)
515524
{
@@ -617,6 +626,9 @@ backtrace(void **trace, int size)
617626
// I wish I could use "ptrauth_strip()" but I get an error:
618627
// "this target does not support pointer authentication"
619628
trace[n++] = (void *)(ip & 0x7fffffffffffull);
629+
630+
// Apple's libunwind can't handle our coroutine switching code
631+
if (is_coroutine_start(ip)) break;
620632
}
621633
return n;
622634
# endif

0 commit comments

Comments
 (0)