Cross compiling to ARM using LLC {Help}

Hello,

I’m trying to cross compile the MiBench benchmarks using LLC and ARM cross compiler the binaries generated will be used on pandaboard or the qemu-arm emulator.

I have faced multiple issues during the compilation process, here are the commands used.

generate LLVM-IR for dijkstra_large.c

$gcc -S -flto -o dijkstra_large.bc -fplugin=${DRAGONEGG} dijkstra_large.c

generate TARGET object file for dijkstra_large.bc

$./llc -march=arm -mcpu=cortex-a9 dijkstra_large.bc -o dijkstra_large.o -filetype=obj -O3

Generate executalbe using Target’s toolchain

$arm-linux-gcc -static dijkstra_large.o -o dijkstra_large

The first issue is that the arguments that I use as an input to dijkstra benchmark do not get inserted in their appropriate position in the [argv] array. In order to run the benchmark the command is ./dijkstra_large input.dat. using this command I got the argv[1] = null which should be input.dat. If I add another extra argument between the benchmark binary name and the input.dat arugment like (./dijkstra_large xxx input.dat) the benchmark works without any error and the argv[1] equals the input.dat. This issue is preventing me from using other benchmarks which needs multiple arguments to run.

The second issue is that when I use “arm-linux-gnueabihf-gcc” cross compiler instead of the arm-linux-gcc I get the following error

“/usr/lib/gcc/arm-linux-gnueabihf/4.6/…/…/…/…/arm-linux-gnueabihf/bin/ld: error: a.out uses VFP register arguments, dijkstra_large.o does not
/usr/lib/gcc/arm-linux-gnueabihf/4.6/…/…/…/…/arm-linux-gnueabihf/bin/ld: failed to merge target specific data of file dijkstra_large.o
collect2: ld returned 1 exit status”

I have tried to change the -mfloat-abi to hard or soft but still getting the same error message. Is there any other options that forces the llvm to use VFP registers?

Also it would be nice if anyone can point me to a tutorial which shows how to build LLVM cross compiler using the clang.

Thanks,
Najem.

Hi Najem,

# generate LLVM-IR for dijkstra_large.c
$gcc -S -flto -o dijkstra_large.bc -fplugin=${DRAGONEGG} dijkstra_large.c

Is your GCC configured as an arm-linux-gnueabihf compiler? If not,
it's almost certainly going to be getting ABI details wrong. I'm
slightly surprised that it affects argv, but it's certainly the first
thing to think about.

# generate TARGET object file for dijkstra_large.bc
$./llc -march=arm -mcpu=cortex-a9 dijkstra_large.bc -o dijkstra_large.o -filetype=obj -O3

If Dragonegg *is* generating for ARM then the "-march=arm" option to
llc should be unnecessary.

Also, GCC should probably have "-O3" as well, since llc is the backend
code generator and doesn't run the mid-end phases.

# Generate executalbe using Target's toolchain
$arm-linux-gcc -static dijkstra_large.o -o dijkstra_large

I've not seen an arm-linux-gcc before, so I'm slightly worried about
what ABI it's using (-gnu, -gnueabi or -gnueabihf).

The second issue is that when I use "arm-linux-gnueabihf-gcc" cross compiler
instead of the arm-linux-gcc I get the following error

Also it would be nice if anyone can point me to a tutorial which shows how
to build LLVM cross compiler using the clang.

That sounds like a very good idea. For a start there are far more
people here who know how to get clang to cooperate than DragonEgg
(I've never even built DragonEgg, for example). We've got a couple of
documents on that topic:

http://llvm.org/docs/HowToCrossCompileLLVM.html
http://clang.llvm.org/docs/CrossCompilation.html

They're not perfect by any means yet (still fairly new), but it'd be
great to hear your experiences trying to follow them so we can improve
things.

Cheers.

Tim.