Skip to content

Build against an older libc, keep the newest in the runtime closure #303405

Open

Description

@SomeoneSerge

Issue description

Libc and libstdc++ compatibility is a dominating factor in how severe is the effect of allowing impure dependencies such as OpenGL, OpenCL, Vulkan, or CUDA drivers. Ultimately, the heuristic is: build against the oldest library you can, load the most recent at runtime. This practice is widely followed in other distributions and is important e.g. for the "manywheel" standard in python packaging.

Currently, Nixpkgs pins a single fairly recent version of glibc and builds every package against that. A suggestion that has been at least occasionally voiced is to invest time in "making [OpenGL] binaries less demanding in regards to the glibc version"1.

Forgetting about maintenance costs for a moment, one can also see it would benefit downstream applications to start generally tracking each package's lowest compatible glibc - by building against it -, while ensuring that only one version - the newest - is ever referred to in runtime closures. For example, if such a mechanism were in place it would've been "trivial" to use Nix to create "manywheel" releases of python packages.

It would be (?) a reasonable starting point to implement an easy to use stdenvAdapters-like mechanism for separating the lib(std)c(++) used at build time from the one recorded in final RUNPATHs, LD_LIBRARY_PATHs, ld.so.cache-s, etc. We can test such mechanism by first applying it to our impure drivers

EDIT(2024-08-12): Apparently there's also the matter of which ld.so to use:

Details
❯ nix build github:NixOS/nixpkgs/nixos-23.05#hello -o hello2305                         
❯ nix build github:NixOS/nixpkgs/master#glibc.lib -o libc2411                            
❯ nix build github:NixOS/nixpkgs/master#glibc.out -o libc2411                            
❯ nix build github:NixOS/nixpkgs/master#hello -o hello2411                               
❯ nix build github:NixOS/nixpkgs/nixos-23.05#glibc.out -o libc2305
❯ LD_LIBRARY_PATH="$(readlink -f $PWD/libc2305/lib)" LD_DEBUG=libs ./hello2305/bin/hello # Expected success
...
Hello, world!
❯ LD_LIBRARY_PATH="$(readlink -f $PWD/libc2411/lib)" LD_DEBUG=libs ./hello2411/bin/hello # Expected success
...
Hello, world!
❯ LD_LIBRARY_PATH="$(readlink -f $PWD/libc2305/lib)" LD_DEBUG=libs ./hello2411/bin/hello # Expected failure
...
*** stack smashing detected ***: terminated
...
❯ LD_LIBRARY_PATH="$(readlink -f $PWD/libc2411/lib)" LD_DEBUG=libs ./hello2305/bin/hello # Unexpected failure
...
   2943758:     /nix/store/0wydilnf1c9vznywsvxqnaing4wraaxp-glibc-2.39-52/lib/libc.so.6: error: symbol lookup error: undefined symbol: __tunable_is_initialized, version GLIBC_PRIVATE (fatal)
./hello2305/bin/hello: symbol lookup error: /nix/store/0wydilnf1c9vznywsvxqnaing4wraaxp-glibc-2.39-52/lib/libc.so.6: undefined symbol: __tunable_is_initialized, version GLIBC_PRIVATE
❯ LD_LIBRARY_PATH="$(readlink -f $PWD/libc2411/lib)" LD_DEBUG=libs ./libc2411/lib/ld-linux-x86-64.so.2 "$(readlink -f ./hello2305/bin/hello)"
...
Hello, world!

Footnotes

  1. https://discourse.nixos.org/t/help-understanding-the-libgl-abi-problem-and-possible-solutions/42022/21 ↩

Activity

  1. added
    6.topic: architecture
    on Apr 11, 2024
  2. nixos-discourse commented on Apr 11, 2024

    @nixos-discourse
  3. changed the title [-]Provide a mechanism to build against an old glibc but link the newest in DT_RUNPATHs[/-] [+]Build against an older libc, keep the newest in the runtime closure[/+] on Apr 11, 2024
  4. added
    6.topic: cuda
    on Apr 11, 2024
  5. nixos-discourse commented on Apr 23, 2024

    @nixos-discourse
  6. nixos-discourse commented on Aug 12, 2024

    @nixos-discourse

    This issue has been mentioned on NixOS Discourse. There might be relevant details there:

    https://discourse.nixos.org/t/review-of-333575/50496/2

  7. kjeremy commented on Aug 21, 2024

    @kjeremy
  8. kjeremy commented on Aug 30, 2024

    @kjeremy
    Contributor

    @SomeoneSerge Is there a plan to do this or an outline of the steps needed? I am running into this issue building software against 22.05 (that I cannot easily upgrade) and running on 24.04.

  9. added
    2.status: stale
    on Jul 4, 2025
  10. de11n commented on Dec 28, 2025

    @de11n

    One option would be to use Zig as the C/C++ compiler. Zig supports targeting specific glibc versions. Zicross has some prior art.

  11. removed
    2.status: stale
    on Dec 28, 2025
  12. Atemu commented on Dec 31, 2025

    @Atemu
    Member

    Honestly, this should just be some sort of config option when linking against glibc.

    Just like Android's target and min SDK versions.

  13. de11n commented on Jan 2, 2026

    @de11n

    glibc doesn't support that, but Zig's toolchain has patches to glibc headers that enable it. It could be possible to use Zig's patched glibc headers directly without actually using Zig's toolchain. But that would be further off-the-beaten-path.

  14. added
    2.status: stale
    on Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    2.status: stale6.topic: architecture6.topic: cuda

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions