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.
    • 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 we ensure statically linked applications stay that way

August 31, 2023
Arjun Shankar
Related topics:
C, C#, C++GoLinux
Related products:
Red Hat Enterprise Linux

    While glibc's highly configurable name resolution and character set handling features offer an advantage when it comes to system configuration and installed content, there are limitations when it comes to statically linked applications. This article summarizes the current state, recent improvements, and plans for moving toward truly statically linked applications.

    Although dynamic linking has advantages, making it the default choice for situations where binary compatibility is guaranteed (i.e., many Red Hat Enterprise Linux components), static linking is still useful in many situations such as:

    • Application developers wanting to ensure that their binaries run on a wide range of operating system vendors and versions.
    • Container introspection tools injected via oc-inject might bring their own dependencies into the system via static linking to avoid depending on in-container libraries.
    • Languages such as Go might produce statically linked binaries by default.

    Statically linking against glibc

    Regardless of the use case, when you statically link an application, the reasonable expectation is that all dependencies are linked statically. When it comes to glibc, this is currently not the case due to several glibc features, such as:

    1. Name service switch (nsswitch)
    2. Character set handling and conversion (iconv)
    3. Thread cancellation (unwinder)
    4. Internationalized domain names (libidn2)
    5. Dynamic library loading from static code (dlopen)

    The first two features allow glibc to be highly configurable when it comes to name resolution and character set handling. There are several non-glibc name resolution services implemented in the form of NSS modules. For example, systemd provides a caching DNS resolver installed by default on Fedora. Along the same lines, while vendor plugins for character set handling are less common, glibc's fairly exhaustive list of character set converters can be shipped and installed separately, reducing system footprint.

    These features also come with a limitation related to statically linked applications. The application can potentially dynamically load (dlopen) NSS or iconv modules during execution, depending on system configuration and module availability. A documented fact which still goes against the principle of least surprise. In the case of Go, while it tries to generate statically linked binaries by default, linking against glibc for NSS ends up making "many Go programmes dynamically-linked, to the point that a lot of people think Go dynamically links by default / preference."

    Recent changes

    The GNU C library offers an --enable-static-nss configure time option that builds libc.a (i.e., statically linked glibc) in a way that NSS modules are statically linked. However, a relatively recent refactor of NSS code removed this feature. It was never enabled for Fedora’s or RHEL’s glibc-static package. Since the refactor, the DNS and files back-ends (the most frequently used) have been moved into glibc instead of being shipped as separate modules. This means that doing name lookups from /etc/hosts or /etc/passwd does not lead to an NSS module load as long as /etc/nsswitch.conf only lists the files and DNS database providers. This has left the --enable-static-nss configure option redundant. However, there is more to be done here.

    Iterating toward a solution

    While there are five subsystems in this problem area, I have picked two to begin the process of iterating toward a solution: NSS and iconv.

    The next step toward avoiding surprising NSS module loads in statically linked applications is to either bring back the functionality that --enable-static-nss provides or do even better by allowing configuring behavior at application build-time instead of distribution build-time and providing a way to completely suppress all dynamic loading, regardless of the contents of nsswitch.conf requiring it.

    I'm currently in the process of trying to solve this. I did some initial experimentation by trying to build a new statically linked library that contains copies of glibc internal functions involved in NSS module loading, but with the module loading disabled. The idea being that with the appropriate linker command line, this can be used to link the alternative (non module loading) versions of the NSS component instead of the default versions that call dlopen. Once I had an idea of the changes we are looking at, I started a conversation upstream.

    I am now working through the implementation details, starting with collecting NSS code scattered across the glibc source tree into one place. Once I am finished with that, I will start posting patches upstream and working toward consensus.

    Please stay tuned for my future article describing glibc's progress on supporting truly statically linked applications.

    Related Posts

    • Recent improvements to concurrent code in glibc

    • Improving math performance in glibc

    • Why we added restartable sequences support to glibc in RHEL 9

    • Upgrading the GNU C Library within Red Hat Enterprise Linux

    Recent Posts

    • Federated identity across the hybrid cloud using zero trust workload identity manager

    • Confidential virtual machine storage attack scenarios

    • Introducing virtualization platform autopilot

    • Integrate zero trust workload identity manager with Red Hat OpenShift GitOps

    • Best Practice Configuration and Tuning for Linux and Windows VMs

    What’s up next?

    This cheat sheet presents a collection of Linux commands and executables for developers who are using the Linux operating system in advanced programming scenarios.

    Get the cheat sheet
    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.