Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking issue for GHC bootstrapping compilers being broken with musl in nixpkgs #99

Closed
talw opened this issue Jul 28, 2020 · 11 comments
Closed
Labels
help wanted Extra attention is needed

Comments

@talw
Copy link

talw commented Jul 28, 2020

First of all, a big thanks for all the work on this big project!

I am trying to build a project statically with GHC 8.8.3 and I get the following error:

/nix/store/nrdv3qhafvxnvbxqksahnffw47ymafh7-ghc-8.6.5-binary/lib/ghc-8.6.5/bin/ghc-pkg: /nix/store/pk12rld0n6g6k74s0c0j9wmr7glpfnrj-ncurses-6.2-abi5-compat/lib/libtinfo.so.5: no version information available (required by /nix/store/nrdv3qhafvxnvbxqksahnffw47ymafh7-ghc-8.6.5-binary/lib/ghc-8.6.5/bin/../terminfo-0.4.1.2/libHSterminfo-0.4.1.2-ghc8.6.5.so)
Inconsistency detected by ld.so: dl-lookup.c: 111: check_match: Assertion `version->filename == NULL || ! _dl_name_match_p (version->filename, map)' failed!
make[1]: *** [ghc.mk:991: install_packages] Error 127
make: *** [Makefile:51: install] Error 2
builder for '/nix/store/4xb1js32jx9a1iwa1b4l3zb5vqm81cvy-ghc-8.6.5-binary.drv' failed with exit code 2
cannot build derivation '/nix/store/jkjqd7fwgv18mqlm8zrpm95cz17h313a-ghc-8.8.3.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/p75l86x5qapq0grk7a3cj2lwi52db9qr-myProj-0.1.0.drv': 1 dependencies couldn't be built

The involved files are:

default.nix:

let
  compiler = "ghc883";

  pkgs = import ./nix/pkgs.nix compiler;

  static-haskell-nix = fetchGit (builtins.fromJSON (builtins.readFile ./nix/static-haskell-rev.json));
  static-pkgs = (import (static-haskell-nix + "/survey/default.nix") {
      pkgs = pkgs.pkgsMusl;
      inherit compiler;
      defaultCabalPackageVersionComingWithGhc = "Cabal_3_0_0_0";
    }).pkgs;

  haskPkgs = pkgs.haskell.packages.${compiler};

  gitignore = pkgs.nix-gitignore.gitignoreSourcePure [ ./.gitignore ];

  static-drv = static-pkgs.haskell.lib.overrideCabal
            (static-pkgs.haskell.packages.${compiler}.callPackage ./proj.nix {})
            (old: {
                  configureFlags = [
                    "-flambda"
                    "--ghc-option=-fPIC"
                    "--ghc-option=-optl-static"
                    "--ghc-option=-optc-static"
                    "--ghc-option=-optl-pthread"
                    "--ld-option=-static"
                    "--ld-option=-pthread"
                    "--extra-lib-dirs=${static-pkgs.gmp6.override { withStatic = true; }}/lib"
                    "--extra-lib-dirs=${static-pkgs.zlib.static}/lib"
                    "--extra-lib-dirs=${static-pkgs.libffi.overrideAttrs (old: { dontDisableStatic = true; })}/lib"
                    "--disable-executable-stripping"
                  ];
            });

in
  {
    inherit static-drv;
  }

proj.nix:

{ mkDerivation, aeson, amazonka, amazonka-core, amazonka-dynamodb
, amazonka-sqs, aws-lambda-haskell-runtime, base, bytestring
, composition, containers, either, generic-lens, iproute, microlens
, random, rio, stdenv, text, time, unordered-containers, uuid
, vector
}:
mkDerivation {
  pname = "myProj";
  version = "0.1.0";
  src = ./.;
  isLibrary = true;
  isExecutable = true;
  libraryHaskellDepends = [
    aeson amazonka amazonka-core amazonka-dynamodb amazonka-sqs
    aws-lambda-haskell-runtime base bytestring composition containers
    either generic-lens iproute microlens random rio text time
    unordered-containers uuid vector
  ];
  executableHaskellDepends = [
    amazonka aws-lambda-haskell-runtime base iproute
  ];
  license = "unknown";
  hydraPlatforms = stdenv.lib.platforms.none;
}

nix/pkgs-rev.json:

{
  "url": "git://github.com/NixOS/nixpkgs-channels",
  "ref": "nixos-unstable",
  "rev": "4cdd64d9078181e8fcb6132909dc2835059a09bd"
}

nix/static-haskell-rev.json:

{
  "url": "git://github.com/nh2/static-haskell-nix",
  "ref": "master",
  "rev": "dbce18f4808d27f6a51ce31585078b49c86bd2b5"
}

I tried many other permutations of options for configureFlags, as well as
adding stuff to the cabal file like ld-options: -static and cc-options: -static.

ghc-options: -threaded -rtsopts -O2 -static -with-rtsopts=-N
ld-options: -static -pthread
cc-options: -static

While, this is not enough to reproduce the problem yourselves, If I could receive
as much as a clue as to a possible direction I should head towards, or a thing
I should try, I will do it and reply with the results, so feel free to suggest anything!

Why is GHC 8.6.5 involved in the building of this? Is this related to the version
mismatch? I tried stating a build with compiler = "ghc865"
It gave an error about a dependency time not found at the correct version for rebase,
so I jailbroken it and continued building but again, once the last module for the project finishes compiling I get an error about that crtbeginT.o but this time the message is different:

/nix/store/x4hjqhnzfbzh4f333xh1sq31zak3dab1-binutils-2.31.1/bin/ld: /nix/store/p9q71abn3zxpbqrr1k4f35j3k6kx8ayk-gcc-9.3.0/lib/gcc/x86_64-unknown-linux-musl/9.3.0/crtbeginT.o: relocation R_X86_64_32 against hidden symbol `__TMC_END__' can not be used when making a shared object
/nix/store/x4hjqhnzfbzh4f333xh1sq31zak3dab1-binutils-2.31.1/bin/ld: /nix/store/p9q71abn3zxpbqrr1k4f35j3k6kx8ayk-gcc-9.3.0/lib/gcc/x86_64-unknown-linux-musl/9.3.0/crtend.o: relocation R_X86_64_32 against `.ctors' can not be used when making a shared object; recompile with -fPIC
/nix/store/x4hjqhnzfbzh4f333xh1sq31zak3dab1-binutils-2.31.1/bin/ld: final link failed: nonrepresentable section on output
collect2: error: ld returned 1 exit status
`cc' failed in phase `Linker'. (Exit code: 1)

