-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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 does not build with musl (ZuriHac 2021 edition) #129247
Comments
Writeup of
|
defaultHardeningFlags = if stdenv.targetPlatform.isMusl | |
then supportedHardeningFlags | |
else lib.remove "pie" supportedHardeningFlags; |
This enables all hardening flags for isMusl
, and disables "pie"
for glibc.
Some side notes
- Fix hardening default for pkgsMusl to reenable -pie #101606 - "Fix hardening default for pkgsMusl to reenable -pie"
Also interesting from there:- cross: regression with armv7 pkgsStatic (error: C compiler cannot create executables) #114953 - "cross: regression with armv7 pkgsStatic (error: C compiler cannot create executables)"
- stdenv: Fix regression on ARM+static when enabling hardening #115363 - "stdenv: Fix regression on ARM+static when enabling hardening"
native aarch64 static also produces segfaulting dynamically linked binaries
It seems that for native x86_64-linux, static builds are fine though.
- stdenv: Fix regression on ARM+static when enabling hardening #115363 - "stdenv: Fix regression on ARM+static when enabling hardening"
- cross: regression with armv7 pkgsStatic (error: C compiler cannot create executables) #114953 - "cross: regression with armv7 pkgsStatic (error: C compiler cannot create executables)"
Finding the fix
With this patch:
--- a/pkgs/development/compilers/ghc/8.6.5-binary.nix
+++ b/pkgs/development/compilers/ghc/8.6.5-binary.nix
@@ -150,6 +150,8 @@ stdenv.mkDerivation rec {
done
'';
+ hardeningDisable = lib.optional stdenv.targetPlatform.isMusl "pie";
+
doInstallCheck = true;
installCheckPhase = ''
unset ${libEnvVar}
The installCheck
of ghc865Binary
passes. However, anything it builds, e.g. happy
on the way to a musl-built ghc, continues to have recompile with -fPIE
errors.
We must disable "pie"
hardening for all Haskell packages with musl.
This commit (is in master
, not 21.05) is promising:
- 830ef64 - "haskell-generic-builder: disable static PIE"
Indeed picking this commit on top of my patch above makes happy
compile.
From here I could continue working on the segfault issue: #118731
Some more side nodes I made during the investigation:
-pie
and-fPIE
are explained in https://nixos.org/manual/nixpkgs/stable/#pie.- GHC does not compile on pkgsMusl after the ld.gold change #84670 - "GHC does not compile on pkgsMusl after the ld.gold change"
- 830ef64 - "haskell-generic-builder: disable static PIE"
- https://gitlab.haskell.org/ghc/ghc/-/issues/19580 - "Support creating static PIE"
- musl: Trivial binaries built with musl will fault on nixos #94228 (comment) - "musl: Trivial binaries built with musl will fault on nixos"
This also affects non static builds.
The most obvious way to compile something with musl, i. e.musl-gcc test.c
will result in a binary which segfaults, because it has the wrong interpreter set. - @nomeata did a similar bisection for ocaml, finding the same commit:
pkgsMusl.ocamlPackages.ocaml: -r and -pie may not be used together #124476 (comment) - "pkgsMusl.ocamlPackages.ocaml: -r and -pie may not be used together" - 6ebb2c3 - "ghc: disable pie, for now limit to musl since not default yet elsewhere"
AddshardeningDisable = ... ++ stdenv.lib.optional stdenv.targetPlatform.isMusl "pie";
- in PR glibc, ghc: disable PIE hardening when enabled by default (musl for now :)) #50426 - "glibc, ghc: disable PIE hardening when enabled by default (musl for now :))"
- linked PR: make-derivation: enable pie hardening with musl #49704 - "make-derivation: enable pie hardening with musl"
- However, these
hardeningDisable
s are for the nix-compiled GHCs, not forghc865Binary
.
- in PR glibc, ghc: disable PIE hardening when enabled by default (musl for now :)) #50426 - "glibc, ghc: disable PIE hardening when enabled by default (musl for now :))"
CC contributors
- from the fix in
master
: @rnhmjoj - from the enabling of
pie
hardening ofmusl
builds: @utsl42 via Fix hardening default for pkgsMusl to reenable -pie #101606
Feel free to add that to |
PR at #129289.
@sternenseemann I tried this but I haven't figured out how to exclude Darwin in there, will need some review suggestions how to do it right :) |
…OS#118731 NixOS#129247. This commit replaces the musl + glibc hackery in the GHC bindist compiler by using the new musl based bindist that GHC HQ provides (built on Alpine). We could alternatively also use a nix-built musl boostrap compiler, but it seems nicer to use the GHC HQ one for now. This fixes the compiler built by `pkgsMusl.haskell.compiler.ghc8102Binary` segfaulting (NixOS#118731) since the commit 5e2311d - musl: 1.2.1 -> 1.2.2 concretely, musl commit 01c7920f - remove redundant pthread struct members repeated for layout purposes which I suspect breaks some glibc/musl ABI compatibility that may have existed accidentally until then. The added lib.optional stdenv.targetPlatform.isMusl "pie"; also fixes that the packaged bindist compiler cannot create a binary in its `installCheck` phase (and overall); see detail explanation in NixOS#129247.
While this does not fix `ghc865Binary` with musl, it at least prevents that the other, newer errors are shadowed (see NixOS#129247).
* include fixes for GHC segfaulting: (NixOS/nixpkgs#129247, NixOS/nixpkgs#129289) * musl 1.2.2, including this important fix from musl 1.2.0: #98 (comment) * workaround for fontforge execution failure due to wrong RPATH: NixOS/nixpkgs#94126 * ilmbase musl compilation error: NixOS/nixpkgs#94205 * mesa: Fix `-Werror=int-conversion` build error on musl: NixOS/nixpkgs#94207
* include fixes for GHC segfaulting: (NixOS/nixpkgs#129247, NixOS/nixpkgs#129289) * musl 1.2.2, including this important fix from musl 1.2.0: #98 (comment) * workaround for fontforge execution failure due to wrong RPATH: NixOS/nixpkgs#94126 * ilmbase musl compilation error: NixOS/nixpkgs#94205 * mesa: Fix `-Werror=int-conversion` build error on musl: NixOS/nixpkgs#94207 survey: * Update file in which stackage packages are listed. See nixpkgs commit 7f236bd4 - hackage2nix: Split configuration, auto disable hydra builds
…OS#118731 NixOS#129247. This commit replaces the musl + glibc hackery in the GHC bindist compiler by using the new musl based bindist that GHC HQ provides (built on Alpine). We could alternatively also use a nix-built musl boostrap compiler, but it seems nicer to use the GHC HQ one for now. This fixes the compiler built by `pkgsMusl.haskell.compiler.ghc8102Binary` segfaulting (NixOS#118731) since the commit 5e2311d - musl: 1.2.1 -> 1.2.2 concretely, musl commit 01c7920f - remove redundant pthread struct members repeated for layout purposes which I suspect breaks some glibc/musl ABI compatibility that may have existed accidentally until then. The added lib.optional stdenv.targetPlatform.isMusl "pie"; also fixes that the packaged bindist compiler cannot create a binary in its `installCheck` phase (and overall); see detail explanation in NixOS#129247.
While this does not fix `ghc865Binary` with musl, it at least prevents that the other, newer errors are shadowed (see NixOS#129247).
I merged PR #129289 into Close this issue when |
The musl support for binary GHC 8.6.5 relied on ABI compat between musl and glibc which is no longer the case: #129247 Since there is no upstream musl (alpine) bindist for GHC 8.6.5, we can only accept that binary 8.6.5 is not possible with musl.
#129289 has now been merged into |
* include fixes for GHC segfaulting: (NixOS/nixpkgs#129247, NixOS/nixpkgs#129289) * musl 1.2.2, including this important fix from musl 1.2.0: #98 (comment) * workaround for fontforge execution failure due to wrong RPATH: NixOS/nixpkgs#94126 * ilmbase musl compilation error: NixOS/nixpkgs#94205 * mesa: Fix `-Werror=int-conversion` build error on musl: NixOS/nixpkgs#94207 survey: * Update file in which stackage packages are listed. See nixpkgs commit 7f236bd4 - hackage2nix: Split configuration, auto disable hydra builds
…OS#118731 NixOS#129247. This commit replaces the musl + glibc hackery in the GHC bindist compiler by using the new musl based bindist that GHC HQ provides (built on Alpine). We could alternatively also use a nix-built musl boostrap compiler, but it seems nicer to use the GHC HQ one for now. This fixes the compiler built by `pkgsMusl.haskell.compiler.ghc8102Binary` segfaulting (NixOS#118731) since the commit 5e2311d - musl: 1.2.1 -> 1.2.2 concretely, musl commit 01c7920f - remove redundant pthread struct members repeated for layout purposes which I suspect breaks some glibc/musl ABI compatibility that may have existed accidentally until then. The added lib.optional stdenv.targetPlatform.isMusl "pie"; also fixes that the packaged bindist compiler cannot create a binary in its `installCheck` phase (and overall); see detail explanation in NixOS#129247.
While this does not fix `ghc865Binary` with musl, it at least prevents that the other, newer errors are shadowed (see NixOS#129247).
In this issue I'm writing up 3 problems that broke GHC on
musl
(e.g.pkgsMusl.ghc
, and all ofstatic-haskell-nix
on current nixpkgs) during the last half year.We started investigating these at ZuriHac, but didn't get to the bottom; with some more weekends sunk into it, I've now figured them out.
The key problems:
check_match: Assertion `version->filename == NULL
error due to mismatching versions ofncurses
in the GHC bindists (link)ghc-8.6.5-binary.nix
compilation fails withrecompile with -fPIE
(explained in this issue)The challenging part about these problems are that they (and some fixes) were introduced in roughly the same time, such that one had to fix all 3 of them to actually get
pkgsMusl.ghc
to compile again, and making bisection much harder.This meant that we were unable to make any real progress during ZuriHac 2021, and a lot more contributor free time had to be spent to figure it out.
lobby time:
An always-green Hydra that builds
pkgsMusl.ghc
would have saved multiple workdays of multiple people here.If you are interested in these topics, here is the table of contents of problems plus their fixes, with links to the detail investigations:
glibc
bindists from GHC HQ, and patchmusl
in so that there are 2 different libcs used in the same program, only worked out of luck so far.check_match: Assertion
version->filename == NULLerror due to mismatching versions of
ncurses` in the GHC bindists (pkgsMusl.haskell.compiler.ghc883 is broken (bootstrap with ghc865-binary fails) #85924)ncurses
; fixed by Fix GHC bootstrap in pkgsMusl and include patch for binutils/16177 #103183. Explained in there.ghc-8.6.5-binary.nix
compilation fails withrecompile with -fPIE
"pie"
hardening formusl
only. Works fine for C, but GHC cannot yet emit outputs that are ready forpie
hardening.pie
hardening is disabled by default forglibc
, because, the heading structure of that manual section is poor, making it easy to read it as part of the enabled-by-default hardening options.pie
hardening for Haskell builds, but found is already done inmaster
by 830ef64 via PR Haskell updates #123682.This issue can be closed when all above problems are addressed on nixpkgs
master
.CC the people involved in these topics: @expipiplus1 @bgamari @nomeata @domenkozar @dtzWill @lunaris @NorfairKing @maralorn @sternenseemann
Special thanks to @aveltras and
tristanC
who helped me debug a lot during ZuriHac.The text was updated successfully, but these errors were encountered: