[Haskell-cafe] Will GHC 6.14 with LLVM use LLVM C compiler to compile external C Libraries

David Terei dave.terei at gmail.com
Thu Sep 9 21:01:20 EDT 2010

On 9 September 2010 22:10, Mathew de Detrich <deteego at gmail.com> wrote:
> It should also hopefully make using Haskell packages on windows that use C
> sources less painful
> Clang could also make using FFI with C++ much easier (for reasons stated
> above)
> Thoughts?

I don't think it would make it any easier to use C/C++ from Haskell at
the moment. LLVM for static compilation works by
compiling to assembly. After that it has no support. So we use gcc to
finish off the rest of the job; producing object code and linking.
There is a pretty cool project going on in LLVM at the moment of
integrating an assembler into LLVM so that it can directly produce
object code. This should mean that the LLVM backend wouldn't need gcc
anymore (but obviously gcc will still be needed by ghc as a whole).

As David Peixotto mentioned though, the ghc runtime can't be built by
clang. There is probably a few reason but a main one is that Clang
doesn't support gcc's global register variable extension (register
pinning). The LLVM guys also have no plans to support this feature so
unless we want to stop using this extension we are stuck with using gcc.

I think the main advantage to trying to use Clang for compiling C/C++
would be that it would enable us to do whole program optimisation
across Haskell and C/C++. It could also make cross compiling slightly
easier. These ideas are defiantly something I'd like to investigate
more in the future.

On 10 September 2010 10:08, John Lask <jvlask at hotmail.com> wrote:
> In fact I would like a lot more information on what is being proposed with
> respect of a LLVM backend and any changes to the compiler tool chain.

What would you like to know? If you're talking just about the new LLVM
backend for GHC (not the proposal here of using clang) then the effect
on the end user is nothing. The LLVM backend compiles an individual
Haskell module to LLVM assembly, which is then compiled to native
assembly by the 'llc' tool. This gets you now to the same place as the
native code generator, where gcc is used to compiled the assembly to
an object file. Obviously there is a new dependency on having LLVM 2.7
or greater installed but that should be it.


More information about the Haskell-Cafe mailing list