Anyone got a static build working with GHC 8.8.x?

@talw talw changed the title Trying to build with ghc883: Inconsistency detected by ld.so: dl-lookup.c: 111: check_match: Assertion `version->filename == NULL || ! _dl_name_match_p (version->filename, map)' failed! Trying to build with ghc883: Inconsistency detected by ld.so: dl-lookup.c: 111: check_match: Assertion failed! Jul 28, 2020
@nh2
Copy link
Owner

nh2 commented Jul 29, 2020

check_match: Assertion `version->filename == NULL || ! _dl_name_match_p (version->filename, map)' failed!

This is a GHC-in-nixpkgs problem; googling that in conjuction with nixpkgs brings up this first result: NixOS/nixpkgs#85924

The fix suggested by @bgamari at NixOS/nixpkgs#85924 (comment) works for me (in nh2/nixpkgs@d7f663f), I'm also using it in #90.

But nobody has PR'd that fix yet.

I think the main holdup with that is testing it and also fixing it for the non-x86_64 GHCs.

If you would like to help with that, start with my patch, also update i686-linux and aarch64-linux to the fitting Fedora releases in here, test that all the Haskell packages build, and PR the change against the haskell-updates nixpkgs branch, CC'ing the participants of NixOS/nixpkgs#85924 and #90 on the PR. You might also want to join @peti's Haskell Twitch stream on Fridays where such PRs are reviewed together.

@talw
Copy link
Author

talw commented Jul 29, 2020

