简体   繁体   English

在Linux编译中,dynamic_cast在“长距离”同级之间失败

[英]dynamic_cast fails between “long distance” siblings on linux compilation

There is a class DerivedClass which inherits from both BaseClassA and BaseClassB publicly. 有一个DerivedClass类,它公开地继承自BaseClassABaseClassB All classes have virtual functions to make sure the virtual table is built properly. 所有类都具有虚函数,以确保正确构建了虚拟表。

BaseClassA and BaseClassB are located in Library1 and DerivedClass is in Library2 . BaseClassABaseClassB位于Library1中DerivedClass位于Library2中

One function in Library1 retrieves a DerivedClass in the form of a BaseClassA pointer and tries to dynamic_cast to BaseClassB but it fails. Library1中的一个函数以BaseClassA指针的形式检索DerivedClass ,并尝试dynamic_cast到BaseClassB,但失败。 The same function works in different environments and compilers (visual studio for instance). 相同的功能可在不同的环境和编译器(例如Visual Studio)中工作。

Extra information: 额外的信息:

  • Reproduced with 4.1.2 and 4.5 gcc versions (read about the old gcc bug) 复制了4.1.2和4.5 gcc版本(了解旧的gcc错误)
  • Derived class name is "Match" (thought it may collide with other library? python?) 派生的类名称为“ Match”(认为可能与其他库相冲突?python?)
  • There are tens of libraries compiling one after the other while linking between them. 有数十个库在它们之间链接时一个接一个地编译。
  • nm -gC : Found the vtable address for Match nm -gC :找到匹配的vtable地址
  • gdb (7.0.1): used to check the vtable address for the class but couldn't understand much. gdb(7.0.1):用于检查该类的vtable地址,但不太了解。 (gdb version doesnt support "info vtbl". gdb can't show direct information about the class claiming it is a typedef) (gdb版本不支持“ info vtbl”。gdb无法显示声称是typedef的类的直接信息)
  • readelf -s : I saw the symbol readelf -s :我看到了符号

I figured it might be one of the following problems 我认为这可能是以下问题之一

  1. duplicated symbol 重复的符号
  2. HIDDEN symbol somewhere in the libraries linked 隐藏符号在链接的库中的某处
  3. Duplicated vtables 重复的vtable
  4. -E and RTLD_GLOBAL dlopen flag linker flag didn't work (the linking is made using the makefile linker stage and probably not the dlopen. -E和RTLD_GLOBAL dlopen标志链接器标志不起作用(链接是使用makefile链接器阶段进行的,可能不是dlopen。
  5. non-inline function manipulation (didnt work as well - but could be my mistake with understanding what exactly has to be done) 非内联函数操作 (也可以进行其他工作-但可能是我的错误,因为我理解必须执行的操作)

Been farming the web trying to find a solution. 一直在网上寻找解决方案。 But what I want to know first is What Is The Problem? 但是我首先要知道是什么问题? How can I focus on it? 我如何专注于它?

(5) looks promising even though I didnt manage to use it. (5)看起来很有希望,即使我没有设法使用它。

Any suggestions would be greatly appreciated (a solution would be great as well ;) ) 任何建议将不胜感激(一个解决方案也将很不错;))

Apparently #4 was the answer. 显然,答案是4。 The was a hidden feature that loads functions dynamically and had to be handles separately. 这是一个隐藏的功能,可以动态加载功能,并且必须分别进行处理。 Adding the -Wl,-E flags to the linking process and changing the loader flags did the trick. 在链接过程中添加-Wl,-E标志并更改加载程序标志就可以了。

What I want to know if there is any linuxy way of understanding this is the error. 我想知道是否有任何Linuxy方式来理解这是错误。

Something like "ldd" command or others (top, nm, readelf, etc) that I tried but couldn't see anything that pointed to this exact error. 我尝试过类似“ ldd”命令或其他命令(top,nm,readelf等),但看不到任何指向此确切错误的东西。

Thanks SOF for continuous help in various subjects 感谢SOF在各个主题上的不断帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM