title: Understanding GCC 5's _GLIBCXX_USE_CXX11_ABI or the new ABI
body: <p><a href="https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html" rel="noreferrer">https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html</a></p>
  
  <p>I ran into crashing/valgrind issues with using std::string on GCC 5. The above link hints that there is a change in the ABI starting GCC 5.x. The new default ABI for libstd++ is C++11/14... which is not compatible with the older ABI.  There is a way to select the older ABI using a define.</p>
  
  <p>I am trying to understand what is the difference between the ABIs and haven't found details.   I'd like help understanding:</p>
  
  <ol>
  <li>What kind of issues with std::string need to be fixed to be compatible with the new ABI?  Are they copy-on-write related?</li>
  <li>Will those changes break it for older ABI?</li>
  <li>Any tips in getting _GLIBCXX_USE_CXX11_ABI to work?</li>
  </ol>
  
  <p>More details on the issue I ran into (<a href="https://github.com/YasserAsmi/jvar/issues/21" rel="noreferrer">https://github.com/YasserAsmi/jvar/issues/21</a>) The project worked fine in GCC 4.8 and Clang.  With GCC, the same code refuses to run:</p>
  
  <pre><code>x_misc(33112,0x7fff728c2000) malloc: *** error for object 0x7fd639c034cc:    pointer being freed was not allocated
  *** set a breakpoint in malloc_error_break to debug
  Abort trap: 6
  </code></pre>
  
  <p>And here is a partial Valgrind output:</p>
  
  <pre><code>==33027== Invalid read of size 1
  ==33027==    at 0x1006F78BA: _platform_memmove$VARIANT$Nehalem (in /usr/lib/system/libsystem_platform.dylib)
  ==33027==    by 0x100009388: jvar::Variant::toString[abi:cxx11]() const (in bin/ex_misc)
  ==33027==    by 0x1000023A7: bugreport() (in bin/ex_misc)
  ==33027==    by 0x1000133B8: main (in bin/ex_misc)
  </code></pre>
  
  <p>The project uses std::string and has some custom memory management. It is doing some non-typical but valid operations using placement new constructors etc.  I am trying to understand better what kind of code is effected by the API and how to fix it--a place to start.</p>