I'm not against working on this but first we need to have properly working x64-linux -> arm-linux cross-compiling tool chain on place which I'm not sure if it's working or not. So I mark this as blocking on #7623 (closed) for now.
I'm using linaro here for this, but the question is not about C cross-compilation tool-chain but about GHC LLVM-based cross-compilation support. If this is ready and working at least for ARM (as the most used cross-compilation target), then let's start working on it. If not, then let's first solve this homework...
for llvm or NCG?
for NCG, its kinda gated on first doing some NCG cleanup, (because theres a lot of copy pasta logic across the current NCG backends, and improving the engineering niceness of NCG will make such easier).
please feel welcome to hack out a prototype if you have the time, but please keep in mind that it may be easier after first cleaning up and refactoring NCG.
I *hope* to have the time to start hacking on that refactoring end of january onwards, though i hope other people collab on it too.
that said, if you mean LLVM specifically, go crazy! I think there may be some experimental support on GHC-IOS, but I could be wrong
sounds reasonable. Will the arm 32 bit ghc calling convention make sense for AArch64? We may need to get a patch into llvm before having a distinct aarch64 abi. (and we should probably do some pretty thorough benchmarking before picking any such ABI)
sounds reasonable. Will the arm 32 bit ghc calling convention make sense for AArch64? We may need to get a patch into llvm before having a distinct aarch64 abi. (and we should probably do some pretty thorough benchmarking before picking any such ABI)
Not at all! aarch64 abi is completely different with completely different (or better nicely extended) register stack! So basically aarch64 is completely different beast than arm and I'm also doing it separately instead of extending current arm support.
W.r.t. benchmarking, I've also had such discussion with David few year ago, but then Stephen comes with work done so no benchmarking was done. The point is to find some sweet-spot inbetween using callee-saved regs for STG regs pinning and between leaving them for LLVM business usage...
Anyway, as I said, we're not there yet, although I already do have some code here. The problem is LLVM/AArch64 is not there yet as you can see from my bug report here: http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-January/069248.html and that is just unregisterised build...
@karel,
unregisterized builds use GCC specific C code, in which case you'll have to use GCC.
GCC 4.8 and newer, when built with multi target support, seems to have aarch 64 support.
clang/llvm wont work.
cheers
-Carter
Carter, this is misunderstanding IMHO. I'm not dealing with unregisterised via C, but instead with unregisterised via LLVM build here. Please read the GHC/LLVM porting document I linked above for more information.
Good! So this LLVM bug above shows only on PrimoptWrappers and I've been able to compile this file without -fllvm as Carter points out above. So here is bindist's HelloWorld running on AArch64/ARM64 platform:
root@localhost:~# ./HelloWorld Hello world!root@localhost:~# file HelloWorld HelloWorld: ELF 64-bit LSB executable, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.7.0, BuildID[sha1]=0x5301662c82ccd3fe7c3f1486ac10d0f13b2f54c9, not strippedroot@localhost:~# uname -maarch64root@localhost:~#
I've been working with Karel Gardas (kgardas) to get this going, and I've now completed an unregisterised GHC bootstrap on Ubuntu arm64. I started by cross-building GHC 7.8 using variations on Karel's patch set, and then bodged together a GHC 7.6 build (since that's what we're shipping on other architectures) bootstrapping off that. This all now appears to be working fine and I should be able to get binaries into our archive in the next few days.
I'm attaching a patch (made against the ghc-7.8 branch); most of it is Karel's from https://ghcarm.wordpress.com/2014/01/18/unregisterised-ghc-head-build-for-arm64-platform/, I've just tweaked it a bit given that I had the advantage of access to real hardware. Some of this may be unnecessary for an unregisterised build, but it doesn't hurt. It would be great if somebody could review and apply it, since it's a lot easier to get started on more advanced things like LLVM or NCG support if you don't have to do the time-consuming bootstrap yourself. Please note that you also need to update the embedded copy of libffi in libffi-tarballs/ to at least version 3.0.12.
Karel's initial patch caused GHC_CONVERT_CPU to return arm64. I changed this to aarch64, since the return value of GHC_CONVERT_CPU is used to construct the --host option for configure scripts and thus it needs to be valid as the first part of a GNU config triplet. I left the Haskell-level architecture name as ArchARM64, since that style is more common as a user-facing name for the architecture: for example, the Linux kernel returns arm64 in its uname output.
Colin, thanks for submitting this. Indeed, I think for basic unregisterised build to work changes done in includes/stg/ and rts/ may be omitted for now. Those are my experimental bits kind of start of a work on registerised support...
Right. I thought that was probably the case, but I didn't really want to do yet another build that omitted them in order to make sure, since it all takes a while as it is!
Yep, I'm using Ben's branch to get LLVM HEAD working in general. I can get a build to complete just fine if I mangle the ASM in StgCRun.c but haven't made it actually work yet.
I'm not sure that 3.4 has full ARM64 support (i.e. works on iOS)...
So basically you try to cross-compile using registerised GHC? If so, then I'm afraid nobody hacked LLVM to support GHC specific calling convention on ARM64 yet! If unregisterised, then you IMHO you should not be in this part of code which is IMHO just for registerised builds. Also if you attempt unregisterised, I would advice to use gcc and not llvm i.e. -fvia-C and not -fllvm for the start.
One general note: the code in StgCRun written for ARM64 was probably written by me (I've provided the patch to Colin). So if this is this code, then please be assured that this code *never* has run on ARM64. It was written just from reading doc and as a first attempt to add support for registerised ARM64. At that time I've finished with this since I had not machine, ARM's foundation model was really slow and LLVM project was just before big merge from ARM's own AArch64 and Apple's own ARM64 LLVM backends together.
Although the situation now looks way much better, at least both LLVM backends were merged together and even some hardware appears this all still means that if nobody has done it yet, then someone needs to do quite a lot. When I've been working on ARM port with Stephen, David helped me a lot and we wrote following LLVM/porting guide. I would recommend to read it: https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler/Backends/LLVM/GHC_LLVMPorting
Likely I should open a new ticket, but I am having trouble with
installing ghc-7.8.3 plus above patch on Fedora 21 ARM64 (aarch64).
"inplace/bin/ghc-cabal" copy libraries/haskell2010 dist-install "strip" '/builddir/build/BUILDROOT/ghc-7.8.3-38.fc22.aarch64' '/usr' '/usr/lib64/ghc-7.8.3' '/usr/share/doc/ghc/html/libraries' 'v dyn 'Installing library in/builddir/build/BUILDROOT/ghc-7.8.3-38.fc22.aarch64/usr/lib64/ghc-7.8.3/haskell2010-1.1.2.0"/builddir/build/BUILDROOT/ghc-7.8.3-38.fc22.aarch64/usr/lib64/ghc-7.8.3/bin/ghc-pkg" --force --global-package-db "/builddir/build/BUILDROOT/ghc-7.8.3-38.fc22.aarch64/usr/lib64/ghc-7.8.3/package.conf.d" update rts/dist/package.conf.installReading package info from "rts/dist/package.conf.install" ... done.rts-1.0: Warning: library-dirs: /usr/lib64/ghc-7.8.3/rts-1.0 doesn't exist or isn't a directoryrts-1.0: Warning: include-dirs: /usr/lib64/ghc-7.8.3/include doesn't exist or isn't a directoryrts-1.0: cannot find any of ["libHSrts.a","libHSrts.p_a","libHSrts-ghc7.8.3.so","libHSrts-ghc7.8.3.dylib","HSrts-ghc7.8.3.dll"] on library path (ignoring)"inplace/bin/ghc-cabal" register libraries/ghc-prim dist-install "/builddir/build/BUILDROOT/ghc-7.8.3-38.fc22.aarch64/usr/lib64/ghc-7.8.3/bin/ghc" "/builddir/build/BUILDROOT/ghc-7.8.3-38.fc22.aarch64/usr/lib64/ghc-7.8.3/bin/ghc-pkg" "/builddir/build/BUILDROOT/ghc-7.8.3-38.fc22.aarch64/usr/lib64/ghc-7.8.3" '/builddir/build/BUILDROOT/ghc-7.8.3-38.fc22.aarch64' '/usr' '/usr/lib64/ghc-7.8.3' '/usr/share/doc/ghc/html/libraries' NO Warning: cannot determine version of/builddir/build/BUILDROOT/ghc-7.8.3-38.fc22.aarch64/usr/lib64/ghc-7.8.3/bin/ghc-pkg:""Registering ghc-prim-0.3.1.0..."inplace/bin/ghc-cabal" register libraries/integer-gmp dist-install "/builddir/build/BUILDROOT/ghc-7.8.3-38.fc22.aarch64/usr/lib64/ghc-7.8.3/bin/ghc" "/builddir/build/BUILDROOT/ghc-7.8.3-38.fc22.aarch64/usr/lib64/ghc-7.8.3/bin/ghc-pkg" "/builddir/build/BUILDROOT/ghc-7.8.3-38.fc22.aarch64/usr/lib64/ghc-7.8.3" '/builddir/build/BUILDROOT/ghc-7.8.3-38.fc22.aarch64' '/usr' '/usr/lib64/ghc-7.8.3' '/usr/share/doc/ghc/html/libraries' NO Warning: cannot determine version of/builddir/build/BUILDROOT/ghc-7.8.3-38.fc22.aarch64/usr/lib64/ghc-7.8.3/bin/ghc-pkg:""ghc-cabal: Installed package ID not registered: "ghc-prim-0.3.1.0-inplace"ghc.mk:901: recipe for target 'install_packages' failedMakefile:64: recipe for target 'install' failedmake[1]: *** [install_packages] Error 1make: *** [install] Error 2
The problem seems to be that the installed (dynlinked) ghc-pkg does no output anything!
(eg "ghc-pkg --version" returns "", same for --help.)
When I try the built binaries I find that
ghc-7.8.3/utils/ghc-pkg/dist/build/tmp/ghc-pkg (which is statically linked)
works normally (ie it outputs --help and --version) whereas
DESTDIR/libdir/ghc-7.8.3/bin/ghc-pkg gives no output on stdout!
Maybe I should try installing statically linked ghc and see if that makes difference.