From 15b3bc33064eeb0cba743cad585c829b6694669c Mon Sep 17 00:00:00 2001 From: Joe Hermaszewski Date: Sun, 8 Nov 2020 23:51:44 +0800 Subject: [PATCH 1/2] ghc865-binary: Use binary distribution which links against ncurses6 for x86_64-linux Ben Gamari's patch from #85924. Fixes #85924, allowing one to bootstrap GHC in `pkgsMusl` `nix-build -A pkgsMusl.haskellPackages.hello` succeeds with this patch. --- .../compilers/ghc/8.6.5-binary.nix | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/pkgs/development/compilers/ghc/8.6.5-binary.nix b/pkgs/development/compilers/ghc/8.6.5-binary.nix index 41af279e83f..9234e3b1457 100644 --- a/pkgs/development/compilers/ghc/8.6.5-binary.nix +++ b/pkgs/development/compilers/ghc/8.6.5-binary.nix @@ -1,6 +1,6 @@ { stdenv , fetchurl, perl, gcc -, ncurses5, gmp, glibc, libiconv +, ncurses5, ncurses6, gmp, glibc, libiconv , llvmPackages }: @@ -10,8 +10,12 @@ assert stdenv.targetPlatform == stdenv.hostPlatform; let useLLVM = !stdenv.targetPlatform.isx86; + useNcurses6 = stdenv.hostPlatform.system == "x86_64-linux"; + + ourNcurses = if useNcurses6 then ncurses6 else ncurses5; + libPath = stdenv.lib.makeLibraryPath ([ - ncurses5 gmp + ourNcurses gmp ] ++ stdenv.lib.optional (stdenv.hostPlatform.isDarwin) libiconv); libEnvVar = stdenv.lib.optionalString stdenv.hostPlatform.isDarwin "DY" @@ -34,12 +38,16 @@ stdenv.mkDerivation rec { # https://downloads.haskell.org/~ghc/8.6.5/ src = fetchurl ({ i686-linux = { + # Don't use the Fedora27 build (as below) because there isn't one! url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-i386-deb9-linux.tar.xz"; sha256 = "1p2h29qghql19ajk755xa0yxkn85slbds8m9n5196ris743vkp8w"; }; x86_64-linux = { - url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-x86_64-deb9-linux.tar.xz"; - sha256 = "1pqlx6rdjs2110g0y1i9f8x18lmdizibjqd15f5xahcz39hgaxdw"; + # This is the Fedora build because it links against ncurses6 where the + # deb9 one links against ncurses5, see here + # https://github.com/NixOS/nixpkgs/issues/85924 for a discussion + url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-x86_64-fedora27-linux.tar.xz"; + sha256 = "18dlqm5d028fqh6ghzn7pgjspr5smw030jjzl3kq6q1kmwzbay6g"; }; aarch64-linux = { url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-aarch64-ubuntu18.04-linux.tar.xz"; @@ -88,9 +96,12 @@ stdenv.mkDerivation rec { '' + # Rename needed libraries and binaries, fix interpreter stdenv.lib.optionalString stdenv.isLinux '' - find . -type f -perm -0100 -exec patchelf \ + find . -type f -perm -0100 \ + -exec patchelf \ --replace-needed libncurses${stdenv.lib.optionalString stdenv.is64bit "w"}.so.5 libncurses.so \ - --replace-needed libtinfo.so libtinfo.so.5 \ + ${ # This isn't required for x86_64-linux where we use ncurses6 + stdenv.lib.optionalString (!useNcurses6) "--replace-needed libtinfo.so libtinfo.so.5" + } \ --interpreter ${glibcDynLinker} {} \; sed -i "s|/usr/bin/perl|perl\x00 |" ghc-${version}/ghc/stage2/build/tmp/ghc-stage2 From b3640e024f01453b3c4f720135dc6cff529da8ab Mon Sep 17 00:00:00 2001 From: Joe Hermaszewski Date: Sun, 8 Nov 2020 23:54:18 +0800 Subject: [PATCH 2/2] binutils: patch to fix https://sourceware.org/bugzilla/show_bug.cgi?id=16177 This bug was preventing one compiling Haskell programs from `pkgsMusl` for armv7. `nix-build --argstr crossSystem "armv7l-linux" -A pkgsMusl.haskellPackages.hello` succeeds with this patch. The patch is Nick Clifton's one, rebased by @ericson2314 here https://sourceware.org/bugzilla/show_bug.cgi?id=16177#c6 Although there was some talk about the efficacy of the binutils patch (https://sourceware.org/bugzilla/show_bug.cgi?id=16177#c9) the resulting binary seems to run without issue on the target platform. Jessica's patch there caused ld to fail linking some programs. Nick's proposed patch has worked well in my testing so far (a Haskell project of some small complexity cross compiled with musl to armv7). --- .../tools/misc/binutils/R_ARM_COPY.patch | 29 +++++++++++++++++++ .../tools/misc/binutils/default.nix | 8 +++++ 2 files changed, 37 insertions(+) create mode 100644 pkgs/development/tools/misc/binutils/R_ARM_COPY.patch diff --git a/pkgs/development/tools/misc/binutils/R_ARM_COPY.patch b/pkgs/development/tools/misc/binutils/R_ARM_COPY.patch new file mode 100644 index 00000000000..87480986352 --- /dev/null +++ b/pkgs/development/tools/misc/binutils/R_ARM_COPY.patch @@ -0,0 +1,29 @@ +@@ -, +, @@ +--- + bfd/elf32-arm.c | 8 +++++++- + 1 file changed, 7 insertions(+), 1 deletion(-) +--- a/bfd/elf32-arm.c ++++ a/bfd/elf32-arm.c +@@ -15398,7 +15398,11 @@ elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info, + linker to copy the initial value out of the dynamic object and into + the runtime process image. We need to remember the offset into the + .rel(a).bss section we are going to use. */ +- if ((h->root.u.def.section->flags & SEC_READONLY) != 0) ++ if (info->nocopyreloc == 0 ++ && (h->root.u.def.section->flags & SEC_ALLOC) != 0 ++ /* PR 16177: A copy is only needed if the input section is readonly. */ ++ && (h->root.u.def.section->flags & SEC_READONLY) != 0 ++ && h->size != 0) + { + s = globals->root.sdynrelro; + srel = globals->root.sreldynrelro; +@@ -15410,6 +15414,8 @@ elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info, + } + if (info->nocopyreloc == 0 + && (h->root.u.def.section->flags & SEC_ALLOC) != 0 ++ /* PR 16177: A copy is only needed if the input section is readonly. */ ++ && (h->root.u.def.section->flags & SEC_READONLY) != 0 + && h->size != 0) + { + elf32_arm_allocate_dynrelocs (info, srel, 1); + diff --git a/pkgs/development/tools/misc/binutils/default.nix b/pkgs/development/tools/misc/binutils/default.nix index c0846fce45c..978ec3f2f99 100644 --- a/pkgs/development/tools/misc/binutils/default.nix +++ b/pkgs/development/tools/misc/binutils/default.nix @@ -101,6 +101,14 @@ stdenv.mkDerivation { ./patches/2.31/0001-x86-Properly-add-X86_ISA_1_NEEDED-property.patch ] ++ lib.optional stdenv.targetPlatform.isiOS ./support-ios.patch + ++ # This patch was suggested by Nick Clifton to fix + # https://sourceware.org/bugzilla/show_bug.cgi?id=16177 + # It can be removed when that 7-year-old bug is closed. + # This binutils bug causes GHC to emit broken binaries on armv7, and + # indeed GHC will refuse to compile with a binutils suffering from it. See + # this comment for more information: + # https://gitlab.haskell.org/ghc/ghc/issues/4210#note_78333 + lib.optional stdenv.targetPlatform.isAarch32 ./R_ARM_COPY.patch ; outputs = [ "out" "info" "man" ];