Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does changing the order of class private data members breaks ABI

I have a class with number of private data members (some of them static), accessed by virtual and non-virtual member functions. There's no inline functions and no friend classes.

class A
{
    int number;
    string str;
    static const int static_const_number;
    bool b;
public:
    A();
    virtual ~A();
public:
    // got virtual and non-virtual functions, working with these memebers
    virtual void func1();
    void func2();

    // no inline functions or friends
};

Does changing the order of private data members breaks ABI in this case?

class A
{
    string str;
    static const int static_const_number;
    int number; // <--   integer member moved here
    bool b;
    ...
};


Edit
The types are not changed, only the order of the members. No bit flags are used as well. The code is used as shared library, there's no static linking to this code. I'm on Linux and the compilers are gcc-3.4.3 and gcc-4.1

like image 735
Dmitry Yudakov Avatar asked May 31 '10 15:05

Dmitry Yudakov


People also ask

What breaks ABI compatibility?

ABI break happens when one binary, e.g. shared object, uses a different ABI when calling functions on another shared object. If both binaries are not ABI compatible, the interpretation of the bytes would be wrong.

What is ABI in GCC?

These details are defined as the compiler Application Binary Interface, or ABI. From GCC version 3 onwards the GNU C++ compiler uses an industry-standard C++ ABI, the Itanium C++ ABI. The GNU C++ compiler, g++, has a compiler command line option to switch between various different C++ ABIs.

What is ABI in c++?

As C++ evolved over the years, the Application Binary Interface (ABI) used by a compiler often needed changes to support new or evolving language features. Consequently, programmers were expected to recompile all their binaries with every new compiler release.


2 Answers

It might, yes, if for no other reason than that the size of A could be different due to differences in the location and number of padding bytes between the data members.

like image 91
James McNellis Avatar answered Sep 30 '22 10:09

James McNellis


According to KDE Policies/Binary Compatibility Issues With C++ you cannot do it without breaking binary compatibility. However, as their disclaimer states, some of the advices they give in "you cannot..." part are compiler dependent, so you might get away with that change (although it's not very likely).

like image 31
chalup Avatar answered Sep 30 '22 11:09

chalup