C ++ binary compatibility

Source: Internet
Author: User

Do not disturb the terms summarized during study and work ~

Since the Standards Committee has never had a uniform standard C ++ ABI, various vendors have their own systems. To avoid accidents, it is also necessary to follow the rules, but you can consider it as appropriate, think twice.


Yes:
1. You can add non-virtual functions.
2. You can add enum to class.
3. You can append an enum value to an existing enum.
4. Remove private delimiters that are not called or used by inline functions and are not virtual functions.
5. You can add static data members.
6. Add a new class
7. Change the default function parameters.
8. Change the friend modifier of the class.


No:
1. The existing class cannot be export or unexport
2. Change the class inheritance relationship
3. Change template parameters
4. Changed the unexport, remove, inline, and overload of fucntion.
5. Change the function signature.
6. Add a virtual function to a class without any virtual members.
7. Change the sequence of virtual functions
8. Reload the existing virtual function
9. For non-private static members or non-static and non-member public data, you cannot set unexport, change type, or change CV-qualifiers.

 

For future class Extension
1. Pimpl
2. Add non-inline virtual destructor
3. All contructors non-inline


C ++ ABI
1. Memory layout of Objects
2. Call the virtual function, usually vptr/vtbl, and then use vtbl [offset] to call it.
3. name mangling (name rename)
4. RTTI and exception
5. Call conventions (parameter transfer method)


Compatible with source code but not binary
1. Add default parameters to the Function
2. Adding a virtual function will change the arrangement of vtbl (this class may have been inherited if a problem is added at the end)
3. added the default template parameter type and changed the name mangling.
4. Change the existing enum value.
5. increase the size of the class data member, resulting in a larger sizeof.


Security Practices
1. Add class
2. added the non-virtual member function.
3. Modify the data member name. the binary code is accessed by offset.
4 ....


Solution
1. Static Link
2. Dynamic library version management to Control Compatibility
3. PIMPL, exposed non-0000ua; interface of the header file, and fixed class size

In addition, the ideas and practices of COM have their historical limitations, but they are also quite complete, but I do not recommend them.


From chenyu2202863

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.