Skip to content

fix(nix): drop GLIBC_ABI_GNU2_TLS so the builtin loads into a non-Nix bash - #1001

Merged
HalFrgrd merged 1 commit into
HalFrgrd:masterfrom
jakob1379:fix/nix-gnu2-tls
Sep 20, 2026
Merged

HalFrgrd merged 1 commit into
HalFrgrd:masterfrom
jakob1379:fix/nix-gnu2-tls

Conversation

@jakob1379

Copy link
Copy Markdown
Contributor

Problem

On a non-NixOS Linux host, loading the flake-built library into the system Bash fails:

bash: enable: cannot open shared object /nix/store/…-flyline-1.8.0/lib/libflyline.so:
/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_ABI_GNU2_TLS' not found
(required by /nix/store/…-flyline-1.8.0/lib/libflyline.so)

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's libc.so.6 satisfies our symbols by soname — the RUNPATH pointing 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=gnu2 on x86-64. Objects with TLS relocations then use TLSDESC, and the linker stamps a GLIBC_ABI_GNU2_TLS version 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:

# parsing .rela.dyn of the 1.8.0 store output
reloc type counts: {R_X86_64_RELATIVE: 10229, R_X86_64_TLSDESC: 6,
                    R_X86_64_GLOB_DAT: 192, R_X86_64_JUMP_SLOT: 17, ...}
TLSDESC relocs: 6   (all sym index 0)

And that marker is the only thing out of reach — every real symbol version the library needs is <= GLIBC_2.39:

$ readelf -V libflyline.so | grep -o 'GLIBC_[0-9A-Za-z_.]*' | sort -uV
GLIBC_2.2.5 … GLIBC_2.38  GLIBC_2.39  GLIBC_ABI_GNU2_TLS

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:

  • aarch64-linux — gcc defaults to -mtls-dialect=trad there, no marker is emitted, and the flag spelling differs (trad/desc). Left alone.
  • Darwin — unaffected, no ELF symbol versioning.

Regression guard

Added a postCheck assertion that fails the build if GLIBC_ABI_GNU2_TLS reappears. This is deliberate: the existing enable -f smoke test runs against nixpkgs' own bashInteractive, 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 broken enable -f on a user's distro. CI doesn't build the flake, so this check is the only automated backstop.

Testing

nix build .#flyline on x86_64-linux, before and after:

before after
GLIBC_ABI_GNU2_TLS present absent
R_X86_64_TLSDESC relocs in .rela.dyn 6 0
highest glibc version required 2.41 (the marker) GLIBC_2.39
  • The new postCheck assertion passes on the fixed build and fails on the pre-fix library, so it is a real guard rather than a no-op.
  • Existing enable -f smoke test and cargoCheckHook unchanged and passing.
  • nixfmt clean.
  • Only mimalloc's C compilation is affected; the traditional TLS dialect uses __tls_get_addr instead of TLSDESC — a marginally slower first access per thread-local, no behavioural difference. The crate is already built with local_dynamic_tls, which is the correct model for a dlopen()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.

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.
@HalFrgrd

Copy link
Copy Markdown
Owner

Thanks!

@HalFrgrd
HalFrgrd merged commit 82c7a6d into HalFrgrd:master Sep 20, 2026
@jakob1379
jakob1379 deleted the fix/nix-gnu2-tls branch September 20, 2026 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants