Clang for ARM Cortex A9

Hi,
We are facing a strange problem with Clang compiler (latest version) for ARM Cortex A9.

When we compile our code using arm-linux-gcc compiler, it compiles perfectly and executes perfectly as well.
When we compile using clang compiler, it compiles but during execution we see certain floating point values overflow. The program still finishes execution but the final output is wrong.

However on x86, both Clang and gcc give no errors.
Since the code base is same we suspect that code generation by clang for ARM is not correct.

Has anyone else faced this problem? Please kindly suggest any solutions.

Thanks and regards,
Kiran.V

It’s certainly possible. It’s also possible that your code is doing something invalid and the LLVM optimizers are being more aggressive about exploiting it. If you can provide a test case, we’ll look at it.

John.

Hello

When we compile using clang compiler, it compiles but during execution we
see certain floating point values overflow. The program still finishes
execution but the final output is wrong.

What is the version of binutils you're using?

Hi,
Thanks for the reply.
The binutils version I am using is 2.19.1-0ubuntu3.
We managed to work around for this problem.
First we converted C code using clang to llvm byte code (-S -emit-llvm), then we converted the llvm bytecode to C file using llc.
Then we used arm-linux-gcc to compile the resulted C file. This seems to work and generated the correct output.

Any other solution is welcome.

regards,
Kiran.V

Hello

The binutils version I am using is 2.19.1-0ubuntu3.

This version is known buggy (it encodes "vcvt" instruction improperly,
thus you'll have wrong int <-> float conversion).
You need to use at least 2.20.1 (or anything else which is newer than
of Jan, 2010).

Hi,
Can I know why binutils is comming into picture. I will give the detailed description of what we have done:

We downloaded the clang source code from http://clang.llvm.org/get_started.html and build clang compiler.
With this clang compiler we try to build the source code using the commands

clang -march=armv7-a -mcpu=cortex-a9 -ccc-host-triple arm-none-linux -ccc-gcc-name arm-none-linux-gnueabi-gcc filename.c
(with relevant include and libraries).

To my knowledge binutils will be used by gcc and not by clang.

regards,
Kiran.V

When you compile with the clang driver, you have several components:

1) clang compiles [Objective-]C[++] code to LLVM IR
2) LLVM optimises this code and converts it to assembly (except on the platforms which have native code generation working)
3) as (from binutils) assembles the assembly into a .o file.
4) ld (from binutils) links these .o files into an executable or shared library.

In this specific case, as Anton said, LLVM is producing the vcvt (vector convert) instruction in the assembly and as is generating the wrong binary encoding of this instruction in the .o.

David