2011-08-19 308 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。