Question

The Raspberry Pi takes a lot of time to compile C code. I want to accelerate that compilation. But I get a compilation error.

To do that, and because I already code on my PC, I want to use my PC, I would like to use LLVM (shipped with cygwin) to produce an LLVM assembly language version of the executable. And then, send it to the Raspberry Pi for final conversion to a native (ARM) executable.

I am hoping to get to a executable a lot faster because I could compile to LLVM language my code in parallel on my multi-core machine before linking (llvm-link). The last step on the Raspberry Pi itself, translating LLVM language to executable binary would be short, I hope.

Let's take an example code:

#include <stdio.h>

int main(){
  printf("0");
  return 0;
}

Then on my PC, I run

clang a.c -emit-llvm -S

This produces a file called a.s an LLVM language version of the .c file

And then, I send a.s to the Raspberry Pi and run on it the command llc -filetype=obj a.s to generate a.s.o an object file.

But when I want to create an executable on the Rasp Pi from this object file, I get an error:

clang a.s.o -o a.out
/usr/bin/ld: error: a.out uses VFP register arguments, a.s.o does not
/usr/bin/ld: failed to merge target specific data of file a.s.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I tried using the following flags -marm -mfloat-abi=hard -mfpu=vfp with clang on the last step but that fails with the same errors. Do you know how to solve this error or have some suggestions that would help me using LLVM to speed up my compilation process?

Thanks in advance

Was it helpful?

Solution

LLVM IR is not portable. It contains all sorts of things spercific to your machine (is an int 32 bit or 64 bit, sizeof and calling conventions). In order to get this to work you need to pass clang arguments as if you are doing a full cross compile. At which point because clang is a full cross compilier you might as well just compile object files.

So compile object files with clang -target armv6-linux-gnueabi -integrated-as -marm -mfloat-abi=hard -mfpu=vfpu -c on your pc then link on the pi using ld.

Edit:

Since you mention the cygwin clang integrated assembler doesn't work the best option is to output arm assembly with: clang -target armv6-linux-gnueabi -marm -mfloat-abi=hard -mfpu=vfpu -S

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top