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

Cross-compilation failure with remote-iserv #441

Closed
michivi opened this issue Feb 8, 2020 · 5 comments · Fixed by #480
Closed

Cross-compilation failure with remote-iserv #441

michivi opened this issue Feb 8, 2020 · 5 comments · Fixed by #480

Comments

@michivi
Copy link
Contributor

michivi commented Feb 8, 2020

Hi everyone,

I tried to cross-compile a Stack project for the Raspberry Pi (ARMv6l) but it fails with the following error:

---> Starting remote-iserv on port 6558
---| remote-iserv should have started on 6558
[         iserv-proxy] Created socket for 127.0.0.1:6558
[         iserv-proxy] Created socket for 127.0.0.1:6558
[         iserv-proxy] connected
[         iserv-proxy] Starting proxy
Listening on port 6558
[         iserv-proxy] fwdLoadCall: missing path: /nix/store/kf2cgy6gfrap9vrraxrx3jsscfnn8b1d-armv6l-unknown-linux-gnueabihf-ghc-8.6.5/lib/armv6l-unknown-linux-gnueabihf-ghc-8.6.5/ghc-prim-0.5.3/HSghc-prim-0.5.3.o
remote-iserv: Failed to lookup symbol: __sync_val_compare_and_swap_8


<no location info>: error:
    ghc: unable to load package `ghc-prim-0.5.3'

The Stack project uses GHC 8.6.5 with the latest version of Haskell-Nix (at the time I wrote this issue), and I had to set the following flags as mentioned in #313 :

packages.ghci.flags.ghci = true;
packages.libiserv.flags.network = true;

I tried cross-compiling the project to ARMv7l and the build ended properly.

Some investigations led me to believe that ghc-prim is using atomic builtin GCC functions that aren't defined for ARMv6l and were hence replaced with external function calls, which remote-iserv failed to find. If I am not mistaken, #387 did remove some of them (in atomic.c), but not the one defined in SMP.h, when a threaded RTS is used.

Have I overlooked something?

Thank you for your help

@angerman
Copy link
Collaborator

angerman commented Feb 9, 2020

This sounds pretty similar to the stuff I did debug with @eamsden a while back... I don't really remember the reason anymore :-/

@eamsden
Copy link
Contributor

eamsden commented Feb 11, 2020

@michivi What git revision of Haskell.nix did you use? Is it more recent than (i.e. does it include) the commit 563e18c?

This looks like one of the errors I was dealing with there: the main issue is that ghc doesn't build its core/boot libraries dynamically when nix sets it up for cross-compilation, so any other libraries that link to those (read, any libraries at all, pretty much) must also not be build dynamically. If you build with haskell.nix including that commit you should get static-only builds when cross-compiling to ARM.

@eamsden
Copy link
Contributor

eamsden commented Feb 11, 2020

@angerman until my PR of a couple of weeks ago all that patching we wound up doing was languishing in input-output-hk/iohk-nix and never made it into haskell.nix, so if @michivi hasn't updated haskell.nix in the last week or two, ARM builds would be broken

@angerman
Copy link
Collaborator

@eamsden you are right, I was implicitly assuming he was using the most recent master. @michivi please provide the haskell.nix revision you are using!

@michivi
Copy link
Contributor Author

michivi commented Feb 12, 2020

@eamsden @angerman I used the most recent version of Haskell.nix I could at that time: efb9a07. I believe it does include commit 563e18c. I also did a test without that commit a few weeks ago, with exactly the same results. Aside from the custom flags I've put for ghci and libiserv in my Stack Nix project file, I'm pretty much using Haskell.nix as-is.

At first, I thought that was a problem in GHC (much like this 9886 GHC issue). But then, the patch ghc-8.6.4-prim-no-arm-atomics.patch removed those call, except for the one in SMP.h and I wondered if it was that call that brought all the other missing signatures. I thought perhaps using the perf-cross build flavor would remove the unused signatures but as you've mentioned in the associated PR, that is actually breaking qemu. I'm still looking for a solution, but my knowledge of GHC's internal is still limited. Thank you for your help!

hamishmack pushed a commit that referenced this issue Mar 11, 2020
This PR adds a patch for GHC 8.6.5 to properly remove the atomic primops fallbacks on ARM architectures. Those primops called some GCC legacy synchronization functions that were not loaded during TH, ending in failure within `remote-iserv`. It turns out that the condition `!defined(arm_HOST_ARCH)` was never `true`, as `arm_HOST_ARCH` was actually defined (on ARM architectures) in a dependency of the `Rts.h` file.

This patch works for my use case (GHC 8.6.5 for armv6l). I haven't done any test on the other GHC versions.

This PR also includes a patch to actually use the native `pkgconfig` during cross-compilation.

Fixes #441

Authored-by: Michivi <webmaster@michvi.com>
michivi added a commit to michivi/haskell.nix that referenced this issue Sep 29, 2020
Fixes the input-output-hk#441 issue with GHC 8.8.3 (issue that was already applied to GHC 8.6.5)
michivi added a commit to michivi/haskell.nix that referenced this issue Sep 29, 2020
Fixes the input-output-hk#441 issue with GHC 8.8.3 (fix that was already applied to GHC 8.6.5)
hamishmack pushed a commit that referenced this issue Oct 14, 2020
Fixes the #441 issue with GHC 8.8.3 (fix that was already applied to GHC 8.6.5 with PR #480).

Testing environment:

- GHC 8.8.3 (cross-compiler)
- NixOS 20.03
- Building host: x86_64
- Target host: armv6l

Without this PR, the symbol `__sync_val_compare_and_swap_8` was not found by `remote-iserv` as described in #441 but this time with GHC 8.8.3. The 8.6.5 patch also works for 8.8.3. Perhaps it would be preferable to apply this patch to a range of GHC versions rather than specific versions, but I have only tested it and verified that it works properly on those specific versions.

I have not submitted this patch to the GHC GitLab as I haven't encountered any problem building a cross-compiling version of GHC from there.
booniepepper pushed a commit to booniepepper/haskell.nix that referenced this issue Feb 4, 2022
…tput-hk#857)

Fixes the input-output-hk#441 issue with GHC 8.8.3 (fix that was already applied to GHC 8.6.5 with PR input-output-hk#480).

Testing environment:

- GHC 8.8.3 (cross-compiler)
- NixOS 20.03
- Building host: x86_64
- Target host: armv6l

Without this PR, the symbol `__sync_val_compare_and_swap_8` was not found by `remote-iserv` as described in input-output-hk#441 but this time with GHC 8.8.3. The 8.6.5 patch also works for 8.8.3. Perhaps it would be preferable to apply this patch to a range of GHC versions rather than specific versions, but I have only tested it and verified that it works properly on those specific versions.

I have not submitted this patch to the GHC GitLab as I haven't encountered any problem building a cross-compiling version of GHC from there.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants