diff --git a/third_party/coro/coro.c b/third_party/coro/coro.c index ca490dc268a9d..65598d019531a 100644 --- a/third_party/coro/coro.c +++ b/third_party/coro/coro.c @@ -40,6 +40,8 @@ #include "coro.h" +#include "trivia/config.h" + #include #include @@ -103,9 +105,20 @@ coro_init (void) coro_transfer (new_coro, create_coro); -#if __GCC_HAVE_DWARF2_CFI_ASM && __amd64 - asm (".cfi_undefined rip"); -#endif + /* + * Call-chain ends here: we need to invalidate this frame's return + * address to make unwinding stop here. + * Some nuances on x86_64, see: + * https://github.com/libunwind/libunwind/blob/ec171c9ba7ea3abb2a1383cee2988a7 + * abd483a1f/src/x86_64/Gstep.c#L91-L92 + * https://github.com/libunwind/libunwind/blob/ec171c9ba7ea3abb2a1383cee2988a7 + * abd483a1f/src/dwarf/Gparser.c#L877 + */ +#ifdef ENABLE_BACKTRACE + __asm__(".cfi_undefined rip\n" + ".cfi_undefined rbp\n" + ".cfi_return_column rbp\n"); +#endif /* ENABLE_BACKTRACE */ func ((void *)arg); @@ -320,21 +333,32 @@ trampoline (int sig) ".fnend\n" #elif __aarch64__ - +#ifdef ENABLE_BACKTRACE ".cfi_startproc\n" - "\tmov x30, #0\n" - "\tsub sp, sp, #16\n" - "\tstr x30, [sp, #0]\n" - ".cfi_def_cfa_offset 16\n" - ".cfi_offset 30, -16\n" + /* + * Call-chain ends here: we need to invalidate this frame's return + * address to make unwinding stop here. + * No nuances: AARCH64 has a special link register for storing + * return addresses. + */ + ".cfi_undefined x30\n" "\tmov x0, x20\n" "\tblr x19\n" -# ifdef __APPLE__ +#ifdef __APPLE__ "\tb _abort\n" -# else +#else /* __APPLE__ */ "\tb abort\n" -# endif +#endif /* __APPLE__ */ ".cfi_endproc\n" +#else /* ENABLE_BACKTRACE */ + "\tmov x0, x20\n" + "\tblr x19\n" +#ifdef __APPLE__ + "\tb _abort\n" +#else /* __APPLE__ */ + "\tb abort\n" +#endif /* __APPLE__ */ +#endif /* ENABLE_BACKTRACE */ #else #error unsupported architecture @@ -834,4 +858,3 @@ coro_stack_free (struct coro_stack *stack) } #endif - diff --git a/third_party/coro/coro.h b/third_party/coro/coro.h index cc277e2786403..1c9fb66f36fae 100644 --- a/third_party/coro/coro.h +++ b/third_party/coro/coro.h @@ -420,4 +420,3 @@ void coro_destroy (coro_context *ctx); #endif #endif -