check_match: Assertion `version->filename == NULL || ! _dl_name_match_p (version->filename, map)' failed!

This is a GHC-in-nixpkgs problem; googling that in conjuction with nixpkgs brings up this first result: NixOS/nixpkgs#85924

The fix suggested by @bgamari at NixOS/nixpkgs#85924 (comment) works for me (in nh2/nixpkgs@d7f663f), I'm also using it in #90.

But nobody has PR'd that fix yet.

I think the main holdup with that is testing it and also fixing it for the non-x86_64 GHCs.

If you would like to help with that, start with my patch, also update i686-linux and aarch64-linux to the fitting Fedora releases in here, test that all the Haskell packages build, and PR the change against the haskell-updates nixpkgs branch, CC'ing the participants of NixOS/nixpkgs#85924 and #90 on the PR. You might also want to join @peti's Haskell Twitch stream on Fridays where such PRs are reviewed together.

Thank you very much! I googled a lot of stuff but did not come across that issue! From this I learn that one should search in nixpkgs' issues as well.
Should this issue be closed as a duplicate of NixOS/nixpkgs#85924 ?
Although it's an issue in nixpkgs, that makes me realize this issue perhaps belongs there as well.

Also, thanks for the guidance on how to proceed from here in order to fix this upstream!

This was referenced Jul 30, 2020
@nh2 nh2 changed the title Trying to build with ghc883: Inconsistency detected by ld.so: dl-lookup.c: 111: check_match: Assertion failed! Tracking issue for GHC bootstrapping compilers being broken with musl in nixpkgs Jul 30, 2020
@nh2 nh2 added the help wanted Extra attention is needed label Jul 30, 2020
@nh2
Copy link
Owner

nh2 commented Jul 30, 2020

Should this issue be closed as a duplicate of NixOS/nixpkgs#85924 ?

We can keep it open, I renamed it accordingly.

Also, thanks for the guidance on how to proceed from here in order to fix this upstream!

Sure thing, that's probably the highest-impact work I can do :)

@nomeata
Copy link

nomeata commented Nov 8, 2020

@talw did you find out more about the crtbeginT.o issue? I am running into this trying to build statically as well (in my case building on top of haskell.nix, input-output-hk/haskell.nix#914)

@talw
Copy link
Author

talw commented Nov 11, 2020

@talw did you find out more about the crtbeginT.o issue? I am running into this trying to build statically as well (in my case building on top of haskell.nix, input-output-hk/haskell.nix#914)

@nomeata

Yes. I applied the patch by @bgamari as suggested by @nh2 and it fixed the issue.
The fix is: NixOS/nixpkgs#85924 (comment)

timjb added a commit to timjb/halma that referenced this issue Dec 13, 2020
Unfortunately, the build fails with

/nix/store/cdbsfljc8m900axs37fab7gnp2y1dksn-binutils-2.31.1/bin/ld: /nix/store/x0ybqvkk6h6x8mhsy5gghplsfvammq6q-gcc-9.3.0/lib/gcc/x86_64-unknown-linux-musl/9.3.0/crtbeginT.o: relocation R_X86_64_32 against hidden symbol `__TMC_END__' can not be used when making a shared object
/nix/store/cdbsfljc8m900axs37fab7gnp2y1dksn-binutils-2.31.1/bin/ld: /nix/store/x0ybqvkk6h6x8mhsy5gghplsfvammq6q-gcc-9.3.0/lib/gcc/x86_64-unknown-linux-musl/9.3.0/crtend.o: relocation R_X86_64_32 against `.ctors' can not be used when making a shared object; recompile with -fPIC

This may be related to

- nh2/static-haskell-nix#99
- input-output-hk/haskell.nix#914
@nomeata
Copy link

nomeata commented Apr 7, 2021

Thanks for applying that fix upstream. It seems I now have a new problem with the bootstrap compiler:

…
Patchelfing /nix/store/iz8azixwl6vzzd87q1p38vlsm3hb21aa-ghc-8.6.5-binary/lib/ghc-8.6.5/bin/hp2ps
Patchelfing /nix/store/iz8azixwl6vzzd87q1p38vlsm3hb21aa-ghc-8.6.5-binary/lib/ghc-8.6.5/bin/ghc-iserv
Patchelfing /nix/store/iz8azixwl6vzzd87q1p38vlsm3hb21aa-ghc-8.6.5-binary/lib/ghc-8.6.5/bin/runghc
Patchelfing /nix/store/iz8azixwl6vzzd87q1p38vlsm3hb21aa-ghc-8.6.5-binary/lib/ghc-8.6.5/ghc-boot-th-8.6.5/libHSghc-boot-th-8.6.5-ghc8.6.5.so
running install tests
/nix/store/6my73ym207a4ds2szcl9wnr1gby10q56-stdenv-linux/setup: line 1318:  7439 Segmentation fault      (core dumped) $out/bin/ghc --make main.hs
builder for '/nix/store/00x82zgp94rf4682gzq63d2nlldzvfmb-ghc-8.6.5-binary.drv' failed with exit code 1

Anyone seen that before?

Opened NixOS/nixpkgs#118731 to track that.

@sjakobi
Copy link

sjakobi commented Apr 7, 2021

Just a shot in the dark, but it might be related to https://gitlab.haskell.org/ghc/ghc/-/issues/17508?!

@bgamari
Copy link

bgamari commented Apr 7, 2021

Indeed every time I've seen a static build fail in the past it has been due to GHC#17508., which is itself due to a very unfortunate ld.gold bug. That being said, I vaguely remember nixpkgs having already worked around this by not using ld.gold in the static GHC build. Can you confirm, @nh2?

@nomeata
Copy link

nomeata commented May 17, 2021

@talw did you find out more about the crtbeginT.o issue? I am running into this trying to build statically as well (in my case building on top of haskell.nix, input-output-hk/haskell.nix#914)

@nomeata

Yes. I applied the patch by @bgamari as suggested by @nh2 and it fixed the issue.
The fix is: NixOS/nixpkgs#85924 (comment)

Thanks! I now get similar error messages when trying nix-build -A pkgsMusl.buildPackages.haskell.compiler.ghc8102Binary on nixpkgs master, namely

Installing library in /nix/store/ffa8jpz98vnqyfsl23pqgp5j44c4rl78-ghc-8.10.2-binary/lib/ghc-8.10.2/ghc-8.10.2
"/nix/store/ffa8jpz98vnqyfsl23pqgp5j44c4rl78-ghc-8.10.2-binary/lib/ghc-8.10.2/bin/ghc-pkg" --force --global-package-db "/nix/store/ffa8jpz98vnqyfsl23pqgp5j44c4rl78-ghc-8.10.2-binary/lib/ghc-8.10.2/package.conf.d" update rts/dist/package.conf.install
/nix/store/ffa8jpz98vnqyfsl23pqgp5j44c4rl78-ghc-8.10.2-binary/lib/ghc-8.10.2/bin/ghc-pkg: /nix/store/s5xpnmnhibl76a47wd65cwrwgjclzrnc-ncurses-6.2/lib/libtinfo.so.6: no version information available (required by /nix/store/ffa8jpz98vnqyfsl23pqgp5j44c4rl78-ghc-8.10.2-binary/lib/ghc-8.10.2/bin/ghc-pkg)
/nix/store/ffa8jpz98vnqyfsl23pqgp5j44c4rl78-ghc-8.10.2-binary/lib/ghc-8.10.2/bin/ghc-pkg: /nix/store/s5xpnmnhibl76a47wd65cwrwgjclzrnc-ncurses-6.2/lib/libtinfo.so.6: no version information available (required by /nix/store/ffa8jpz98vnqyfsl23pqgp5j44c4rl78-ghc-8.10.2-binary/lib/ghc-8.10.2/bin/../terminfo-0.4.1.4/libHSterminfo-0.4.1.4-ghc8.10.2.so)
Inconsistency detected by ld.so: dl-lookup.c: 105: check_match: Assertion `version->filename == NULL || ! _dl_name_match_p (version->filename, map)' failed!
make[1]: *** [ghc.mk:973: install_packages] Error 127
make: *** [Makefile:51: install] Error 2
builder for '/nix/store/hnn4qhzk85vy5rhpi77zfcsykfaz6mmh-ghc-8.10.2-binary.drv' failed with exit code 2

but it seems that the patch by bgamari that you linked to is already applied there.

@nh2
Copy link
Owner

nh2 commented Jul 5, 2021

We can close this issue once the latter is merged.

@nh2
Copy link
Owner

nh2 commented Jul 12, 2021

Closing as I merged the fix: NixOS/nixpkgs#129289

You will still need to wait a bit until it hits master; subscribe to NixOS/nixpkgs#129247 for that.

@nh2 nh2 closed this as completed Jul 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants