zig icon indicating copy to clipboard operation
zig copied to clipboard

With LTO enabled for libunwind, zig-provided libc++ cannot throw exceptions in release modes with static musl after upgrading to LLVM 15

Open andrewrk opened this issue 3 years ago • 1 comments

Reproduction:

$ zig build test-standalone

Or more precisely:

[nix-shell:~/dev/zig/test/standalone/c_compiler]$ ../../../build-llvm15/stage3/bin/zig build test -Dtarget=native-native-musl -Drelease-safe
libc++abi: terminating due to uncaught exception of type int
The following command terminated unexpectedly:
cd /home/andy/dev/zig/test/standalone/c_compiler && /home/andy/dev/zig/test/standalone/c_compiler/zig-cache/o/9c5c6f76b50c4f1fa06f77a845e869b7/test_cpp 
error: the following build command failed with exit code 1:
/home/andy/dev/zig/test/standalone/c_compiler/zig-cache/o/d8562c3cd84702a070abce1bcd28b9aa/build /home/andy/dev/zig/build-llvm15/stage3/bin/zig /home/andy/dev/zig/test/standalone/c_compiler /home/andy/dev/zig/test/standalone/c_compiler/zig-cache /home/andy/.cache/zig test -Dtarget=native-native-musl -Drelease-safe

In GDB, it looks like C++ failed to throw an exception:

libc++abi: [LWP 1426813 exited]
terminating due to uncaught exception of type int

Thread 1 "test_cpp" received signal SIGABRT, Aborted.
0x0000000000264897 in raise ()
(gdb) up
#1  0x00000000002603a9 in abort ()
(gdb) 
#2  0x00000000002224bf in abort_message ()
(gdb) 
#3  0x00000000002228ca in demangling_terminate_handler() ()
(gdb) 
#4  0x0000000000222533 in std::__terminate(void (*)()) ()
(gdb) 
#5  0x0000000000221db6 in __cxxabiv1::failed_throw(__cxxabiv1::__cxa_exception*) ()
(gdb) 
#6  0x0000000000221d54 in __cxa_throw ()
(gdb) 
#7  0x000000000021fb60 in main (argc=1, argv=<optimized out>) at test.cpp:72
72	    throw 20;
(gdb) 

andrewrk avatar Sep 13 '22 06:09 andrewrk

This is now a tracking issue for https://github.com/llvm/llvm-project/issues/56825

When it is fixed, LTO for libunwind can be re-enabled.

andrewrk avatar Sep 13 '22 18:09 andrewrk