Skip to content

compiler-rt: enable build of libatomic#488265

Merged
alyssais merged 1 commit intoNixOS:masterfrom
tobim:push-sloqoxpwytsx
Mar 7, 2026
Merged

compiler-rt: enable build of libatomic#488265
alyssais merged 1 commit intoNixOS:masterfrom
tobim:push-sloqoxpwytsx

Conversation

@tobim
Copy link
Copy Markdown
Contributor

@tobim tobim commented Feb 8, 2026

continuation of #398520.

Additional changes:

  • Simplified the conditional logic around LLVM versions, as most of the old versions are no longer included in nixpkgs.

Credit goes to @mildsunrise.

Fixes: #311930

Tested with

nix-build -E '
let
  pkgs = import ./. {
    crossSystem = {
      system = builtins.currentSystem;
      useLLVM = true;
    };
  };
in
  pkgs.llvmPackages.compiler-rt
'

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

LLVM stdenvs lack a set of `__atomic_*` routines that compilers
sometimes rely on, making it impossible to build certain C programs in
them. The reason we lack these routines is that we're using neither
compiler-rt's implementation of them (which was disabled by default a
long time ago) nor gcc's implementation (libatomic). See NixOS#391740 for a
more detailed explanation and an example of program that cannot be built.

Since no particular preference was expressed as to which approach
should be used to solve this, I'm going with LLVM's implementation
and recommended setup, which seems to be used also in AIX, Fuchsia
and Apple platforms. This consists of enabling a CMake flag,
`COMPILER_RT_BUILD_STANDALONE_LIBATOMIC`, which causes the routines to
be built and shipped in a separate DSO (placing them in a DSO instead
of `builtins.a` is needed for correctness, as it ensures the lock
section is unique in memory).

As with the other builtins, I'm symlinking this DSO to `libatomic.so` so
that downstream packages don't need specific/complicated logic for LLVM.

Other details:
- For static platforms, since no dynamic linking is expected at all, it
  should be correct to ship the symbols in `builtins.a`.
  So, that's what I'm doing in those cases.
- Since v19, compiler-rt allows using pthread locks rather than ad-hoc
  ones for the atomic routines. Since this plays better with
  instrumentation, I'm enabling this whenever libc is available.
- It would be nice to put the DSO in a separate output / derivation, so
  that the rest of compiler-rt isn't pulled into the runtime closure,
  but it isn't high prio since compiler-rt doesn't pull in dependencies
  other than libc, libc++ and unwinder.

Fixes: NixOS#311930
@nixpkgs-ci nixpkgs-ci bot requested a review from a team February 8, 2026 09:55
@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related labels Feb 8, 2026
@mildsunrise
Copy link
Copy Markdown
Contributor

@RossComputerGuy PTAL, looks like the feedback in #398520 was addressed

@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Feb 9, 2026
@tobim
Copy link
Copy Markdown
Contributor Author

tobim commented Feb 19, 2026

@RossComputerGuy mind taking a look?

@tobim
Copy link
Copy Markdown
Contributor Author

tobim commented Mar 6, 2026

@NixOS/llvm can somebody take a look at this?

@alyssais alyssais added this pull request to the merge queue Mar 7, 2026
Merged via the queue into NixOS:master with commit b25485c Mar 7, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build failure: rustc on LLVM stdenv

3 participants