2011-08-19 303 views
1

我正面临一个奇怪的问题,涉及跨DSO边界抛出的异常。 当代码被编译的嵌入式Linux板用臂-NONE-Linux的gnueabi-G ++,从ubuntu的一切正常异常不能被捕获,如果与正常gcc编译编译:(不可捕捉的C++异常(共享库,arm-linux-gnueabi-g ++)

澄清:

我们有三个组成部分:

一个Executeable文件,该文件通过dlopen()的加载的DSO,对dlsym()..

一个DSO文件(libMod2.so),其包含类MOD2会抛出自定义EException (从std :: runtime_error派生)在调用throwException()时

一个DSO文件(libtest.so),包含一个MOD1类,它获得一个指向MOD2类的指针并调用MOD2 :: throwException()。

void MOD1::setMod2(IMOD2* mod2){ 
    cout << "Calling mod2 throwException()" << endl; 
    try{ 
     mod2->throwException(); 
    }catch(EException& e){ 
     cout << "Got you!" << endl << e.what() << endl; 
    }catch (...){ 
     cout << "slippery shit..." << endl; 
    } 
} 

现在的问题是,异常无法被arm目标上的第一个异常处理程序捕获。

我认为这个问题是在链接时产生的: 在DSO上的nm -C显示了EException异常时的一些差异。

TARGET:

[email protected]:/var/lib/tftpboot$ /opt/freescale/usr/local/gcc-4.4.4-glibc-2.11.1-multilib-1.0/arm-fsl-linux-gnueabi/bin/arm-none-linux-gnueabi-g++ --version 
arm-none-linux-gnueabi-g++ (4.4.4_09.06.2010) 4.4.4 
Copyright (C) 2010 Free Software Foundation, Inc. 
This is free software; see the source for copying conditions. There is NO 
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOS 



[email protected]:/var/lib/tftpboot$ nm -C libtest.so | grep EEx 
00009ef0 V typeinfo for EException 
000017f4 V typeinfo name for EException 

Ubuntu的:

[email protected]:/nfs$ g++ --version 
g++ (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5 
Copyright (C) 2010 Free Software Foundation, Inc. 
This is free software; see the source for copying conditions. There is NO 
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 

[email protected]-TT:/nfs$ nm -C libtest.so | grep EEx 
0000303c d DW.ref._ZTI10EException 
00002edc V typeinfo for EException 
00001373 V typeinfo name for EException 

的DSO与Ubuntu GCC创建具有额外符号DW.ref._ZTI10EException。我认为解决方案是将这个符号也带入arm-DSO,但是如何?

有人知道这个问题吗?

回答

0

问题解决了!

问题不是链接器相关,它更简单,更简单。

我解决了它通过添加RTLD_GLOBAL到dlopen()调用。看来,我的ubuntu安装中的标准gcc默认设置了这个,arm目标的编译器使用默认的RTLD_LOCAL。