6

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.

Joel
  • 1,295
  • 15
  • 30
  • I wouldn't bet on ABI compability, but who knows? It may be easier and safer to compile LLVM yourself with exceptions enabled. –  Mar 03 '12 at 11:36
  • @delnan Compiling llvm is not an option. My software is used by several people on different platforms (linux, mac, windows) and I need to rely on the default llvm installation that you get e.g. from apt-get. – Joel Mar 03 '12 at 11:54
  • @delnan: I don't know much about ABI compatibility, but would I get it in this case if functions are declared with throws()? I modified the question accordingly. – Joel Mar 03 '12 at 12:30
  • AFAIK, LLVM packages in most Linux distros are built with exceptions and RTTI. – arrowd Mar 04 '12 at 12:45
  • @arrowdodger On Ubuntu 10.4 at least, it was not the case – Joel Mar 04 '12 at 16:52

1 Answers1

4

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.