ABI
It is how the objects and types look to the compiler.
- Size, number and order of data members in a type.
- Size, number and order of virtual functions.
- Number and order of function parameters
- Function return types
Changing the return type
- https://godbolt.org/z/5e8K8h9GM
- Return type is not part of the name mangling, so if the header doesn’t match the binary things can go very wrong.
Changing the order of virtual functions
- https://godbolt.org/z/PbGfn8df4
- If you change the order of virtual functions the compiler will call the wrong one!
Changing the order of member variables
- https://godbolt.org/z/dW8YocG1Y
- Just like chnaging function order, the compiler would generate the wrong offset
Broken ABI
- Same words, different meaning
ABI stability advantages
- To prevent ABI brekage bugs, our compiler and standard library vendors have been giving us “ABI stability” from some time now.
- This is good in some ways
- A new C++ executable on OS with new compiler with knowledge that libraries built with old compiler will work.
ABI stability stuck
- Can never change the return type of the function
- Can never add/remove/reorder virtual functions
- Can never add/remove/reorder member variables
- Can never add/remove/reorder function parameters (but new overloads can be added)
ABI stability disadvantages
- Bug requires changing layout - cannot be fixed
- Cannot add/remove member variable
- Cannot change design
- The Day The Standard Library Died
- Microsoft C/C++ language conformance by Visual Studio version
Conclusions
- By refusing to break the ABI we are encouraging and enabling companies to use old, broken, insecure and unfixable code that was compiled with a buggy compiler!
- This only helps enforce the idea that C++ is an unsecure language!
- A silent ABI break is very dangerous, so this must be detectable at compile, link, or runtime
- Possible Solution: Provide a C wrapper