Reference the unwinder weakly from the runtime's raise

scr_unwind.c is linked into every Linux executable, and its references
to _Unwind_ForcedUnwind and _Unwind_GetCFA pulled the unwinder out of
libgcc_eh (or Zig's libunwind) even for programs that never raise, which
grew a static hello world past its size ceiling. The references are now
weak: programs that raise reference the personality routine from their
landing pads, and its unit links the unwinder in.
This commit is contained in:
Chris Tate
2026-10-24 15:38:37 -05:00
parent 2967a1b8c0
commit d4fcd787a8
+8 -1
View File
@@ -10,6 +10,13 @@
#include <string.h>
#include <unwind.h>
/* Weak, so the runtime unit alone does not link the unwinder into every
* program: programs that raise reference the personality routine from
* their landing pads, and its unit references the unwinder's entry points,
* which link it in. */
#pragma weak _Unwind_ForcedUnwind
#pragma weak _Unwind_GetCFA
#if defined(__SANITIZE_ADDRESS__)
#define SCR_UNWIND_ASAN 1
#elif defined(__has_feature)
@@ -69,7 +76,7 @@ void scr_unwind_raise(void) {
#ifdef SCR_UNWIND_ASAN
scr_unwind_low = (uintptr_t)__builtin_frame_address(0);
#endif
_Unwind_ForcedUnwind(exc, scr_unwind_stop, NULL);
if (_Unwind_ForcedUnwind != NULL) _Unwind_ForcedUnwind(exc, scr_unwind_stop, NULL);
fputs("scriptc: the native unwinder could not raise an exception\n", stderr);
abort();
}