Linking with code that does not support exception handling (C++/LLVM)

淺唱寂寞╮ 提交于 2019-12-23 09:11:48

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!