Skip to content

GHC creates invalid test instruction for 64-bit code

When compiling the cpuid package from Hackage (http://hackage.haskell.org/cgi-bin/hackage-scripts/package/cpuid), Don Stewart noticed that compilation aborts on a 64-bit Linux box with the following error message:

Error: suffix or operands invalid for test'`

Examining the assembler code, we see that the instruction

testq $2147483648,%rax

is generated, but test is only allowed to take a 32-bit immediate operand.

Don's compilation info follows:

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.8.2

$ gcc --version
gcc (GCC) 4.3.1
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ uname -msr
Linux 2.6.25-ARCH x86_64

    $ cabal install cpuid
    Resolving dependencies...
    Downloading cpuid-0.2...
    Configuring cpuid-0.2...
    Preprocessing library cpuid-0.2...
    Building cpuid-0.2...
    [1 of 1] Compiling System.Cpuid     ( System/Cpuid.hs, dist/build/System/Cpuid.o )
    /tmp/ghc23771_0/ghc23771_0.s: Assembler messages:

    /tmp/ghc23771_0/ghc23771_0.s:3254:0:
         Error: suffix or operands invalid for `test'
    cabal: Error: some packages failed to install:
    cpuid-0.2 failed during the building phase. The exception was:
    exit: ExitFailure 1

Checking the temp files, this is generated:

    $ runhaskell Setup.lhs configure --ghc-options=-keep-tmp-files
    $ runhaskell Setup.lhs build                                  
    Preprocessing library cpuid-0.2...
    Building cpuid-0.2...
    [1 of 1] Compiling System.Cpuid     ( System/Cpuid.hs, dist/build/System/Cpuid.o )
    /tmp/ghc9500_0/ghc9500_0.s: Assembler messages:

    /tmp/ghc9500_0/ghc9500_0.s:3254:0:
         Error: suffix or operands invalid for `test'
    $ vim /tmp/ghc9500_0/ghc9500_0.s +3254


    s3TR_info:
        addq $208,%r12
        cmpq %r15,%r12
        ja .Lc3W2
        movq 7(%rbx),%rax
        testq $2147483648,%rax
        je .Lc3W4
        movq 8(%rbp),%rsi
        addq $16,%rbp
        addq $-208,%r12
        jmp r2By_info
Trac metadata
Trac field Value
Version 6.8.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information