Skip to content
New issue

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

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

Already on GitHub? # to your account

zig c++: Unwinding across shared library boundaries doesn't work #11422

Open
sfackler opened this issue Apr 12, 2022 · 1 comment
Open

zig c++: Unwinding across shared library boundaries doesn't work #11422

sfackler opened this issue Apr 12, 2022 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior os-macos
Milestone

Comments

@sfackler
Copy link
Contributor

Zig Version

0.10.0-dev.1756+17631cb2d

Steps to Reproduce

With CXX set to either g++ or zig c++:

$ cat library.hpp
void throws_exception();
$ cat library.cpp
#include "library.hpp"

void throws_exception() {
        throw 1;
}
$ cat binary.cpp
include "library.hpp"
#include <iostream>

int main() {
        try {
                throws_exception();
        } catch (int e) {
                std::cout << "caught " << e << std::endl;
        }
}
$ $CXX -shared -o liblibrary.dylib -I. library.cpp
$ $CXX binary.cpp -I. -L. -llibrary
$ DYLD_LIBRARY_PATH=. ./a.out

Expected Behavior

The program should output "caught 1"

Actual Behavior

With CXX=g++:

$ DYLD_LIBRARY_PATH=. ./a.out
caught 1

With CXX=zig c++:

$ DYLD_LIBRARY_PATH=. ./a.out
Segmentation fault: 11

LLDB output:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
    frame #0: 0x00000001002e20c7 liblibrary.dylib`__cxxabiv1::readEncodedPointer(unsigned char const**, unsigned char, unsigned long) + 279
liblibrary.dylib`__cxxabiv1::readEncodedPointer:
->  0x1002e20c7 <+279>: movq   (%rax), %rax
    0x1002e20ca <+282>: jmp    0x1002e20ce               ; <+286>
    0x1002e20cc <+284>: xorl   %eax, %eax
    0x1002e20ce <+286>: movq   %r9, (%rdi)
Target 0: (a.out) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
  * frame #0: 0x00000001002e20c7 liblibrary.dylib`__cxxabiv1::readEncodedPointer(unsigned char const**, unsigned char, unsigned long) + 279
    frame #1: 0x00000001002e17d0 liblibrary.dylib`__gxx_personality_v0 + 304
    frame #2: 0x00007ff822498bf9 libunwind.dylib`_Unwind_RaiseException + 233
    frame #3: 0x00000001002e110c liblibrary.dylib`__cxa_throw + 108
    frame #4: 0x00000001002df7ed liblibrary.dylib`throws_exception() at library.cpp:4:2 [opt]
    frame #5: 0x0000000100000f03 a.out`main at binary.cpp:6:3 [opt]
    frame #6: 0x00000001000ea51e dyld`start + 462

On an aarch64 Linux host, instead of segfaulting I just see

libc++abi: terminating with uncaught exception of type int
Aborted
@sfackler sfackler added the bug Observed behavior contradicts documented or intended behavior label Apr 12, 2022
@andrewrk andrewrk added the zig cc Zig as a drop-in C compiler feature label Apr 16, 2022
@andrewrk andrewrk added this to the 0.11.0 milestone Apr 16, 2022
@sagehane
Copy link
Contributor

sagehane commented Apr 18, 2022

Perhaps #10892 is also related.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Observed behavior contradicts documented or intended behavior os-macos
Projects
None yet
Development

No branches or pull requests

3 participants