Skip to content

Building static-linux-musl binary with clang: gcc_eh library not found #177129

@avdv

Description

@avdv

Describe the bug

After upgrading nixpkgs to 22.05 from 21.11, trying to build a simple hello world C program, using the pkgsStatic.llvmPackages_11.stdenv or pkgsStatic.llvmPackages.stdenv or pkgsStatic.clangStdenv results in

/nix/store/fnw7g7s8z6wmaank060jpqppl0hiqbal-x86_64-unknown-linux-musl-binutils-2.38/bin/x86_64-unknown-linux-musl-ld: cannot find -lgcc_eh: No such file or directory
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)

Steps To Reproduce

Steps to reproduce the behavior:

  1. flake.nix:
    {
      inputs.nixpkgs.url = "nixpkgs/nixos-22.05";
    
      outputs = { nixpkgs, ... }:
        let
          system = "x86_64-linux";
          pkgs = import nixpkgs { inherit system; };
          pkgsStatic = pkgs.pkgsStatic;
          stdenvStatic = pkgsStatic.llvmPackages.stdenv;
          # also tried:
          # stdenvStatic = pkgsStatic.clangStdenv;
        in
        {
          packages.${system}.default = stdenvStatic.mkDerivation {
            name = "hello";
            src = ./.;
            unpackPhase = ''
              cat > hello.c <<"EOF"
              #include <stdio.h>
              int main() {
                printf("hello, world\n");
              }
              EOF
            '';
            buildPhase = "$CC -o hello hello.c";
            installPhase = "install -D -t $out/bin hello";
          };
        };
    }
  2. nix build .
    $ nix build .
    error: builder for '/nix/store/pgk2n1vcmy4gjkqycbqs1wblmjmwhwpz-hello-x86_64-unknown-linux-musl.drv' failed with exit code 1;
           last 9 log lines:
           > unpacking sources
           > patching sources
           > updateAutotoolsGnuConfigScriptsPhase
           > configuring
           > no configure script, doing nothing
           > building
           > clang-11: warning: argument unused during compilation: '-pie' [-Wunused-command-line-argument]
           > /nix/store/fnw7g7s8z6wmaank060jpqppl0hiqbal-x86_64-unknown-linux-musl-binutils-2.38/bin/x86_64-unknown-linux-musl-ld: cannot find -lgcc_eh: No such file or directory
           > clang-11: error: linker command failed with exit code 1 (use -v to see invocation)
           For full logs, run 'nix log /nix/store/pgk2n1vcmy4gjkqycbqs1wblmjmwhwpz-hello-x86_64-unknown-linux-musl.drv'.

Expected behavior

I am able to build a static executable, based on musl, with clang.

Additional context

It seems like the gcc_eh.a library is indeed missing:

ls /nix/store/d41dvnv1rir038hxx8k8xf57icrfz7l4-x86_64-unknown-linux-musl-stage-final-gcc-11.3.0/lib64/gcc/x86_64-unknown-linux-musl/11.3.0/*.a
   libgcc.a    libgcov.a

Removing the -lgcc_eh option from the linker flags and manually running the resulting command produces a valid executable. (but I suppose this only works since I am not using exceptions ?)

Notify maintainers

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 5.15.43, NixOS, 22.05 (Quokka)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.8.1`
 - channels(root): `"nixos-21.11.336538.64fc73bd74f, nixos-hardware"`
 - channels(claudio): `"nixos-21.11.334139.1bd4bbd49be"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

Note, I am using nix flake to configure my system:

$ nix flake info
Resolved URL:  git+file:///home/claudio/src/nix-config
Locked URL:    git+file:///home/claudio/src/nix-config
Description:   NixOS and Home Manager config
Path:          /nix/store/sy3hlsffnh0mcbx6f597yj9pmcwa70fk-source
Last modified: 2022-06-06 22:44:21
Inputs:
├───flake-compat: github:edolstra/flake-compat/b7547d3eed6f32d06102ead8991ec52ab0a4f1a7
├───flake-utils: github:numtide/flake-utils/3cecb5b042f7f209c56ffd8371b2711a290ec797
├───home-manager: github:nix-community/home-manager/a8d00f5c038cf7ec54e7dac9c57b171c1217f008
│   └───nixpkgs follows input 'nixpkgs'
├───nixos-hardware: github:NixOS/nixos-hardware/816a935bf5aa5f77cb1f03ebfe20ab13b112d0f1
└───nixpkgs: github:NixOS/nixpkgs/d9794b04bffb468b886c553557489977ae5f4c65

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bugSomething is broken2.status: stalehttps://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md6.topic: llvm/clangIssues related to llvmPackages, clangStdenv and related6.topic: muslRunning or building packages with musl libc6.topic: staticStatic builds (e.g. pkgsStatic)
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions