Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • View All Red Hat Products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat Developer Sandbox

      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Secure Development & Architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • Product Documentation
    • API Catalog
    • Legacy Documentation
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

GCC5 and the C++11 ABI

February 5, 2015
Jason Merrill
Related topics:
Linux
Related products:
Red Hat Enterprise Linux

Share:

    The GNU C++ team works hard to avoid breaking ABI compatibility between releases, including between different -std= modes. But some new complexity requirements in the C++11 standard require ABI changes to several standard library classes to satisfy, most notably to std::basic_string and std::list. And since std::basic_string is used widely, much of the standard library is affected.

    Many users routinely rebuild all their code when they change compilers; such users will be unaffected by this change. Code built with an earlier compiler will also continue to work with the new libstdc++, which provides both old and new ABIs.

    Users that depend on third-party libraries or plugin interfaces that still use the old ABI can build their code with -D_GLIBCXX_USE_CXX11_ABI=0 and everything should work fine. In most cases, it will be obvious when this flag is needed because of errors from the linker complaining about unresolved symbols involving "__cxx11".

    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.  If they want to provide coexistence, they need to understand how to handle the change.

    The last time G++ went through an ABI change, back in the 3.x period, we changed the soname of libstdc++, which was widely regarded as a mistake. Changing the soname caused a lot of pain but is not sufficient to deal with changes in symbol ABIs: if you load multiple shared objects that depend on different versions of the library, you can still get clashes between different versions of the same symbol.

    So the plan for this ABI change has been to leave the soname (and the existing binary interface) alone, and express the new ABI using different mangled names.

    C++11 introduced inline namespaces, which are useful for changing the mangled name of a type or declaration without affecting its users. But inline namespaces only deal with ABI changes that are visible in the mangled name; for other ABI changes, such as changes to return type or non-static data members, we need to do something else.

    So we've introduced the notion of ABI "tags", to correspond to particular changes in the ABI of a type, function, or variable that would not otherwise be reflected in the mangled name. ABI tags become part of the mangled name, and thereby avoid the problem of two conflicting definitions of the same symbol. Tags are expressed via attribute abi_tag, which can be applied to an inline namespace, or directly to a declaration. So to allow the new ABI to coexist with the old ABI, a library such as libstdc++ needs to ensure that all the declarations with modified ABI are tagged appropriately.

    #ifdef ABI_CHANGE
    inline namespace abi2 __attribute ((abi_tag)) {
      class MyType { ... };
      MyType fn();
    }
    #endif

    Since C++ allows classes to be declared as incomplete before they are defined, we can't just automatically propagate tags from, e.g., base to derived class. The derived class needs to be explicitly tagged as well. To help with this, the compiler provides the -Wabi-tag flag, which warns about any declarations which involve a tagged type but don't have that tag themselves.

    // warning: Derived does not have the abi2 tag
    struct Derived: MyType { ... };

    It is recommended to use inline namespaces for tags when possible, but that obviously won't work for non-namespace-scope declarations such as member functions.  If there is an ABI change to a member function that is not reflected in the mangled name, then you can apply a tag to it directly.  For instance, the return type of complex::real changed in C++11:

    #if __cplusplus >= 201103L
          __attribute ((abi_tag ("cxx11")))
          constexpr _Tp real() const { return _M_real; }
    #else
          _Tp& real() { return _M_real; }
    #endif

    The libabigail (https://sourceware.org/libabigail/) tools are also useful for testing whether there are any ABI changes in existing symbols between versions of your library.

    Again, only providers of libraries and the like need to think about these complexities, and then only if they want to provide backward compatibility.  Users just need to make sure that they are building with the ABI used by the libraries that they depend on.


    Red Hat Enterprise Linux 7 ships with GCC 4. You can easily install the latest stable version of GCC using yum. As of May 2018, GCC 7.3 was shipped as part of Red Hat Developer Toolset (DTS).

    Last updated: August 31, 2018

    Recent Posts

    • Migrating Ansible Automation Platform 2.4 to 2.5

    • Multicluster resiliency with global load balancing and mesh federation

    • Simplify local prototyping with Camel JBang infrastructure

    • Smart deployments at scale: Leveraging ApplicationSets and Helm with cluster labels in Red Hat Advanced Cluster Management for Kubernetes

    • How to verify container signatures in disconnected OpenShift

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue