Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the Implications of using _GLIBCXX_CXX11_ABI to use pre-5.1 C++ ABI with C++ 11/14 features?

Tags:

c++

gcc

abi

From the manual:

In the GCC 5.1 release libstdc++ introduced a new library ABI that includes new implementations of std::string and std::list. These changes were necessary to conform to the 2011 C++ standard which forbids Copy-On-Write strings and requires lists to keep track of their size.

It is possible to use the _GLIBCXX_USE_CXX11_ABI macro to control whter the library headers use the old or the new ABI, independently of which "-std" is being used.

I'd like to know what the implications of using this "compatibility ABI" would be? I guess that the run-time performance of small-string operations will be impacted (negatively I assume), and that list-size access goes from O(1) (C11 ABI) to O(N) (compatibility ABI).

  1. Are my guesses correct and can anyone elaborate?
  2. Are there other implications which I have missed? What about atomics and concurrency features? Any impact?
like image 510
Spacemoose Avatar asked Dec 18 '15 08:12

Spacemoose


1 Answers

Your first question is actually answered by the manual itself:

... the choice of ABI to use is independent of the -std option used to compile your code... This ensures that the -std does not change the ABI, so that it is straightforward to link C++03 and C++11 code together.

Regarding the second question, I'm afraid it's hard to generalize the impact because it depends on how your code is using the standard library. Does it copy strings a lot? How often a list size is queried? Is the code multi-threaded?

Although atomics and concurrency were introduced in C++11's standard, I'd guess that stdlib++ copy-on-write mechanism already used a variation of it anyhow. Those implementations are typically thread-safe.

Perhaps one thing you didn't directly mention is the impact on other std components that depend on those behaviors, such as list::splice

like image 122
Leandro T. C. Melo Avatar answered Sep 18 '22 17:09

Leandro T. C. Melo