ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.32k stars 2.51k forks source link

Missing symbol `__gcc_personality_seh0` for `zig cc -target x86_64-windows-gnu -fexceptions` and `__attribute__((cleanup))` #9383

Closed alexrp closed 1 week ago

alexrp commented 3 years ago
$ zig version
0.8.0
$ cat main.c
static void cleanup(void *p) {}

int main (void)
{
    int a __attribute__((cleanup(cleanup)));
    int b __attribute__((cleanup(cleanup)));
}
$ zig cc main.c -target x86_64-windows-gnu -fexceptions
lld-link: error: undefined symbol: __gcc_personality_seh0
>>> referenced by C:\Users\alex\AppData\Local\zig\o\24f89eeeaa605b321fb98488ff7e9c91\main.obj

(For some reason, it only happens with 2+ variables using the cleanup attribute.)

alexrp commented 3 months ago

This still reproduces with 0.13.0, but now gives an additional error:

❯ zig cc main.c -target x86_64-windows-gnu -fexceptions
lld-link: error: undefined symbol: _Unwind_Resume
>>> referenced by C:\Users\Alex Rønne Petersen\source\repos\tests\main.c:7
>>>               C:\Users\Alex Rønne Petersen\AppData\Local\zig\o\ae60fb380b2b070096508d68b5346ae2\main.obj:(main)

lld-link: error: undefined symbol: __gcc_personality_seh0
>>> referenced by C:\Users\Alex Rønne Petersen\AppData\Local\zig\o\ae60fb380b2b070096508d68b5346ae2\main.obj:(.xdata)
alexrp commented 2 months ago

For reference, the code we need to port is here: https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/builtins/gcc_personality_v0.c

alexrp commented 1 week ago

This now works after #21472, but requires adding -lunwind.