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

Fix GHC bootstrap in pkgsMusl and include patch for binutils/16177 #103183

Merged
merged 2 commits into from
Nov 28, 2020

Conversation

expipiplus1
Copy link
Contributor

@expipiplus1 expipiplus1 commented Nov 9, 2020

Motivation for this change

This allows one to cross compile statically linked Haskell programs for armv7

Fixes #85924 using Ben's patch from there. A similar patch should probably be applied to ghc8102-binary.

Fixes https://sourceware.org/bugzilla/show_bug.cgi?id=16177 by applying the patch mentioned there.

Although there was some talk about the efficacy of the binutils patch (https://sourceware.org/bugzilla/show_bug.cgi?id=16177#c9 and expipiplus1/nixpkgs@14efdb2) the resulting binary seems to run without issue on the target platform. Jessica's patch there caused ld to fail linking some programs.

It would be good if there was some resolution to the discussion on the binutils ticket, however this does seem to be an improvement over the broken state of things at the moment.

Obviously this would require rebuilding everything Haskell, and everything on armv7.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@expipiplus1
Copy link
Contributor Author

@ofborg build pkgsMusl.haskellPackages.hello

@cdepillabout
Copy link
Member

cc @Ericson2314 as maintainer for binutils

@dasJ
Copy link
Member

dasJ commented Nov 9, 2020

Mass rebuild so open this against staging, please

@expipiplus1
Copy link
Contributor Author

Oops, changed the target branch in github and the whole world got requested for reviews, sorry!

@dasJ
Copy link
Member

dasJ commented Nov 9, 2020

@expipiplus1 Don't worry about it, that's just what happens 🤷

@zowoq zowoq removed their request for review November 15, 2020 00:42
@expipiplus1
Copy link
Contributor Author

If I revert the gdb change then pkgsMusl.haskellPackages.hello builds fine, obviously this update shouldn't be reverted but it's nice to know that this change should enable pkgsMusl.haskellPackages.hello to work once gdb is working again.

Copy link
Contributor

@nh2 nh2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added two requests to add comments, sounds great otherwise.

@expipiplus1
Copy link
Contributor Author

@nh2 I've added the comments as suggested

Also, while doing this I realize that this patch will break the i686 build! I've added some small amount of complexity to only use ncurses6 on x86_64.

@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild and removed 10.rebuild-darwin: 501+ 10.rebuild-darwin: 5001+ labels Nov 26, 2020
Copy link
Contributor

@nh2 nh2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, while doing this I realize that this patch will break the i686 build! I've added some small amount of complexity to only use ncurses6 on x86_64.

Just to understand, why is that? Does ncurses6 not work on i686?

@expipiplus1
Copy link
Contributor Author

It doesn't compile with the changes as before for i686, I guess because it's still using the deb9 version which is linked with ncurses5. There's no fedora27 version for i686.

@nh2
Copy link
Contributor

nh2 commented Nov 28, 2020

It doesn't compile with the changes as before for i686, I guess because it's still using the deb9 version which is linked with ncurses5. There's no fedora27 version for i686.

@expipiplus1 Ah, please add that as a comment as well -- "upstream does not provide a version" is a good justification.

@bgamari Do you think there should be a fedora27 version for i686, or should this stay with ncurses5?

@expipiplus1
Copy link
Contributor Author

Is there even an i686 release of fedora27?

x86_64-linux

Ben Gamari's patch from NixOS#85924.

Fixes NixOS#85924, allowing one to bootstrap GHC in `pkgsMusl`

`nix-build -A pkgsMusl.haskellPackages.hello` succeeds with this patch.
…d=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).
@expipiplus1
Copy link
Contributor Author

@nh2, done

@nh2
Copy link
Contributor

nh2 commented Nov 28, 2020

Is there even an i686 release of fedora27?

I think they dropped kernel support with fedora31, but I'm not sure I get the whole picture there: https://fedoramagazine.org/in-fedora-31-32-bit-i686-is-86ed/

@nh2
Copy link
Contributor

nh2 commented Nov 28, 2020

@cdepillabout Good to go? The comment you requested has been added. I'm not quite sure if all your questsions from #103183 (comment) are addressed.

Copy link
Member

@cdepillabout cdepillabout left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, thanks for fleshing out the comments!

@FRidh FRidh merged commit e239c8b into NixOS:staging Nov 28, 2020
@expipiplus1 expipiplus1 deleted the joe-haskell-cross-2 branch November 28, 2020 13:29
@talw
Copy link
Contributor

