Porting ghc to a new platform

I need to port ghc compiler to the new platform based on the cpu which currently is not supported. How can I do it by cross-compiling?

1 Like

I’d start by looking here:

I’ve modified the checkArch() function in aclocal.m4 and run autoreconf, but then I have the following error:

$ ./configure --target=e2k-unknown-linux-gnu –enable-unregisterised

checking for e2k-unknown-linux-gnu-objdump… no
checking for e2k-unknown-linux-gnu-gcc… no
checking for e2k-unknown-linux-gnu-clang… no

checking for e2k-unknown-linux-gnu-ar… no
configure: error: cannot find ar in your PATH, no idea how to make a library

Does it mean that configure script is looking for C compiler and related tools that generate code for my target platform to be run on my build platform?

1 Like

I’m no expert on porting GHC, but it indeed looks that way.

1 Like

the RTS is compiled and linked to all haskell executables and a significant chunk of the RTS is written in C, i am certain it is impossible to use a cross-compiling GHC without a cross-compiling C toolchain

2 Likes

The problem is that contemporary Haskell needs GHC to be build. So essentially everybody out there either just downloads a binary distribution of GHC or they build GHC from source, using a possibly older (but not much) version of GHC that they already have. When building the GHC package, the builders use, well, the GHC package. Obviously, even GHC does not exist since the beginning of time, and the first versions surely were built using something else than GHC.

The oldest version of GHC you can find on the GHC web page is version 0.29. But the installation instructions write:

  • GHC 0.26 is best built with itself, GHC 0.26. We heartily recommend it. GHC 0.26 can certainly be built with GHC 0.23 or 0.24, and with some earlier versions, with some effort.
  • GHC has never been built with compilers other than GHC and HBC.

So it seems that besides GHC, only ever HBC was used to compiler GHC, but I’m unable to find any HBC sources

1 Like

Can’t you just use any existing binary version? My knowledge about Elbrus and VLIW in general is very limited, but according to wikipedia you can install Linux (ELF) and and utilize x86 ISA.

No, I cant use existing binaries, ghc is dynamically linked and ldd shows me a whole lot of different external references

i don’t know if they removed it yet but i know there was a time you could compile from Source a Unregistered GHC that compiles haskell into extremely slow C code and it was said that this was mostly done to port to new architectures

EDIT:
https://ghc.gitlab.haskell.org/ghc/doc/users_guide/codegens.html#c-code-generator-fvia-c

1 Like

I think that’s already what --enable-unregisterised does.