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

GHC 7.10.3 (and later) don't compile on NixOS #10752

Closed
mboes opened this issue Oct 31, 2015 · 9 comments · Fixed by #20288
Closed

GHC 7.10.3 (and later) don't compile on NixOS #10752

mboes opened this issue Oct 31, 2015 · 9 comments · Fixed by #20288

Comments

@mboes
Copy link
Contributor

mboes commented Oct 31, 2015

The ghcHEAD package is currently pinned at a commit from 2015-08-28. I attempted to update it to a commit dated 2015-10-30 using the below patch to nixpkgs commit 7eea66cabeaaefa0961cf38630a17aee0e2dd536:

diff --git a/pkgs/development/compilers/ghc/head.nix b/pkgs/development/compilers/ghc/head.nix
index fe0d0b3..96c5a0a 100644
--- a/pkgs/development/compilers/ghc/head.nix
+++ b/pkgs/development/compilers/ghc/head.nix
@@ -17,14 +17,14 @@ let
 in

 stdenv.mkDerivation rec {
-  version = "7.11.20150828";
+  version = "7.11.20151030";
   name = "ghc-${version}";
-  rev = "38c98e4f61a48084995a5347d76ddd024ce1a09c";
+  rev = "91c6b1f54aea658b0056caec45655475897f1972";

   src = fetchgit {
     url = "git://git.haskell.org/ghc.git";
     inherit rev;
-    sha256 = "0wnxrfzjpjcmsmd2i0zg30jg7zpw1rrfwz8r56g314l7xcns6yp1";
+    sha256 = "0p0jrj957s9cpffvpf7qwrvjc9b8i4k21baa9yj480wpwi7xy690";
   };

   postUnpack = ''

But with this and other more recent versions of GHC HEAD, I'm getting:

    Call hs_init_ghc() from your main() function to set these options.
"inplace/bin/ghc-stage1" -o utils/dll-split/dist-install/build/tmp/dll-split -hisuf dyn_hi -osuf  dyn_o -hcsuf dyn_hc -fPIC -dynamic  -H32m -O -Wall     -hide-all-packages -i -iutils/dll-split/. -iutils/dll-split/dist-install/build -iutils/dll-split/dist-install/build/autogen -Iutils/dll-split/dist-install/build -Iutils/dll-split/dist-install/build/autogen     -optP-include -optPutils/dll-split/dist-install/build/autogen/cabal_macros.h -package-id base-4.8.2.0 -package-id containers-0.5.6.2 -package-id filepath-1.4.0.0 -XHaskell2010  -no-user-package-db -rtsopts      -odir utils/dll-split/dist-install/build -hidir utils/dll-split/dist-install/build -stubdir utils/dll-split/dist-install/build   -optl-L'/tmp/nix-build-ghc-7.11.20151030.drv-0/ghc-91c6b1f/libraries/filepath/dist-install/build' -optl-L'/tmp/nix-build-ghc-7.11.20151030.drv-0/ghc-91c6b1f/libraries/containers/dist-install/build' -optl-L'/tmp/nix-build-ghc-7.11.20151030.drv-0/ghc-91c6b1f/libraries/deepseq/dist-install/build' -optl-L'/tmp/nix-build-ghc-7.11.20151030.drv-0/ghc-91c6b1f/libraries/array/dist-install/build' -optl-L'/tmp/nix-build-ghc-7.11.20151030.drv-0/ghc-91c6b1f/libraries/base/dist-install/build' -optl-L'/tmp/nix-build-ghc-7.11.20151030.drv-0/ghc-91c6b1f/libraries/integer-gmp/dist-install/build' -optl-L'/nix/store/i4g323b60pskbayk4awl3ffz8m365264-gmp-5.1.3/lib' -optl-L'/tmp/nix-build-ghc-7.11.20151030.drv-0/ghc-91c6b1f/libraries/ghc-prim/dist-install/build' -optl-L'/tmp/nix-build-ghc-7.11.20151030.drv-0/ghc-91c6b1f/rts/dist/build' -optl-lgmp -optl-lm -optl-lrt -optl-ldl -fPIC -dynamic  -H32m -O -Wall     -hide-all-packages -i -iutils/dll-split/. -iutils/dll-split/dist-install/build -iutils/dll-split/dist-install/build/autogen -Iutils/dll-split/dist-install/build -Iutils/dll-split/dist-install/build/autogen     -optP-include -optPutils/dll-split/dist-install/build/autogen/cabal_macros.h -package-id base-4.8.2.0 -package-id containers-0.5.6.2 -package-id filepath-1.4.0.0 -XHaskell2010  -no-user-package-db -rtsopts      -fno-use-rpaths -optl-Wl,-rpath -optl-Wl,'$ORIGIN/../filepath-1.4.0.0' -optl-Wl,-rpath -optl-Wl,'$ORIGIN/../containers-0.5.6.2' -optl-Wl,-rpath -optl-Wl,'$ORIGIN/../deepseq-1.4.2.0' -optl-Wl,-rpath -optl-Wl,'$ORIGIN/../array-0.5.1.0' -optl-Wl,-rpath -optl-Wl,'$ORIGIN/../base-4.8.2.0' -optl-Wl,-rpath -optl-Wl,'$ORIGIN/../integer-gmp-1.0.0.0' -optl-Wl,-rpath -optl-Wl,'$ORIGIN/../ghc-prim-0.4.0.0' -optl-Wl,-rpath -optl-Wl,'$ORIGIN/../rts' -optl-Wl,-zorigin utils/dll-split/dist-install/build/Main.dyn_o    
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: warning: libpthread.so.0, needed by /nix/store/hd6km3hscbgl2yw8nx7lr5z9s8h89p04-glibc-2.21/lib/librt.so, not found (try using -rpath or -rpath-link)
/nix/store/hd6km3hscbgl2yw8nx7lr5z9s8h89p04-glibc-2.21/lib/librt.so: undefined reference to `pthread_detach@GLIBC_2.2.5'
/nix/store/hd6km3hscbgl2yw8nx7lr5z9s8h89p04-glibc-2.21/lib/librt.so: undefined reference to `pthread_attr_setstacksize@GLIBC_2.2.5'
/nix/store/hd6km3hscbgl2yw8nx7lr5z9s8h89p04-glibc-2.21/lib/librt.so: undefined reference to `pthread_barrier_init@GLIBC_2.2.5'
/nix/store/hd6km3hscbgl2yw8nx7lr5z9s8h89p04-glibc-2.21/lib/librt.so: undefined reference to `pthread_cancel@GLIBC_2.2.5'
/nix/store/hd6km3hscbgl2yw8nx7lr5z9s8h89p04-glibc-2.21/lib/librt.so: undefined reference to `pthread_create@GLIBC_2.2.5'
/nix/store/hd6km3hscbgl2yw8nx7lr5z9s8h89p04-glibc-2.21/lib/librt.so: undefined reference to `__shm_directory@GLIBC_PRIVATE'
/nix/store/hd6km3hscbgl2yw8nx7lr5z9s8h89p04-glibc-2.21/lib/librt.so: undefined reference to `pthread_once@GLIBC_2.2.5'
/nix/store/hd6km3hscbgl2yw8nx7lr5z9s8h89p04-glibc-2.21/lib/librt.so: undefined reference to `pthread_sigmask@GLIBC_2.2.5'
/nix/store/hd6km3hscbgl2yw8nx7lr5z9s8h89p04-glibc-2.21/lib/librt.so: undefined reference to `pthread_barrier_wait@GLIBC_2.2.5'
/nix/store/hd6km3hscbgl2yw8nx7lr5z9s8h89p04-glibc-2.21/lib/librt.so: undefined reference to `__pthread_unwind@GLIBC_PRIVATE'
/nix/store/hd6km3hscbgl2yw8nx7lr5z9s8h89p04-glibc-2.21/lib/librt.so: undefined reference to `__pthread_get_minstack@GLIBC_PRIVATE'
collect2: error: ld returned 1 exit status
`cc' failed in phase `Linker'. (Exit code: 1)
utils/dll-split/ghc.mk:18: recipe for target 'utils/dll-split/dist-install/build/tmp/dll-split' failed
make[1]: *** [utils/dll-split/dist-install/build/tmp/dll-split] Error 1
Makefile:121: recipe for target 'all' failed
make: *** [all] Error 2
builder for ‘/nix/store/s3b14rbv6xvnj7l0nn8bpd675mqvmxxm-ghc-7.11.20151030.drv’ failed with exit code 2
error: build of ‘/nix/store/s3b14rbv6xvnj7l0nn8bpd675mqvmxxm-ghc-7.11.20151030.drv’ failed
/run/current-system/sw/bin/nix-shell: failed to build all dependencies

This happens when using the command

$ nix-shell --pure haskell.compiler.ghcHEAD -I nixpkgs=~/src/nixpkgs

Versions:

$ nix-shell --version
nix-shell (Nix) 1.10
$ nixos-version                                                                   
16.03pre70725.763ad33 (Emu)
@peti
Copy link
Member

peti commented Oct 31, 2015

Have you reported this issue to the ghc developers?

@mboes
Copy link
Contributor Author

mboes commented Oct 31, 2015

I haven't yet, since I don't know whether this is a GHC bug. It would be useful to a bisect to a specific commit. What's the best way to do that (nix-shell throws away build artifacts at each invocation)?

@peti
Copy link
Member

peti commented Nov 1, 2015

If you have a local checkout of the repository, then you can enter a build environment (nix-shell -A haskell.packages.ghcHEAD.ghc) and compile in there manually. Those builds would be incremental.

From the looks of it, it appears to me that GHC tries to link -lrt without -pthread, which fails. But I haven't investigated it much either.

@mboes
Copy link
Contributor Author

mboes commented Nov 1, 2015

I get

$  nix-shell -p haskell.compiler.ghcHEAD -A haskell.packages.ghcHEAD.ghc -I nixpkgs=~/nixpkgs
error: attribute ‘haskell’ in selection path ‘haskell.packages.ghcHEAD.ghc’ not found

Do I need to write a special default.nix? If so, what should I write? (still a beginner with nix...)

@mboes
Copy link
Contributor Author

mboes commented Nov 1, 2015

Ah! I think I got it...

$ nix-shell '<nixpkgs>' -A haskell.packages.ghcHEAD.ghc -I nixpkgs=~/nixpkgs

@mboes
Copy link
Contributor Author

mboes commented Nov 1, 2015

So the issue I have is that configurePhase and buildPhase are local shell functions, not commands, so I can't include them in a script to be run by git bisect run. Is there any way I can wrap those?

@waern
Copy link
Contributor

waern commented Nov 29, 2015

Seems to me like this is the offending GHC commit: ghc/ghc@296bc70

I'll investigate a bit more and try to file a GHC ticket.

@waern
Copy link
Contributor

waern commented Nov 30, 2015

I created a GHC ticket: https://ghc.haskell.org/trac/ghc/ticket/11147

@peti
Copy link
Member

peti commented Dec 9, 2015

ghc 7.10.3 has the same issue: http://hydra.cryp.to/build/1411032/log/raw

@peti peti self-assigned this Dec 9, 2015
@peti peti changed the title Update GHC HEAD GHC 7.10.3 (and later) don't compile on NixOS Dec 15, 2015
peti referenced this issue in ghc/ghc Dec 16, 2015
On Windows, we're constrained to 32k bytes total for command line
arguments.  When building large projects, this limit can be exceeded.
This patch changes GHC to always use response files for linker
arguments, a feature first used by Microsoft compilers and added to GCC
(over a decade ago).

Alternatives here include:

* Only use this method on Windows systems
* Check the length of the command line arguments and use that to decide
  whether to use this method

I did not pursue either of these, as I believe it would make the patch
more likely to break in less tested situations.

Test Plan:
Confirm that linking still works in general. Ideally: compile a very
large project on Windows with this patch. (I am attempting to do that
myself now, but having trouble getting the Windows build tool chain up
and running.)

Reviewers: goldfire, hvr, rwbarton, austin, thomie, bgamari, Phyx

Reviewed By: thomie, bgamari, Phyx

Subscribers: erikd, awson, #ghc_windows_task_force, thomie

Differential Revision: https://phabricator.haskell.org/D1158

GHC Trac Issues: #8596, #10777
@peti peti closed this as completed in a421e7b Dec 16, 2015
peti added a commit that referenced this issue Jan 21, 2016
The new GHC version contains a patch [1] that passes linker and compiler flags
to GCC via response files rather than directly on the command-line. This is
supposed to be beneficial on Windows and other platforms that have trouble
dealing with long argument lists. On NixOS, however, this feature breaks the
flag handling provided by gcc-wrapper [2] and therefore causes the entire GHC
build to fail.

This issue has been reported upstream at [3]. It's not clear yet how to remedy
this problem, but until we've figured that out we just don't pass compiler flags
in response files on NixOS to fix #10752.

[1] ghc/ghc@296bc70
[2] #11762
[3] https://ghc.haskell.org/trac/ghc/ticket/11147

(cherry picked from commit a421e7b)
peti added a commit that referenced this issue Jan 21, 2016
domenkozar added a commit that referenced this issue Nov 10, 2016
haskell.compiler.ghcHEAD: fix patchPhase #10752
adrianpk added a commit to adrianpk/nixpkgs that referenced this issue May 31, 2024
The new GHC version contains a patch [1] that passes linker and compiler flags
to GCC via response files rather than directly on the command-line. This is
supposed to be beneficial on Windows and other platforms that have trouble
dealing with long argument lists. On NixOS, however, this feature breaks the
flag handling provided by gcc-wrapper [2] and therefore causes the entire GHC
build to fail.

This issue has been reported upstream at [3]. It's not clear yet how to remedy
this problem, but until we've figured that out we just don't pass compiler flags
in response files on NixOS to fix NixOS#10752.

[1] ghc/ghc@296bc70
[2] NixOS#11762
[3] https://ghc.haskell.org/trac/ghc/ticket/11147

(cherry picked from commit a421e7b)
adrianpk added a commit to adrianpk/nixpkgs that referenced this issue May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants