cannot build with exceptions
xantares opened this issue · comments
Hi again,
Why are exceptions disabled ?
Would it require to link against a cross-compiled version of llvm custom stdlib "libc++" ?
xan.
Exceptions are disabled because clang doesn't support exceptions on Windows.
Quoting http://clang.llvm.org/docs/MSVCCompatibility.html
Exceptions and SEH: Minimal. Clang can parse both constructs, but does not know how to emit compatible handlers. Clang cannot throw exceptions but it can rethrow them.
I have added -fno-exceptions
to cause a clear compiler error rather than weird linker errors.
Latest Clang from trunk:
$ cat test.cpp
#include <new>
#include <iostream>
int main()
{
try { new char[-1u]; }
catch(...) { std::cerr << "exception" << std::endl; }
return 0;
}
$ WCLANG_FORCE_CXX_EXCEPTIONS=1 w32-clang++ test.cpp -wc-verbose -wc-static-runtime
wclang: verbose: command in: w32-clang++ test.cpp -wc-verbose -wc-static-runtime
wclang: verbose: command out: /opt/other/llvm-trunk/bin/clang++ -static-libgcc -static-libstdc++ -target i686-w64-mingw32 -nostdinc -isystem /opt/other/llvm-trunk/bin/../lib/clang/3.6.0/include -isystem /usr/i686-w64-mingw32/include -isystem /usr/i686-w64-mingw32/include/../../../usr/lib/gcc/i686-w64-mingw32/4.9-win32/include/c++ -isystem /usr/i686-w64-mingw32/include/../../../usr/lib/gcc/i686-w64-mingw32/4.9-win32/include/c++/i686-w64-mingw32 test.cpp
wclang: verbose: start +0.001 ms
wclang: verbose: end +0.277 ms
/tmp/test-dfc3c5.o:(.text+0x122): undefined reference to `_Unwind_Resume'
/tmp/test-dfc3c5.o:(.eh_frame+0x63): undefined reference to `__gxx_personality_v0'
collect2: error: ld returned 1 exit status
clang-3.6: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)
hello,
although not advertised from v3.6 changelog, there as been work in clang regarding windows exceptions
from http://planet.clang.org/:
- Clang gained initial support for Win64 SEH IR emission, http://reviews.llvm.org/rL226760
- Initial support for Win64 SEH catch handlers has landed. See the commit message for current missing functionality: http://reviews.llvm.org/rL225904
- Reid Kleckner has posted an RFC on approaches to representing structured exception handling (SEH) in LLVM IR. This is the exception handling model used on Windows:
http://article.gmane.org/gmane.comp.compilers.clang.devel/39152 - The documentation on MSVC compatibility has been updated to represent the current state of affairs. Clang has also gained support for rethrowing MS C++ exceptions. r222731, r222733.
Does this allow to generate exception with mingw ?
Yes, 64-bit SEH exceptions are working now with trunk (3.7), but not with 3.6, as 3.6 was branched before exception support was added.
I have removed the -fno-exceptions
flag for 3.7 + 64-bit.