Repository navigation
fix(nix): drop GLIBC_ABI_GNU2_TLS so the builtin loads into a non-Nix bash - #1001
Merged
Merged
Conversation
nixpkgs' gcc defaults to -mtls-dialect=gnu2 on x86-64, so the linker stamps a GLIBC_ABI_GNU2_TLS version dependency (glibc >= 2.41) onto libflyline.so. Bash dlopen()s the builtin into a process that has already mapped a libc, so the host distro's glibc resolves our symbols regardless of RUNPATH and `enable -f` fails outright on anything older. Every other symbol version the library needs is <= GLIBC_2.39, so this marker is the only barrier. Only mimalloc's C thread-locals emit TLS relocations here and they do not need the gnu2 dialect. With -mtls-dialect=gnu the six R_X86_64_TLSDESC relocations disappear and the highest requirement drops to GLIBC_2.39. Add a postCheck assertion so the marker cannot silently return: the existing `enable -f` smoke test runs against nixpkgs' own bash, which has a new enough glibc to pass either way.
Owner
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On a non-NixOS Linux host, loading the flake-built library into the system Bash fails:
This is specific to flyline being a loadable builtin. Bash
dlopen()s it into a process that has already mapped a libc, so the host'slibc.so.6satisfies our symbols by soname — theRUNPATHpointing at nixpkgs' glibc never gets a say. The library therefore has to be loadable against the distro's glibc, not just the one it was built against. Anyone consuming this flake through Home Manager on Ubuntu/Mint/Debian hits this; NixOS users never do.Cause
nixpkgs' gcc defaults to
-mtls-dialect=gnu2on x86-64. Objects with TLS relocations then use TLSDESC, and the linker stamps aGLIBC_ABI_GNU2_TLSversion dependency onto the output. That version node only exists in glibc >= 2.41.In flyline the TLS relocations come from mimalloc's C thread-locals — the Rust side emits none. Six of them, all against local symbols:
And that marker is the only thing out of reach — every real symbol version the library needs is
<= GLIBC_2.39:So a single build flag is the whole difference between "loads on Ubuntu 24.04" and "doesn't load at all".
Fix
Set
NIX_CFLAGS_COMPILE = "-mtls-dialect=gnu"for x86-64 Linux. mimalloc has no need for the gnu2 dialect; the traditional dialect produces the same behaviour without the version dependency.Scoped narrowly on purpose:
-mtls-dialect=tradthere, no marker is emitted, and the flag spelling differs (trad/desc). Left alone.Regression guard
Added a
postCheckassertion that fails the build ifGLIBC_ABI_GNU2_TLSreappears. This is deliberate: the existingenable -fsmoke test runs against nixpkgs' ownbashInteractive, which has a new enough glibc and passes either way. A nixpkgs bump that changes gcc defaults, or a future C dependency that forces gnu2, would be completely invisible on NixOS and would only surface as a brokenenable -fon a user's distro. CI doesn't build the flake, so this check is the only automated backstop.Testing
nix build .#flylineon x86_64-linux, before and after:GLIBC_ABI_GNU2_TLSR_X86_64_TLSDESCrelocs in.rela.dynGLIBC_2.39postCheckassertion passes on the fixed build and fails on the pre-fix library, so it is a real guard rather than a no-op.enable -fsmoke test andcargoCheckHookunchanged and passing.nixfmtclean.__tls_get_addrinstead of TLSDESC — a marginally slower first access per thread-local, no behavioural difference. The crate is already built withlocal_dynamic_tls, which is the correct model for adlopen()ed library.Known limitation
This does not make the Nix build universally portable. The library still requires glibc >= 2.39 on the host, so it won't load into a Bash on an older distro. It only removes the artificial 2.41 floor, which was an accident of the build toolchain rather than a real requirement of the code.