Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
andrewrk opened this issue Sep 13, 2022 · 1 comment
Labels
backend-llvm The LLVM backend outputs an LLVM IR Module. bug Observed behavior contradicts documented or intended behavior os-linux upstream An issue with a third party project that Zig uses.
Milestone

Comments

@andrewrk
Copy link
Member

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 andrewrk added bug Observed behavior contradicts documented or intended behavior os-linux regression It worked in a previous version of Zig, but stopped working. labels Sep 13, 2022
@andrewrk andrewrk added this to the 0.10.0 milestone Sep 13, 2022
andrewrk added a commit that referenced this issue Sep 13, 2022
See tracking issue #12828
@andrewrk
Copy link
Member Author

This is now a tracking issue for llvm/llvm-project#56825

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

@andrewrk andrewrk changed the title zig-provided libc++ can no longer throw exceptions in release modes with static musl after upgrading to LLVM 15 With LTO enabled for libunwind, zig-provided libc++ cannot throw exceptions in release modes with static musl after upgrading to LLVM 15 Sep 13, 2022
@andrewrk andrewrk added upstream An issue with a third party project that Zig uses. backend-llvm The LLVM backend outputs an LLVM IR Module. and removed regression It worked in a previous version of Zig, but stopped working. labels Sep 13, 2022
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Sep 13, 2022
andrewrk added a commit that referenced this issue Sep 13, 2022
This reverts commit d31be31.

The problem was happening due to an LLVM bug exposed by having LTO
enabled for libunwind. The simple workaround is to disable LTO for
libunwind. It can be re-enabled in the future when the upstream bug
is fixed.

See #12828
Vexu pushed a commit to Vexu/zig that referenced this issue Oct 10, 2022
Vexu pushed a commit to Vexu/zig that referenced this issue Oct 10, 2022
This reverts commit d31be31.

The problem was happening due to an LLVM bug exposed by having LTO
enabled for libunwind. The simple workaround is to disable LTO for
libunwind. It can be re-enabled in the future when the upstream bug
is fixed.

See ziglang#12828
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend-llvm The LLVM backend outputs an LLVM IR Module. bug Observed behavior contradicts documented or intended behavior os-linux upstream An issue with a third party project that Zig uses.
Projects
None yet
Development

No branches or pull requests

1 participant