Is clang++ ABI same as g++? [duplicate]

2019-01-14 21:40发布

问题:

Possible Duplicate:
GCC 4.0, 4.2 and LLVM ABI Compatibility

As per subject, are both C++ ABIs compatible?
I.e. can a binary (Shared Object) generated with the former be used and linked with the latter (and vice-versa)?

Cheers

回答1:

According to the clang libc++ page, they're targeting

ABI compatibility with gcc's libstdc++ for some low-level features such as exception objects, rtti and memory allocation.

which seems to imply that they're not targeting 100% compatibility. For example, on that page they also say:

From years of experience (including having implemented the standard library before), we've learned many things about implementing the standard containers which require ABI breakage and fundamental changes to how they are implemented. For example, it is generally accepted that building std::string using the "short string optimization" instead of using Copy On Write (COW) is a superior approach for multicore machines (particularly in C++'0x, which has rvalue references). Breaking ABI compatibility with old versions of the library was determined to be critical to achieving the performance goals of libc++.

I believe that GCC is still using a reference-counted COW, so it appears that clang isn't worried about ABI compatibility with std::string (either with older clang compiled binaries or with GCC).



回答2:

It seems to be compatible. Clang also has a project for their own C++ runtime, and it states that it is low-level compatible with GNU stdlibc++. I just tried a small example program, where I compiled one file with clang++, and compiled and linked the main program and with g++. No problem so far, but the program was rather simple.