开发者

Uncatchable C++ exceptions (Shared libs, arm-linux-gnueabi-g++)

开发者 https://www.devze.com 2023-03-29 01:18 出处:网络
I\'m facing a strange problem related to exceptions thrown across DSO boundaries. When the code is compiled for embedded linux board with arm-none-linux-gnueabi-g++, the exceptions can\'t be caught, i

I'm facing a strange problem related to exceptions thrown across DSO boundaries. When the code is compiled for embedded linux board with arm-none-linux-gnueabi-g++, the exceptions can't be caught, if compiled with normal gcc compiler from ubuntu everything works fine :(

To clarify:

We have three components:

one Executeable file, which loads DSOs via dlopen(), dlsym()..

one DSO file (libMod2.so), containing a class MOD2 which throws self defined EException (derived from std::runtime_error) when calling throwException()

one DSO file (libtest.so), containing a class MOD1 which get's a pointer to class MOD2 located and calls 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;
    }
}

The problem is now that the Exception couldn't be caught by the first exception handler on arm target.

I think the problem is produced when linking: A nm -Con the DSO show some differences when grepping for EException.

TARGET:

toterhaa@develop-TT:/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.0开发者_如何学JAVA6.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



toterhaa@develop-TT:/var/lib/tftpboot$ nm -C libtest.so | grep EEx
00009ef0 V typeinfo for EException
000017f4 V typeinfo name for EException

Ubuntu:

toterhaa@develop-TT:/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.

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

The DSO created with ubuntu gcc has a additional symbol DW.ref._ZTI10EException. I think the solution is to bring this symbol also into the arm-DSO, but how?

Does anybody know this problem?


Problem solved!

The problem is not linker related, it was simpler, much simpler.

I solved it by adding RTLD_GLOBAL to the dlopen() call. It seems that the standard gcc in my ubuntu installation sets this by default and the compiler for the arm target uses RTLD_LOCAL as default.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号