How to provide coexisting std::string's (with and without abi:cxx11) in GCC 5.1 and above?

Jeffrey Walton noloader@gmail.com
Thu Mar 24 11:25:00 GMT 2016


On Thu, Mar 24, 2016 at 6:54 AM, Markus Trippelsdorf
<markus@trippelsdorf.de> wrote:
> On 2016.03.24 at 06:50 -0400, Jeffrey Walton wrote:
>> We caught a report due to _GLIBCXX_USE_CXX11_ABI and abi:cxx11. We are
>> upstream, and it appears Debian built the library using GCC and
>> _GLIBCXX_USE_CXX11_ABI was in effect. A user then came along with
>> Clanf and compiled the userland program. The link failed. This is
>> expected given our understanding of the landscape.
>>
>> We found "GCC5 and the C++11 ABI",
>> https://developerblog.redhat.com/2015/02/05/gcc5-and-the-c11-abi/. The
>> pages says:
>>
>>     Providers of such libraries or interfaces need to consider
>>     whether they want to provide ABI coexistence, like libstdc++
>>     does, or require their users to rebuild.
>>
>> I read the Red Hat blog post, but its not clear to me how to
>> accomplish the coexistence. That is, I want to ensure the library that
>> Debian builds has a symbol in both namespace so linking can occur with
>> either GCC or Clang and "things just work" for the user.
>>
>> How is libstdc++ providing symbols in both namespaces? How do I ensure
>> the symbol is present in both namesspaces so "things just work" for a
>> user?
>
> It will not work until this clang bug gets fixed:
> https://llvm.org/bugs/show_bug.cgi?id=23529

Thanks Markus.

Please forgive my ignorance... What is the "coexistence" that is
discussed? Naively, I thought it would have been something like this
contrived example:

  $ cat test.cxx
  #include <string>

  std::string foo __attribute__ ((visibility ("default")));
  std::string bar __attribute__ ((visibility ("default")));

  $ g++ -g3 -O2 -shared test.cxx -o test.so

  $ nm test.so | grep _Z3
  ...
  0000201c B _Z3barB5cxx11
  00002034 B _Z3fooB5cxx11

  $ echo _Z3fooB5cxx11 _Z3barB5cxx11 | c++filt
  foo[abi:cxx11]  bar[abi:cxx11]
  foo  bar

In the above contrived example, foo and bar are in both namespaces.
That is, the symbol coexists and "things just work".

Jeff



More information about the Gcc-help mailing list