问题
I am trying to use llvm as a code-generation back-end to my software and just realized that llvm was compiled without support for C++ exception handling (for efficiency). In my software, however, I use exception handling extensively.
If I wrap all my callback functions in try-catch-blocks (so that no exceptions need to be propagated "through" the llvm code), can I then safely remove the "-fno-exceptions" (for GCC) from my linker flags? (this flag is normally required when linking with llvm, as it turns up when doing llvm-config --cxxflags).
If not, does the situation change if I wrap the llvm functions with functions declared with "throws ()"? The implementation of these functions could be compiled with -fno-exceptions.
回答1:
If I wrap all my callback functions in try-catch-blocks (so that no exceptions need to be propagated "through" the llvm code), can I then safely remove the "-fno-exceptions" (for GCC) from my linker flags?
Yes, assuming you have a suitable way of reporting whatever conditions caused the exceptions to be thrown.
-fexceptions is the default for C++. -fno-exceptions is the default for C. There is no problem at all mixing C++ code compiled with the default options together with C code compiled with the default options, so there cannot be a problem mixing -fexceptions with -fno-exceptions.
But consider adding -fexceptions instead of removing -fno-exceptions: parsing command-line options in the exact same way as GCC is complicated, and there is no need for you to attempt to do so.
来源:https://stackoverflow.com/questions/9545688/linking-with-code-that-does-not-support-exception-handling-c-llvm