[LLVMdev] cross compiling with the C backend

Kevin André
Mon, 18 Feb 2008 16:09:36 -0000

For my master's thesis, I am trying to cross compile programs for the
PSP (PlayStation Portable) with LLVM and llvm-gcc.

This is what I do:

(1) compile a program and the libraries it uses (libpng etc.) with llvm-gcc
(2) link the bitcode files with llvm-ld into one file
(3) run "llc -march=c" on the result
(4) compile the resulting C source with the PSP toolchain

It seems to work with a very simple program (Pi_Calc, calculates Pi
and prints it), but it fails when I try it with another program that
is a bit more advanced: the PSP hangs when I run the program.

Am I using the right approach here? I have compiled llvmgcc-4.2-2.2 on
my machine as a native compiler (i686-pc-linux-gnu). Does llvm-gcc
have an impact on the portability of the resulting LLVM bitcode? And
is the C code generated by the C backend really portable? I use the
"-nostdinc" option for llvm-gcc and specify the include paths of the
PSP SDK instead. But I still get warnings with llvm-gcc that do not
appear with psp-gcc ("passing argument 2 of 'xyz' discards
qualifiers
from pointer target type"). And the output of the C back end generates
lots of warnings as well, or is that expected?

What could solve this problem? Do I have to configure llvm-gcc as a
cross compiler? MIPS might be a better candidate than the 'i686' from
the native configuration. Or could it be simply a bug in llvm-gcc or
LLVM?

Another option could be to add real support for the PSP to LLVM,
though I'm not sure if I'll be able to accomplish that.


Regards,

-Kevin André