Bug#539496: armel llvm-gcc-4.2-generated executables give illegal instruction on armv4t CPUs

Martin Guy martinwguy at gmail.com
Sat Aug 1 13:18:01 UTC 2009


Package: llvm-gcc-4.2
Version: 2.2-1

Hi, and thanks for packaging a great compiler!
I just found one fairly simple portability problem on armel architecture:

The minimum ARM ISA that Debian armel runs on is  armv4t, and Debian
armel gcc by default generates armv4t output but executables created
with llvm-gcc die on armv4t CPUs with "Illegal instruction",
specifically "clz" (which is armv5t and above).

Although llvm itself seems to be correctly generating armv4t code by
default (checked by seeing the default arch setting in the llvm source
and by scanning all .o's in a LAME build), the version of libgcc.a
that it links against has been compiled for armv5t, and contains "clz"
instructions in the libgcc integer div(/mod) and softfloat support
functions:
__aeabi_{uidiv,uidivmod,idiv,idivmod,l2f}
__umodsi3 __modsi3 __adddf3 __addsf3

Repeat-by (on an armv4t host):
cat > c.c << EOF
main() {return foo(2);}
foo(int a) { return(12/a);}
EOF
llvm-gcc c.c
./a.out

Illegal instruction

To identify all affected libraries installed on an armel system:

    find /usr/lib/llvm -name '*.a' | while read a
    do
        objdump -d $a | egrep -q '\<clz\>' && echo $a
    done

/usr/lib/llvm/gcc-4.2/lib/gcc/arm-linux-gnueabi/4.2.1/kext/libgcc.a
/usr/lib/llvm/gcc-4.2/lib/gcc/arm-linux-gnueabi/4.2.1/static/libgcc.a
/usr/lib/llvm/gcc-4.2/lib/gcc/arm-linux-gnueabi/4.2.1/libgcc.a
/usr/lib/llvm/gcc-4.2/lib/libstdc++.a

It looks from the llvm scripts that it is building a native GCC and
using that to compile the gcc libraries. If so, the following may be
relevant:
I know that the GCC source as supplied defaults to armv5t for ARM-EABI
and that Debian gcc has a patch to fix this (attached).
If the llvm-gcc build script builds a native version of gcc and builds
the GCC libraries using that, then adding a version of this to the
llvm-gcc debian patches should sort it out.

I'm assuming 2.5 has the same problem as 2.2, since the debian
changelog says nothing about this.

There is a 600MHz 512MB armv5t Debian armel box here that can be used
for compiling and a 200MHz 64MB armv4t board for testing, both on 24/7
and accessible via ssh. If that would be useful, please write
privately suggesting a username.

Cheers

   M
-------------- next part --------------
A non-text attachment was scrubbed...
Name: arm-unbreak-eabi-armv4t.dpatch
Type: application/octet-stream
Size: 1014 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/pkg-llvm-team/attachments/20090801/63084adf/attachment.obj>


More information about the Pkg-llvm-team mailing list