Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

How the GNU C Library handles backward compatibility

August 1, 2019
DJ Delorie
Related topics:
Developer toolsC, C#, C++
Related products:
Developer Toolset

    One of the GNU C Library's (glibc's) unwritten rules is that a program built against an old version of glibc will continue to work against newer versions of glibc. But how does this work? What hidden magic lets you call the same function with different results, just based on when you built your program?

    Add magical symbols

    This magic is called "compat symbols," which lets glibc and the static linker (the one used at build time) select from one of many implementations of a function. For example, if we look at the 32-bit libc-2.29.so's dynamic symbol table, we see three versions of the glob64 function (in 2017, the glob function was changed to handle dangling symlinks differently, which would cause older programs to crash, but that's a different story):

    $ readelf --dyn-syms -W /lib/libc-2.29.so | grep glob64
       411: 0012d0e0  7183 FUNC    GLOBAL DEFAULT   14 glob64@GLIBC_2.1
       412: 0012edb0  7183 FUNC    GLOBAL DEFAULT   14 glob64@GLIBC_2.2
       413: 000b69a0  7183 FUNC    GLOBAL DEFAULT   14 glob64@@GLIBC_2.27
    

    In your program, you only refer to glob64(). The dynamic linker (the one invoked to start your program) searches for a symbol that starts with glob64 followed by @@ and something else. The @@ tells the dynamic linker that this version is the default version. In this case, the dynamic linker finds glob64@@GLIBC_2.27, because that application binary interface (ABI) last changed in glibc 2.27. The linker replaces @@ with @ to make glob64@GLIBC_2.27, which is stored in your program's dynamic symbol table.

    If the dynamic linker doesn't find any @@ symbols, it looks for an unversioned symbol, as usual.

    Next, when your program runs the dynamic linker and sees the version numbers on all symbols, it links to the correspondingly versioned symbol, because the names now match. The only exception here is that the current version of each symbol still has @@ in the shared object, which is matched against @ in your program:

    $ readelf --dyn-syms -W myprog.x | grep glob64
         2: 00000000     0 FUNC    GLOBAL DEFAULT  UND glob64@GLIBC_2.27 (2)
    

    Now consider the case where we've built a program against version 2.26 of the C library. In that case, glibc's dynamic symbol table has something like this when you link against it:

       411: 0012d0e0  7183 FUNC    GLOBAL DEFAULT   14 glob64@GLIBC_2.1
       412: 0012edb0  7183 FUNC    GLOBAL DEFAULT   14 glob64@@GLIBC_2.2
    

    Your program would select the GLIBC_2.2 version as the "latest" symbol, and would add glob64@GLIBC_2.2 in its dynamic symbol table.

    If you run that build on a system with glibc 2.27, the dynamic linker sees that you've built against version 2.2 of that symbol, and links you to version 2.2 despite there being a newer version available.

    Change your ABI with compatibility

    Let us say you wanted to do something similar in your own library. Consider this example code:

    int lookup (int index)
    {
     . . .
    }
    

    After a few releases, you realize you want to pass a pointer to the thing you want to look up:

    int lookup (int index, void *data)
    {
     . . .
    }
    

    You can't have two copies of the same function in your library. You don't want to change the name of the function, so you write something like this:

    __asm__(".symver lookup_v2, lookup@@v2");
    int lookup_v2 (int index, void *data)
    {
     . . .
    }
    
    __asm__(".symver lookup_v1, lookup@");
    int lookup_v1 (int index)
    {
     . . .
    }
    

    We now have two differently named functions. The original code is now lookup_v1 and is set to version @, which means "no version tag, but not the default version." The dynamic symbol table has an entry lookup for this symbol, which is what your older binaries expect.

    The new function lookup_v2 is set to version @@v2, where the @@ means it is the default for any newly-linked programs. If you link a program against the new library, an entry lookup@v2 (note one @) is added to its dynamic symbol table.

    The last step here is to tell the static linker what versions you're using and what internal names to hide, using a version file like this one, which we will call mylib.vers:

    v1 {
      local: lookup_v1;
    };
    
    v2 {
      local: lookup_v2;
    };
    

    You specify this version file to the static linker with the --version-script option, like this:

      gcc . . . -Wl,--version-script,mylib.vers
    

    Note the v1 and v2 clauses corresponding to the versions we're using. We also use the local command to "hide" our internal names for the functions that implement older versions. This practice makes the (for example) lookup_v2 symbol local in scope to your library, and not visible outside it.

    Plan ahead

    In the case of glibc, versioning was used from the beginning. You can do this, too, if you add a wildcard version to your version script, like this:

    v1 {
      *;
    };
    

    This code sets the version for all of your symbols that don't already have a specific version to v1. Of course, you only want to do this before your first release, because versioning your symbols is itself an ABI change. Then, as you develop future versions of your library, you add more version clauses and list new symbols in those new clauses.

    Understand compatibility's limits

    Despite the long history of compatibility and its almost magical ability to keep old programs running, there is one scenario that compatibility can't solve. You can't run a new program on an old glibc. Well, that's not exactly true. You can build a new program that's intended to run on an old glibc if you have a copy of that old glibc and its headers around. The easiest way to do that is to install an older operating system that has the version of glibc you want, which is the typical advice of "build on the oldest platform you want to support," possibly using a more modern toolset (gcc et al.), such as Red Hat's Developer Toolset, which was created for this purpose. That way, the new program depends only on compatibility symbols that are available in that old glibc and any newer glibc. Older glibcs cannot, of course, know the future.

    Unless you can predict the future, in which case, please already have contacted me.

    Know your nits, picks, and caveats

    As this is a short article, a lot of details are glossed over. For example, the @@ syntax is merely a user-visible version of the executable and linkable format (ELF) structure's internals, which is beyond the scope of this piece.

    Although it's possible for your program to link against two dynamically shared objects (DSOs) that use two different versions of the same symbol (i.e., those two DSOs were built against different glibc versions), such a situation is not supported. The glibc developers do their best to make it work anyway, but if it breaks, you get to keep both pieces.

    Similarly, using dlsym to look up symbols in glibc (or any other versioned DSO) can result in using a different version of the symbol than other DSOs you use, with the same caveats.

    Learn more

    Here are additional materials that may interest you:

    • ld's VERSION command
    • glibc wiki: Symbol Versioning
    • "How To Write Shared Libraries" by Ulrich Drepper, Dec. 2011
    Last updated: July 29, 2019

    Recent Posts

    • Trusted software factory: Building trust in the agentic AI era

    • Build a zero trust AI pipeline with OpenShift and RHEL CVMs

    • Red Hat Hardened Images: Top 5 benefits for software developers

    • How EvalHub manages two-layer Kubernetes control planes

    • Tekton joins the CNCF as an incubating project

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    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
    © 2026 Red Hat

    Red Hat legal and privacy links

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

    Chat Support

    Please log in with your Red Hat account to access chat support.