Cross-compiling To Aarch64-multiplatform-musl Fails With CPP

by ADMIN 61 views

Introduction

Cross-compiling to aarch64-multiplatform-musl is a complex process that involves building a static binary for the aarch64 architecture on a host machine running x86_64-linux. However, this process can fail when packages containing CPP are involved. In this article, we will explore the issue of cross-compiling to aarch64-multiplatform-musl failing with CPP and provide a step-by-step guide to reproduce the issue.

Steps To Reproduce

To reproduce the issue, we will use the pkgsCross.aarch64-multiplatform-musl package on an x86_64-linux host. We will use GHC 9.12.2 to avoid the issue mentioned in #2314. The repro can be tried by running the following commands:

# Building with aarch64-multiplatform-musl fails
nix build github:thomasjm/aarch64-cpp-repro#aarch64-multiplatform-musl

# Building with all of the following succeed
nix build github:thomasjm/aarch64-cpp-repro#aarch64-multiplatform
nix build github:thomasjm/aarch64-cpp-repro#musl64
nix build github:thomasjm/aarch64-cpp-repro#normal

Additional Context

Interestingly, the aarch64-multiplatform-musl target does work with the hackage method, like this:

(pkgs.pkgsCross.aarch64-multiplatform-musl.haskell-nix.hackage-package { compiler-nix-name = "ghc9122"; name = "pandoc-types"; }).components.library

which you can test like this:

nix build github:thomasjm/aarch64-cpp-repro#hackage

Logs

The logs for the failed build are as follows:

