Exceptions across binary boundary

前端 未结 5 1271
生来不讨喜
生来不讨喜 2021-02-07 02:06

I know, this question has been asked quite some times, however I can\'t find a solution for my problem.

I have the following situation:

   A
  / \\
 /            


        
相关标签:
5条回答
  • 2021-02-07 02:47

    I had similar problems with gcc < 4.5 with RTTI symbols used across shared library boundaries, but not with gcc 4.6. However, you might still find the following information useful.

    As already mentioned, the vtable (containing an entry to the typeinfo object) for EException seems to be duplicated in some translation units which was definitely a problem with gcc < 4.5 (well, it is an issue of libsupc++, as far as I know, not merging the type_info objects). Anchoring the vtable of EException by defining a virtual out-of-line destructor (it must be the first virtual function declaration in the header) in A did the trick for me.

    Posting the complete header file for EException might also be helpful.

    0 讨论(0)
  • 2021-02-07 02:50

    You may try to compile A, B and C with -rdynamic (at linkage stage)

    The GCC man page tell about -rdynamic:

    Pass the flag -export-dynamic to the ELF linker, on targets that support it. This instructs the linker to add all symbols, not only used ones, to the dynamic symbol table. This option is needed for some uses of "dlopen" or to allow obtaining backtraces from within a program.

    0 讨论(0)
  • 2021-02-07 02:55

    Check for

    -fvisibility=hidden

    option in your linker settings. If it set, change it to

    -fvisibility=default

    0 讨论(0)
  • 2021-02-07 03:00

    B is using it's own EException class definition V typeinfo for EException whereas C seems to use an Unresolved one ( the U means the type is undefined in the current translation unit and must be resolved by the loader and dynamic linker ).

    Verify that B is still a shared library and it is not linked statically whith A but dynamicaly, preventing C from findind A's stuffs, cause as I cant see B won't link the same type as A. Take care of your header ^^.

    0 讨论(0)
  • 2021-02-07 03:06

    IMHO, this as nothing to do with the compiler flags whatsoever.

    Declare your exception object as extern and don't provide any implementation anywhere except in your main binary.

    This will force the linker (dynamic linker BTW) to use the only implementation that's possible.

    No typeinfo is generated on extern definition only.

    0 讨论(0)
提交回复
热议问题