NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.98k stars 13.99k forks source link

glibc.static breaks gcc #59267

Open Lassulus opened 5 years ago

Lassulus commented 5 years ago

Issue description

having glibc.static in buildInputs produces broken binaries if gcc is called without -static calling the binary results in a segfault:

segmentation fault  /nix/store/bdgyzm53lbslwfx4q41n3wni3m63hlij-test

Steps to reproduce

{ pkgs }: let

  hello_c = pkgs.writeText "hello.c" ''
    int main() {
      return 0;
    }
  '';

in pkgs.stdenv.mkDerivation {
  name = "test";
  buildInputs = with pkgs; [ glibc.static gcc ];
  phases = [ "buildPhase" ];
  buildPhase = ''
    gcc ${hello_c} -o $out
    $out
  '';
}

Technical details

matthewbauer commented 5 years ago

I suspect it's some bogus linker script. For instance this works fine:

{ pkgs }: let

  hello_c = pkgs.writeText "hello.c" ''
    int main() {
      return 0;
    }
  '';

in pkgs.stdenv.mkDerivation {
  name = "test";
  buildInputs = with pkgs; [ glibc glibc.static ];
  phases = [ "buildPhase" ];
  buildPhase = ''
    gcc ${hello_c} -o $out
  '';
}
stale[bot] commented 4 years ago

Thank you for your contributions.

This has been automatically marked as stale because it has had no activity for 180 days.

If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.

Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse.
  3. Ask on the #nixos channel on irc.freenode.net.
Guekka commented 1 year ago

Hello, Almost three years later, I've encountered this issue. Here's one small additional detail: I noticed the above derivation works, but it doesn't if we swap glibc and glibc.static like so


in pkgs.stdenv.mkDerivation {
  // ...
  buildInputs = with pkgs; [ glibc.static glibc ];
  // ...
}```

Since it is recommended by the bot, I'm pinging @edolstra  and @Ma27
AleXoundOS commented 1 year ago

@Guekka, I'm afraid the "ping" didn't work, because it's inside the code section :)

Guekka commented 1 year ago

@Guekka, I'm afraid the "ping" didn't work, because it's inside the code section :)

Oh, good catch. Thanks! Moving it here:

Since it is recommended by the bot, I'm pinging @edolstra and @Ma27

kubkon commented 1 year ago

I have encountered the same issue while working on TLS general dynamic model in Zig's zld linker. It seems that with glibc.static the linker ends up receiving both static and dynamic version of glibc resulting in link errors (if you're lucky), or worse, in loader errors.

Zzorz commented 4 months ago

Same issue here. The difference between [ glibc.static glibc ] and [glibc glibc.static] cause the order of -L/nix/store/*/lib reversed. It's euqal to below:

$ gcc check.c -o check -L/nix/store/{glibc_path}/lib -L/nix/store/${glibc_static_path}/lib

$ ./check
$ gcc check.c -o check -L/nix/store/${glibc_static_path}/lib -L/nix/store/{glibc_path}/lib

$ ./check
[1]    847400 segmentation fault  ./check

However, same error occur when I just leave glibc.static alone,:

$ gcc check.c -o check -L/nix/store/${glibc_static_path}/lib

$ ./check
[1]    847559 segmentation fault  ./check