2011-08-19 2 views
1

DSO 경계를 넘어서 던진 예외와 관련된 이상한 문제가 있습니다. 코드가 정상 GCC 컴파일러로 컴파일하면 우분투는 모든 것이 잘 작동에서 예외가 잡힐 수 없습니다 팔 - 없음 - 리눅스 - gnueabi-g ++, 임베디드 리눅스 보드 용으로 컴파일 할 때 :(Uncatchable C++ 예외 (공유 라이브러리, arm-linux-gnueabi-g ++)

는 명확히하기 :

를 자기 정의 던져 클래스 MOD2을 포함, dlopen을()를 통해 DSO를로드

하나하는 실행 파일 파일, dlsym을() ..

하나 DSO 파일 (libMod2.so) :

우리는 세 가지 구성 요소가 throwException() 호출시 (std :: runtime_error에서 파생)

하나의 DSO 파일 (libtest.so)은 MOD2 클래스에 대한 포인터를 가져 와서 MOD2 :: throwException()을 호출하는 클래스 MOD1을 포함합니다.

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; 
    } 
} 

이제 팔 대상의 첫 번째 예외 처리기에서 예외를 발견 할 수없는 문제가 있습니다.

링크 할 때 문제가 발생한다고 생각합니다. DSO의 nm -C에 EException을 그릴 때 약간의 차이가 있습니다.

TARGET :

t[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 

우분투 : 우분투 gcc가 만들어

[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]:/nfs$ nm -C libtest.so | grep EEx 
0000303c d DW.ref._ZTI10EException 
00002edc V typeinfo for EException 
00001373 V typeinfo name for EException 

DSO를가 추가 기호 DW.ref._ZTI10EException 있습니다. 나는 해결책이 팔 -DSO에도이 기호를 가져 오는 것이라고 생각하지만, 어떻게?

아무도이 문제를 알고 있습니까?

답변

0

문제가 해결되었습니다.

문제는 링커와 관련이 없으며 훨씬 간단합니다.

dlopen() 호출에 RTLD_GLOBAL을 추가하여 해결했습니다. 그것은 내 우분투 설치 표준 gcc는 기본적으로 이것을 설정하고 암 타겟에 대한 컴파일러는 기본적으로 RTLD_LOCAL을 사용하는 것으로 보인다.