Skip to content

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

@andrewrk

Description

@andrewrk

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) 

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend-llvmThe LLVM backend outputs an LLVM IR Module.bugObserved behavior contradicts documented or intended behavioros-linuxupstreamAn issue with a third party project that Zig uses.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions