[cfe-dev] Current state of libcxx compatibility with libstdc++

Martin J. O'Riordan via cfe-dev cfe-dev at lists.llvm.org
Tue Aug 9 08:45:31 PDT 2016


It is usually not even possible to pass Standard C++ objects between libraries that have been built with different versions of the "same" implementation of Standard C++ libraries, as it is not at all unusual for the library implementator to refactor the implementation of the Standard types, with a substantial amount of the implementation residing in the headers.

The compilers themselves generally go to considerable lengths to ensure that the same code compiled with different versions of the compiler are binary compatible, but the C++ Standard Library headers usually break object compatibility because the code is "not" the same code.

I haven't checked recently (v3.8 to v3.9), but this is usually the case from one release of CLang's own LibC++ to another.

	MartinO

-----Original Message-----
From: cfe-dev [mailto:cfe-dev-bounces at lists.llvm.org] On Behalf Of David Chisnall via cfe-dev
Sent: 09 August 2016 16:26
To: Jonathan Roelofs <jonathan at codesourcery.com>
Cc: cfe-dev at lists.llvm.org
Subject: Re: [cfe-dev] Current state of libcxx compatibility with libstdc++

On 9 Aug 2016, at 14:53, Jonathan Roelofs via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> Yes.
> 
>> Is there any way we can work around this to link c++ programs 
>> compiled with libcxx against system libraries which are compiled with 
>> gcc?
> 
> "compiled with gcc" isn't the issue. The issue is that you have one set of objects *built against libstdc++* and you're trying to link them against another set *built against libcxx*. This can only work if your interface between them does not contain things from the standard library.
> 
> Let me re-iterate: it is ok to link against both standard libraries (their symbols won't collide). What's not going to work is to use the headers from one library against the binaries from the other.

More specifically:

- It is not likely to be okay to mix libsupc++ (typically statically linked with libstdc++) and libc++abi in the same process.  They declare the same symbols and stuff is likely to break in exciting ways due to the conflicts.  We solved this in FreeBSD by linking both libstdc++ and libc++ against libcxxrt.  Other Linux distros have solved it by linking libc++ to libstdc++.

- It is fine to mix libstdc++ and libc++ in the same program, but it is *not* fine to pass standard library objects across library boundaries between parts of the code that use libstdc++ and parts that use libc++.  You can not, for example, pass a std::string from a program using libc++ to a library using libc++.  Most of these will result in link failures, but there are some cases that will just cause exciting run-time failures when you either bypass the type system, expect dynamic_cast (or any_cast) to work, or throw standard library objects other than std::exception in between different parts of the code.

David

_______________________________________________
cfe-dev mailing list
cfe-dev at lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list