Preprocessing library for pandoc-types-1.23.1..
Building library for pandoc-types-1.23.1..
[1 of 7] Compiling Paths_pandoc_types ( dist/build/autogen/Paths_pandoc_types.hs, dist/build/Paths_pandoc_types.o )
[2 of 7] Compiling Text.Pandoc.Definition ( src/Text/Pandoc/Definition.hs, dist/build/Text/Pandoc/Definition.o )
---> Starting iserv-proxy-interpreter on port 5157
---| iserv-proxy-interpreter should have started on 5157
Listening on port 5157
iserv-proxy-interpreter: internal error: 0x0 address for _ZZN12_GLOBAL__N_110get_globalEvE6global + 0 of type 562 in tmp/nix/store/n3hqwf99iff5xna2r17rld384j5hyb6c-aarch64-unknown-linux-musl-gcc-13.3.0/aarch64-unknown-linux-musl/lib/libstdc++.a(#40:eh_globals.o) for relocation 0 in section 4 of kind: 0

    (GHC version 9.12.2 for aarch64_unknown_linux)
    Please report this as a GHC bug:  https://www.haskell.org/ghc/reportabug
qemu: uncaught target signal 6 (Aborted) - core dumped
is-proxy: Uncaught exception ghc-internal:GHC.Internal.IO.Exception.IOException:

{handle: <socket: 9>}: GHCi.Message.remoteCall: end of file

HasCallStack backtrace:
  collectBacktraces, called at libraries/ghc-internal/src/GHC/Internal/Exception.hs:169:13 in ghc-internal:GHC.Internal.Exception
  toExceptionWithBacktrace, called at libraries/ghc-internal/src/GHC/Internal/Exception.hs:89:42 in ghc-internal:GHC.Internal.Exception
  throw, called at libraries/ghci/GHCi/Message.hs:673:16 in ghci-9.12.2-inplace:GHCi.Message

/nix/store/94ssjbg3g4lzki51qjrvc9ni3fqaakrx-iserv-wrapper/bin/iserv-wrapper: line 13:   457 Aborted                 /nix/store/xbfjilai721rzd9rf9dhhpv03xza4xp4-qemu-9.1.3/bin/qemu-aarch64 /nix/store/0116qb75b4d4pxwmvq6h6prh4cwhndg1-iserv-proxy-exe-iserv-proxy-interpreter-aarch64-unknown-linux-musl-9.3/bin/iserv-proxy-interpreter tmp $PORT $ISERV_ARGS
<no location info>: error: External interpreter terminated (1)

Conclusion

Cross-compiling to aarch64-multiplatform-musl fails with CPP due to an internal error in the iserv-proxy-interpreter. This issue can be reproduced by building a package containing CPP using pkgsCross.aarch64-multiplatform-musl on an x86_64-linux host. The issue is not present when building with the hackage method or with other targets such as aarch64-multiplatform or musl64.

Possible Solutions

  1. Update GHC: The issue may be related to a bug in GHC 9.12.2. Updating to a newer version of GHC may resolve the issue.
  2. Use a different compiler: The issue may be specific to the aarch64-multiplatform-musl target. Using a different compiler or target may resolve the issue.
  3. Disable CPP: If the package can be built without CPP, disabling CPP may resolve the issue.
  4. Use a different build method: The issue may be related to the build method used. Using a different build method, such as hackage, may resolve the issue.

Future Work

To resolve this issue, further investigation is needed to determine the root cause of the problem. This may involve:

  1. Analyzing the logs: Analyzing the logs to determine the exact cause of the internal error.
  2. Testing with different compilers: Testing with different compilers to determine if the issue is specific to GHC 9.12.2.
  3. Testing with different targets: Testing with different targets to determine if the issue is specific to the aarch64-multiplatform-musl target.
  4. Disabling CPP: Disabling CPP to determine if the issue is related to CPP.

By following these steps and possible solutions, we can resolve the issue of cross-compiling to aarch64-multiplatform-musl failing with CPP.

Introduction

In our previous article, we explored the issue of cross-compiling to aarch64-multiplatform-musl failing with CPP. In this article, we will provide a Q&A section to answer some of the most frequently asked questions related to this issue.

Q: What is the cause of the internal error in the iserv-proxy-interpreter?

A: The exact cause of the internal error in the iserv-proxy-interpreter is not yet known. However, it is believed to be related to a bug in GHC 9.12.2 or a specific issue with the aarch64-multiplatform-musl target.

Q: How can I reproduce the issue?

A: To reproduce the issue, you can follow the steps outlined in our previous article. You will need to build a package containing CPP using pkgsCross.aarch64-multiplatform-musl on an x86_64-linux host.

Q: What are the possible solutions to this issue?

A: There are several possible solutions to this issue, including:

  1. Update GHC: The issue may be related to a bug in GHC 9.12.2. Updating to a newer version of GHC may resolve the issue.
  2. Use a different compiler: The issue may be specific to the aarch64-multiplatform-musl target. Using a different compiler or target may resolve the issue.
  3. Disable CPP: If the package can be built without CPP, disabling CPP may resolve the issue.
  4. Use a different build method: The issue may be related to the build method used. Using a different build method, such as hackage, may resolve the issue.

Q: What are the next steps to resolve this issue?

A: To resolve this issue, further investigation is needed to determine the root cause of the problem. This may involve:

  1. Analyzing the logs: Analyzing the logs to determine the exact cause of the internal error.
  2. Testing with different compilers: Testing with different compilers to determine if the issue is specific to GHC 9.12.2.
  3. Testing with different targets: Testing with different targets to determine if the issue is specific to the aarch64-multiplatform-musl target.
  4. Disabling CPP: Disabling CPP to determine if the issue is related to CPP.

Q: Can I use a different build method to resolve this issue?

A: Yes, you can use a different build method to resolve this issue. For example, you can use the hackage method to build the package.

Q: What are the benefits of using a different build method?

A: Using a different build method can provide several benefits, including:

  1. Improved reliability: Using a different build method may improve the reliability of the build process.
  2. Increased flexibility: Using a different build method may provide more flexibility in terms of the build options and settings.
  3. Better performance: Using a different build method may improve the performance of the build process.

Q: Can I use a different compiler to resolve this issue?

A: Yes, you can use a different compiler to resolve this issue. For example, you can use a different version of GHC or a different compiler altogether.

##: What are the benefits of using a different compiler?

A: Using a different compiler can provide several benefits, including:

  1. Improved reliability: Using a different compiler may improve the reliability of the build process.
  2. Increased flexibility: Using a different compiler may provide more flexibility in terms of the build options and settings.
  3. Better performance: Using a different compiler may improve the performance of the build process.

Q: What are the next steps to resolve this issue?

A: To resolve this issue, further investigation is needed to determine the root cause of the problem. This may involve:

  1. Analyzing the logs: Analyzing the logs to determine the exact cause of the internal error.
  2. Testing with different compilers: Testing with different compilers to determine if the issue is specific to GHC 9.12.2.
  3. Testing with different targets: Testing with different targets to determine if the issue is specific to the aarch64-multiplatform-musl target.
  4. Disabling CPP: Disabling CPP to determine if the issue is related to CPP.

By following these steps and possible solutions, we can resolve the issue of cross-compiling to aarch64-multiplatform-musl failing with CPP.