Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 257
Emanuele Avatar asked Jul 27 '12 06:07

Emanuele


People also ask

Are GCC and Clang ABI compatible?

clang, modulo bugs, is fully C++ ABI compatible with GCC (they both follow the intervendor Itanium ABI) on unix systems. Make sure you use the same standard library for all components because libstdc++ and libc++ are different implementations with completely different object layouts.

Is G ++ a Clang?

gcc and g++ are the traditional GNU compilers for C and C++ code. Recently, clang (and clang++) using LLVM has been gaining popularity as an alternative compiler.

Does Clang define __ GNUC __?

(GNU C is a language, GCC is a compiler for that language.Clang defines __GNUC__ / __GNUC_MINOR__ / __GNUC_PATCHLEVEL__ according to the version of gcc that it claims full compatibility with.

What ABI does GCC use?

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.


2 Answers

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).

like image 116
Michael Burr Avatar answered Sep 21 '22 05:09

Michael Burr


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.

like image 25
Arne Avatar answered Sep 20 '22 05:09

Arne