Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ARM cross-compiling, segmentation fault on multiple inheritance

I have a C++ application using multiple inheritance and polymorphism. It works correctly on x86_64-linux but on arm-linux I'm experiencing a segmentation fault.

I've written a simple test to re-create 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 fault when calling list_clone.size() because the copied list have an incorrect tail pointer.

I have tried with gcc 4.8.3 and 4.9.1 but I've seen the same behavior. The target architecture is ARM cortex-A processors with hard floating point.

Any idea?

Actually I have find two independent ways to make it work:

  1. by removing the SmartObject destructor, but this is not feasible on the overall application.
  2. by declaring MyObject in this way (virtual on SmartObject and order inverted):

class MyObject : public virtual IMyInterface, public virtual SmartObject

Thanks in advance

like image 826
ingram Avatar asked Nov 09 '22 10:11

ingram


1 Answers

It's a bug of gcc 4.9.X on ARM targets. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66666-

like image 72
ingram Avatar answered Nov 15 '22 05:11

ingram