与不支持异常处理的代码链接(C ++/LLVM) [英] Linking with code that does not support exception handling (C++/LLVM)

查看:90
本文介绍了与不支持异常处理的代码链接(C ++/LLVM)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将llvm用作软件的代码生成后端,并且刚刚意识到llvm编译时不支持C ++异常处理(以提高效率).但是,在我的软件中,我广泛使用异常处理.

如果我将所有回调函数都包装在try-catch-blocks中(这样就无需通过llvm代码传播"任何异常),然后可以安全地从中删除"-fno-exceptions"(对于GCC)我的链接器标志? (与llvm链接时通常需要此标志,因为在执行llvm-config --cxxflags时会出现此标志.)

如果没有,将llvm函数包装为用"throws()"声明的函数,情况是否会改变?这些功能的实现可以使用-fno-exceptions进行编译.

解决方案

如果我将所有回调函数都包装在try-catch-blocks中(这样就无需通过" llvm代码传播任何异常),然后我可以从中安全删除"-fno-exceptions"(对于GCC)了吗?我的链接器标志?

是的,假设您有一种适当的方式来报告导致异常抛出的任何条件.

-fexceptions是C ++的默认设置. -fno-exceptions是C的默认值.将使用默认选项编译的C ++代码与使用默认选项编译的C代码混合在一起完全没有问题,因此将-fexceptions-fno-exceptions混合不会有问题.

但是请考虑添加-fexceptions而不是删除-fno-exceptions:解析命令行选项的方式与GCC完全相同,这很复杂,因此您无需尝试这样做.

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.

解决方案

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.

这篇关于与不支持异常处理的代码链接(C ++/LLVM)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