ARM cross-compilation, segmentation error with multiple inheritance

I have a C ++ application using multiple inheritance and polymorphism. It works correctly on x86_64-linux, but in arm-linux I experience a segmentation error.

I wrote a simple test to recreate the problem:

#include <list> #include <iostream> class SmartObject { public: // removing this destructor makes it work in ANY way virtual ~SmartObject(){ } void method(void) {} }; class IMyInterface { public: // removing this destructor have no effect (fails) virtual ~IMyInterface(){ } virtual std::list<int> getList() = 0; }; class MyObject : public SmartObject, public virtual IMyInterface { public: MyObject() { list.push_back(4); list.push_back(5); } virtual std::list<int> getList() { return list; } std::list<int> list; }; int main() { IMyInterface * ip = new MyObject(); std::list<int> list_clone = ip->getList(); std::cout << list_clone.size() << std::endl; delete ip; return 0; } 

This code works correctly on x64-linux and win32 (also on other embedded platforms), but on arm-linux it causes a segmentation error when calling list_clone.size () because the copied list has an invalid pointer to a pointer.

I tried gcc 4.8.3 and 4.9.1, but I saw the same behavior. The target architecture is ARM cortex-A processors with a hard floating point.

Any idea?

In fact, I have two independent ways to make it work:

  • by removing the SmartObject destructor, but this is not a possible general application.
  • declaring MyObject this way (virtual on SmartObject and inverted order):

class MyObject : public virtual IMyInterface, public virtual SmartObject

Thank you in advance

+5
source share
2 answers

This is gcc 4.9.X bug for ARM purposes. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66666-

+2
source

You will also need a virtual destructor for the class MyObject . Otherwise, you cannot expect to properly destroy the MyObject instance using an IMyInterface .

-1
source

All Articles