talw commented Dec 9, 2020

@expipiplus1 @Ericson2314

Indeed it is. Cython being used + gdb being target sensative + no splicing black magic has gotten here. I'll make an issue: #104135.

If I revert the gdb change then pkgsMusl.haskellPackages.hello builds fine, obviously this update shouldn't be reverted but it's nice to know that this change should enable pkgsMusl.haskellPackages.hello to work once gdb is working again.

First of all, thank you for the PRs!

I still seem to fail compiling statically due to gdb, whether with the earliest revision containing both PRs 15b3bc33064eeb0cba743cad585c829b6694669c or with the latest revision of nixos-unstable

EDIT: By both PRs, I mean this one, and #104201

Configuring in ./gdb
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I../../opcodes -I. -I../../opcodes -I../bfd -I../../opcodes/../include -I../../opcodes/../bfd -I./../intl -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wstack-usage=262144 -g -O2 -MT disassemble.lo -MD -MP -MF .deps/disassemble.Tpo -c -DARCH_all ../../opcodes/disassemble.c -o disassemble.o
mkdir -p -- ./libctf
Configuring in ./libctf
/nix/store/nz8dyqljf2xwacml7jivafpqqajh15jj-binutils-2.31.1/bin/ld: ax-ipa.o: in function `ax_printf(unsigned long, unsigned long, char const*, int, unsigned long*) [clone .isra.0]':
/build/gdb-10.1/_build/gdbserver/../../gdbserver/ax.cc:928: undefined reference to `libintl_gettext'
/nix/store/nz8dyqljf2xwacml7jivafpqqajh15jj-binutils-2.31.1/bin/ld: /build/gdb-10.1/_build/gdbserver/../../gdbserver/ax.cc:837: undefined reference to `libintl_gettext'
/nix/store/nz8dyqljf2xwacml7jivafpqqajh15jj-binutils-2.31.1/bin/ld: /build/gdb-10.1/_build/gdbserver/../../gdbserver/ax.cc:889: undefined reference to `libintl_gettext'
/nix/store/nz8dyqljf2xwacml7jivafpqqajh15jj-binutils-2.31.1/bin/ld: ax-ipa.o: in function `gdb_eval_agent_expr(eval_agent_expr_context*, agent_expr*, unsigned long*)':
/build/gdb-10.1/_build/gdbserver/../../gdbserver/ax.cc:1334: undefined reference to `libintl_gettext'
/nix/store/nz8dyqljf2xwacml7jivafpqqajh15jj-binutils-2.31.1/bin/ld: gdbsupport/common-utils-ipa.o: in function `xstrvprintf(char const*, __va_list_tag*)':
/build/gdb-10.1/_build/gdbserver/../../gdbserver/../gdbsupport/common-utils.cc:57: undefined reference to `libintl_gettext'
/nix/store/nz8dyqljf2xwacml7jivafpqqajh15jj-binutils-2.31.1/bin/ld: gdbsupport/common-utils-ipa.o:/build/gdb-10.1/_build/gdbserver/../../gdbserver/../gdbsupport/common-utils.cc:69: more undefined references to `libintl_gettext' follow
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:389: libinproctrace.so] Error 1

(...non-error lines...)

make[2]: Leaving directory '/build/gdb-10.1/_build/gdbserver'
make[1]: *** [Makefile:9365: all-gdbserver] Error 2

(...non-error lines...)

make: *** [Makefile:854: all] Error 2
builder for '/nix/store/lay3ilkzal9qsr2k9nbyxm38x1p5cd8k-gdb-10.1.drv' failed with exit code 2
building '/nix/store/v66vfzmg640vgljbq3w61xsyjn1blaqp-cmake-3.19.1.drv'...
cannot build derivation '/nix/store/cbi55fccyxivc6g1nrkh029r4yzdjwfx-python3.8-Cython-0.29.21.drv': 1 dependencies couldn't be built

Is it the same problem? Or is it a different problem?

@Ericson2314
Copy link
Member

@talw that looks different, can you make a separate issue if this still exists?

@Ericson2314
Copy link
Member

@matthewbauer should we backport this?

@talw
Copy link
Contributor

talw commented Dec 21, 2020

@Ericson2314

I see. I guess it is something different.
I was pulled off temporarily from working on the project where I stumbled upon this case.
But once I get back to it, I will try again with the latest revision at that time, and if it will still happen I shall make an issue for it.

Thanks!

@nh2
Copy link
Contributor

nh2 commented Dec 21, 2020

I am using static-haskell-nix which has a survey.nix that overrides a bunch of stuff that results in a gdb that fails to compile.

@talw If you can tell me how to reproduce (best even directly with a nix-build invocation to build gdb from it), I can try and help fix it.

@talw
Copy link
Contributor

talw commented Dec 22, 2020

I am using static-haskell-nix which has a survey.nix that overrides a bunch of stuff that results in a gdb that fails to compile.

@talw If you can tell me how to reproduce (best even directly with a nix-build invocation to build gdb from it), I can try and help fix it.

Thanks @nh2

For reference here is the message I wrote and deleted shortly after (to which you replied):

@talw that looks different, can you make a separate issue if this still exists?

@Ericson2314

I looked at it today, and it looks like it is different as gdb's derivations are different.
Comparing them with nix-diff there were changes going all the way back to curl, zlib and friends. I am using static-haskell-nix which has a survey.nix that overrides a bunch of stuff that results in a gdb that fails to compile. My issue is to be in that repository. Unless I am misguided about the usage of survey.nix

What I realized shortly after is that while the gdb is different and fails to compile, even without
survey.nix's overrides, the vanilla pkgsMusl.gdb fails to compile due to the same problem and on the
revision that includes the 2 PRs that I imagined would fix the gdb issue (perhaps they are unrelated after all?).

The PRs are #104201 and this one #103183

The revision I chose is simply the earliest one to contain both PRs. To reproduce:

$ nix-build --show-trace --no-out-link -E "(import (fetchTarball \"https://github.com/NixOS/nixpkgs/archive/15b3bc33064eeb0cba743cad585c829b6694669c.tar.gz\") {}).pkgsMusl.gdb"

...abbreviated...

/nix/store/zkpjbbicsqa36sg6jb7fcg5qlahcx2na-binutils-2.31.1/bin/ld: ax-ipa.o: in function `ax_printf(unsigned long, unsigned long, char const*, int, unsigned long*) [clone .isra.0]':
/build/gdb-10.1/_build/gdbserver/../../gdbserver/ax.cc:928: undefined reference to `libintl_gettext'
/nix/store/zkpjbbicsqa36sg6jb7fcg5qlahcx2na-binutils-2.31.1/bin/ld: /build/gdb-10.1/_build/gdbserver/../../gdbserver/ax.cc:837: undefined reference to `libintl_gettext'
/nix/store/zkpjbbicsqa36sg6jb7fcg5qlahcx2na-binutils-2.31.1/bin/ld: /build/gdb-10.1/_build/gdbserver/../../gdbserver/ax.cc:889: undefined reference to `libintl_gettext'
/nix/store/zkpjbbicsqa36sg6jb7fcg5qlahcx2na-binutils-2.31.1/bin/ld: ax-ipa.o: in function `gdb_eval_agent_expr(eval_agent_expr_context*, agent_expr*, unsigned long*)':
/build/gdb-10.1/_build/gdbserver/../../gdbserver/ax.cc:1334: undefined reference to `libintl_gettext'
/nix/store/zkpjbbicsqa36sg6jb7fcg5qlahcx2na-binutils-2.31.1/bin/ld: gdbsupport/common-utils-ipa.o: in function `xstrvprintf(char const*, __va_list_tag*)':
/build/gdb-10.1/_build/gdbserver/../../gdbserver/../gdbsupport/common-utils.cc:57: undefined reference to `libintl_gettext'
/nix/store/zkpjbbicsqa36sg6jb7fcg5qlahcx2na-binutils-2.31.1/bin/ld: gdbsupport/common-utils-ipa.o:/build/gdb-10.1/_build/gdbserver/../../gdbserver/../gdbsupport/common-utils.cc:69: more undefined references to `libintl_gettext' follow
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:389: libinproctrace.so] Error 1

...abbreviated...

make[2]: Leaving directory '/build/gdb-10.1/_build/gdbserver'
make[1]: *** [Makefile:9365: all-gdbserver] Error 2

...abbreviated...

make: *** [Makefile:854: all] Error 2
builder for '/nix/store/9ly1l78ggcd6nlhs1c81ilw6x83zc2py-gdb-10.1.drv' failed with exit code 2
error: build of '/nix/store/9ly1l78ggcd6nlhs1c81ilw6x83zc2py-gdb-10.1.drv' failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pkgsMusl.haskell.compiler.ghc883 is broken (bootstrap with ghc865-binary fails)
7 participants