Sep 30, 2019

[C++] ABI compatibility

Reference:
https://www.acodersjourney.com/20-abi-breaking-changes/
https://community.kde.org/Policies/Binary_Compatibility_Issues_With_C%2B%2B
https://community.kde.org/Policies/Binary_Compatibility_Examples


Each of these items needless to memorize, it's listed for convenience.
All based on memory layout reasoning. (plus linking logics)


Break ABI changes:
  1. Un-export or remove a class from the shared library
  2. Un-export or remove a function or method from a class
  3. Change the signature of any method in the class. This includes
    Changing the return type
    Changing the order of parameters
    Change the access rights ( eg. public to protected)
    Removing or adding parameters
  4. Add, remove, or re-order member variables in a class
  5. Change the type of any member variable in a class
  6. Change the class hierarchy  of the class exposed in shared library:
    make the exposed class inherit from a different base class
    make the exposed class  inherit from additional base classes
    remove base class(es) from the exposed class
  7. Change the template arguments (add, remove, re-order) of a templated class
    In line with #3 above since changing the template arguments changes the underlying function signatures generated when the template is instantiated
  8. Inline a function in an exported class
    When a function is declared inlined, the compiler inlines it where the function is called and may not generate an out-of-line copy. The client binary, which was thus far depending on the exported out-of-line function signature cannot locate it and will fail in unexpected ways (crash most likely).
  9. Change the const or volatile qualifier of a member function
    Some compilers encode the const-ness of a function in the mangled name and hence changing the function from const to non-const changes the mangled name.
  10. Change the type of global data
  11. Changing the const or volatile qualifiers on global data
  12. Adding an explicit copy constructor or destructor to a class that would otherwise have implicit versions.
    Reference: https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html
  13. Changing a non-virtual method to be virtual, and vice versa.
  14. Adding a virtual method to a class with no existing virtual methods.
  15. Changing the order of virtual methods.
  16. Adding new virtual methods (some compilers may preserve binary compatibility if you only add new virtual methods after existing ones).
  17. Override a virtual that doesn't come from a primary base
  18. Remove a virtual function, even if it is a reimplementation of a virtual function from the base class
  19. Change the calling convention of an exported function ( from _stdcall to _cdecl and vice versa)
  20. If passing C++ types across shared library boundary, make sure that your client binary and shared library are compiled with the same version of the compiler.


ABI remains with these changes:
  1. Add new class to the shared library
  2. Add new free functions
  3. Add new non-virtual method to an existing class
  4. Add new static variables to a class
  5. Remove private static variable
    (if never referenced from an inline method)
  6. Remove non-virtual private method (if never called from an inline method)
  7. Change the implementation of an inline method
  8. Change an inline method to non-inline
  9. Adding new constructors to the class
  10. Add a new enum to a class
  11. Append new enum values to an existing enum class
  12. Change the default arguments of a method
  13. Add or remove friend declarations from a class
  14. Add new static data members
  15. Extend reserved bit fields, provided this doesn't cause the bit field to cross the boundary of its underlying type
    (8 bits for char & bool, 16 bits for short, 32 bits for int, etc.)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.