Template Haskell linking/loading broken on aarch64 Linux
With GHC 8.10.7 on aarch64 Linux, Template Haskell sometimes tries to load symbols from dependency DSOs that aren't there. The only package I've found so far that produces this problem is accelerate-llvm
. The following is the (admittedly quite large) repro setup:
- Clone rev
0dec9b4deeb86a28fe89fb330f93aa025ef38745
ofhttps://github.com/acceleratehs/accelerate-llvm
- In the
accelerate-llvm
subdirectory, use thisshell.nix
:
let pkgsrc = builtins.fetchGit
{
url = "https://github.com/nixos/nixpkgs";
ref = "nixos-21.05";
rev = "372e59d2af704bffd133cbe029f1d5efe73ba6fb";
};
pkgs = import pkgsrc {};
d = with pkgs; runCommand "test"
{
buildInputs = [ cabal-install haskell.compiler.ghc8107 ];
} "";
in d
and this cabal.project
:
packages: .
source-repository-package
type: git
location: https://github.com/TravisWhitaker/accelerate
tag: dc3bea3bdc0f63658daefd68bd3cb27954c3ba1d
All I've done in this fork of the accelerate dependency is change the cabal file a bit so that I can reference it as a source-repository-package (without those changes, cabal complains about some missing generated doctest files).
-
cabal build -j
and (eventually) observe this error:
[ 3 of 59] Compiling Data.Array.Accelerate.LLVM.Link.Tracy ( src/Data/Array/Accelerate/LLVM/Link/Tracy.hs, /home/anduril/sources/accelerate-llvm/accelerate-llvm/dist-newstyle/build/aarch64-linux/ghc-8.10.7/accelerate-llvm-1.3.0.0/build/Data/Array/Accelerate/LLVM/Link/Tracy.o, /home/anduril/sources/accelerate-llvm/accelerate-llvm/dist-newstyle/build/aarch64-linux/ghc-8.10.7/accelerate-llvm-1.3.0.0/build/Data/Array/Accelerate/LLVM/Link/Tracy.dyn_o )
<command line>: /home/anduril/.cabal/store/ghc-8.10.7/accelerate-1.3.0.0-aa96bd337a471d03fadf8b886242c986d3f72358021163a7aa3e87f9da7de420/lib/libHSaccelerate-1.3.0.0-aa96bd337a471d03fadf8b886242c986d3f72358021163a7aa3e87f9da7de420-ghc8.10.7.so: undefined symbol: c6YS2_closure
I was suspicious of the TH-time loading of the tracy
library that the TH in this module was doing, but if I stub it out I get a similar failure on a much more innocuous TH usage later on. Here's the TH part of that module:
instance Downcast (IntegralType a) LLVM.Type where
downcast TypeInt = LLVM.IntegerType $( [| fromIntegral (finiteBitSize (undefined :: Int)) |] )
downcast TypeInt8 = LLVM.IntegerType 8
downcast TypeInt16 = LLVM.IntegerType 16
downcast TypeInt32 = LLVM.IntegerType 32
downcast TypeInt64 = LLVM.IntegerType 64
downcast TypeWord = LLVM.IntegerType $( [| fromIntegral (finiteBitSize (undefined :: Word)) |] )
downcast TypeWord8 = LLVM.IntegerType 8
downcast TypeWord16 = LLVM.IntegerType 16
downcast TypeWord32 = LLVM.IntegerType 32
downcast TypeWord64 = LLVM.IntegerType 64
And the build error:
[13 of 59] Compiling LLVM.AST.Type.Downcast ( src/LLVM/AST/Type/Downcast.hs, /home/anduril/sources/accelerate-llvm/accelerate-llvm/dist-newstyle/build/aarch64-linux/ghc-8.10.7/accelerate-llvm-1.3.0.0/build/LLVM/AST/Type/Downcast.o, /home/anduril/sources/accelerate-llvm/accelerate-llvm/dist-newstyle/build/aarch64-linux/ghc-8.10.7/accelerate-llvm-1.3.0.0/build/LLVM/AST/Type/Downcast.dyn_o )
<command line>: /home/anduril/.cabal/store/ghc-8.10.7/accelerate-1.3.0.0-aa96bd337a471d03fadf8b886242c986d3f72358021163a7aa3e87f9da7de420/lib/libHSaccelerate-1.3.0.0-aa96bd337a471d03fadf8b886242c986d3f72358021163a7aa3e87f9da7de420-ghc8.10.7.so: undefined symbol: c6YS2_closure
This exact same setup builds fine on x86_86 Linux and x86_64 Darwin. This same setup builds just fine with GHC 8.8.4.
Edit:
Building accelerate
with -O0
(instead of its default -O2
) allows the Template Haskell in accelerate-llvm
to run successfully.