Skip to content

LLVM platform stdenvs lack __atomic_* routines #391740

@mildsunrise

Description

@mildsunrise

In certain occasions, both gcc and LLVM emit libcalls to a set of equivalent __atomic_* routines.

  • gcc implements these routines in its libatomic module, which programs are expected to link explicitly (-latomic)
  • LLVM implements these routines in compiler-rt, but the routines are not built by default

This means specifying useLLVM = true; for a platform yields an stdenv that does not provide these routines anywhere, making it impossible to build certain programs. Trivial example:

let
pkgs = import <nixpkgs> {
  crossSystem = {
    config = "x86_64-unknown-linux-gnu";
    useLLVM = true;
  };
};
source = pkgs.writeText "test.c" ''
  int main() { __int128 src, dst; __atomic_load(&src, &dst, __ATOMIC_SEQ_CST); }
'';
in pkgs.runCommandCC "test" {} ''
  source $stdenv/setup
  $CC ${source} -o $out
''

I'm not sure how we should fix that. Since the set of routines should coincide, perhaps after #132340 we could try using gcc's libatomic in LLVM stdenvs. Assuming we want to use compiler-rt's implementation (which btw does not depend on pthreads), their recommended setup seems to be shipping those symbols in a shared library (which I presume would be named libatomic.so to match gcc's requirements on user builds). But from feedback I got, I think we do not plan on shipping these symbols in a separate library and would instead like to ship them in builtins.a? I'm not sure and this is the first thing I'd like to understand before attempting to fix anything.

Metadata

Metadata

Assignees

No one assigned

    Labels

    2.status: stalehttps://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md6.topic: llvm/clangIssues related to llvmPackages, clangStdenv and related6.topic: stdenvStandard environment
    No fields configured for issues without a type.

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions