FW: RE: x86_64 port

Simon Marlow simonmar at microsoft.com
Mon Mar 7 06:47:31 EST 2005

On 04 March 2005 17:32, Kurt Roeckx wrote:

> I have no idea what ghc has too do with gcc,

A bit of background: GHC uses gcc as a backend compiler.  GHC generates
C code that is compiled using gcc (we also have a native code generator
for some platforms; but not for x86_64 yet).

> or what the problem exactly is.

The problem is that gcc generates incorrect code for C code that uses
global register variables.  You won't have noticed this, because most
programs don't use global register variables.  GHC uses global register
variables to speed up the generated code.

> We have very little problems with gcc for the debian
> amd64 port.  Our default compiler is still 3.3.  This builds
> almost everything without problems, however we build a few
> mozilla packages with gcc-3.4.
> All I can tell is that ghc6 seems to be working on debian amd64.
> It can build itself and things like that.

That build of ghc6 is what we call "unregisterised": it doesn't make use
of register variables to speed up the generated code.  IOW, it generates
plain ANSI C code, which gcc compiles fine.

> Can someone please give a test case (and show what to do) to see
> what is wrong?

Ok, here's a really simple example:

$ cat bug.c    
register void * R1 __asm__("%r13");

extern void g(void);
static void f(void) {
 R1 = g;
 goto *R1;
$ gcc -S -O bug.c

And take a look at the generated assembly for the function f:

        movl    $g, %eax
        jmp     *%rax

Note that the assignment to the global variable R1 has been lost.  It
works fine on x86 though: change the register variable to %esi and try

> Out current default compiler in debian is:
> gcc version 3.3.5 (Debian 1:3.3.5-8)
> The gcc 3.4 version is:
> gcc version 3.4.4 20050203 (prerelease) (Debian 3.4.3-9)
> And ghc6 is at version 6.2.2-3.

I'm going to try with different versions of gcc.  I've just submitted
this bug report to the gcc guys.


More information about the Glasgow-haskell-users mailing list