SIGSEGV在DSO,混合的C / C ++ [英] SIGSEGV in DSO, mixed C/C++

查看:162
本文介绍了SIGSEGV在DSO,混合的C / C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是SWI-Prolog的外语界面 C ++,试图整合一些其他的资源。

I'm using the SWI-Prolog foreign language interface for C++, attempting to integrate some other resource.

它主要工作,但任何试图在SIGSEGV抛出异常的结果。异常在的用户参数的验证常规使用,并且因此所述接口的基本组成部分。

It mostly works, but any attempt to throw an exception result in a SIGSEGV. Exceptions are routinely used in validation of user parameters, and thus are a fundamental part of the interface.

我是从源代码编译SWI-Prolog的(通过提供的脚本),以及CXX标志

I'm compiling SWI-Prolog from source (via supplied script), and the CXX flags are

-c -O2 -gdwarf-2 -g3 -Wall -pthread -fPIC

我使用的是相同的标志来编译我的C ++ code,即组装在一个.so,在SWI-Prolog的动态加载(通过的dlopen,我认为)。

I'm using the same flags to compile my C++ code, that is assembled in a .so, dynamically loaded in SWI-Prolog (via dlopen, I think).

在SEGV后堆栈(通过GDB)的检查表明AT&LT的IP; +36>,里面__cxa_allocate_exception。可能__cxa_get_globals @ PLT无法访问。

Inspection of the stack (via GDB) after the SEGV shows the IP at <+36>, inside __cxa_allocate_exception. Likely __cxa_get_globals@plt isn't accessible.

        Dump of assembler code for function __cxa_allocate_exception:
0x00007ffff1d80220  <+0>:               push   %r12
0x00007ffff1d80222  <+2>:               lea    0x80(%rdi),%r12
0x00007ffff1d80229  <+9>:               push   %rbp
0x00007ffff1d8022a  <+10>:              mov    %r12,%rdi
0x00007ffff1d8022d  <+13>:              push   %rbx
0x00007ffff1d8022e  <+14>:              callq  0x7ffff1d1de30 <malloc@plt>
0x00007ffff1d80233  <+19>:              test   %rax,%rax
0x00007ffff1d80236  <+22>:              mov    %rax,%rbx
0x00007ffff1d80239  <+25>:              je     0x7ffff1d802d8 <__cxa_allocate_exception+184>
0x00007ffff1d8023f  <+31>:              callq  0x7ffff1d1efc0 <__cxa_get_globals@plt>
0x00007ffff1d80244  <+36>:              addl   $0x1,0x8(%rax)
0x00007ffff1d80248  <+40>:              test   $0x1,%bl
0x00007ffff1d8024b  <+43>:              mov    %rbx,%rdi
0x00007ffff1d8024e  <+46>:              mov    $0x80,%edx
0x00007ffff1d80253  <+51>:              jne    0x7ffff1d803d0 <__cxa_allocate_exception+432>
0x00007ffff1d80259  <+57>:              test   $0x2,%dil

借助唯一的资源我已经能够找到,这似乎相关的索赔

The only resource I've been able to find that seems pertinent claims

除了要求所属类别查找

和这样可以使SIGSEGV感。

and this could make sense of the SIGSEGV.

但我现在无法继续进行。当然,我希望能在一些神奇CXX或LD标志。
或者我应该装饰我的库入口点(我认识到Windows declspec(S),我用他们广泛建立MFC扩展DLL)或什么?

But I'm unable to proceed now. Of course, I hope in some magic CXX or LD flag. Or should I decorate my library entry points (I'm acquainted to Windows declspec(s), I used them extensively to build MFC extension DLLs) or whatever?

推荐答案

当来自前导叫,你不能抛出任何异常到Prolog的内核。在C ++接口将赶上PlException和它的子类,并将其转化为Prolog的例外。所有其他异常绝不允许逃脱你的库。

When called from Prolog, you can't throw any exceptions into the Prolog kernel. The C++ interface will catch PlException and its subclasses and transform them into Prolog exceptions. All other exceptions must not be allowed to escape your library.

由于SWI Prolog是LGPL,你可能动态链接到它。因此,你必须确保所有的C ++被抛出对ELF系统默认的知名度。

Since SWI Prolog is LGPL, you are probably dynamically linking to it. Therefore, you must ensure that all C++ that are thrown have default visibility on ELF systems.

这篇关于SIGSEGV在DSO,混合的C / C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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