[llvm-dev] LLVM MCJIT SEH Exception handling
Stefan de Bruijn via llvm-dev
llvm-dev at lists.llvm.org
Tue Sep 6 01:44:29 PDT 2016
I apologize if I'm posting this to the wrong list; if this is the case, please let me know.
For some time now, I've been trying to get SEH exception handling to work in LLVM MCJIT (x64). While reading up on LLVM 3.8, I decided to pick it up again, because a lot has changed which simplifies things greatly.
As a toy project, I'm attempting to catch an exception that's thrown in a Windows x64 C++ library call from within an LLVM x64 MCJIT instance. The version I'm working with is LLVM 3.8.1, and the code I've created is based on the documentation http://llvm.org/docs/ExceptionHandling.html . I've also been reading up on the Exception toy/example code that's shipped with LLVM, as well as several mail discussions, the CGException class from clang and of course the ever useful 'clang --emit-llvm'. My aim here is to create a minimum working test case.
My first attempt was to simply compile a piece of C++ code with an external function call and run that through LLC. The code is pretty straight-forward:
extern "C++" void Test2();
My first attempt was to run LLC to simply create the code for me. Basically the steps I took were:
- clang -std=c++14 -O3 -emit-llvm -S -fexceptions -fms-compatibility -fcxx-exceptions test.cpp
- llc -march=cpp -o test_exceptions.cpp test.ll
Unfortunately this won't work; LLC doesn't seem to support this and will exit with an error: 'LLVM ERROR: Bad constant'.
My second attempt was to simply create the CPP code myself and emit the same IR code that clang has so gracefully provided me. The complete code of a self-contained minimum test case can be found at http://stackoverflow.com/questions/39224636/llvm-mcjit-seh-exception-handling . However, when I try to run that code, the exception seems to corrupt the stack and the Visual Studio debugger will abort the execution with "Stack cookie instrumentation code detected a stack-based buffer overrun.".
Currently I'm a bit lost what to try next. At this point I'm not even sure if this behavior is to be expected or not. I'm by no means an expert on SEH exception handling, so any help or advice would be very much appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the llvm-dev