Generate Executable to Mips

Hi,
How can I generate executable to mips with llvm-gcc.
I’m using Ilvm-2.9, X86PC and the following commands:

llvm-gcc -emit-llvm hello.c -c -o hello.bc (OK)
llc -march=mips hello.bc -o hello.s (OK)

gcc hello.s -o hello (does not work).

Thanks,

This is true?
clang/llvm cannot produce mips object code or executable (yet).

You will need to install a cross compiler.
I think you can find one somewhere in this link:
https://sourcery.mentor.com/GNUToolchain/

Once you have a cross compiler, this should do what you want (if you
want little-endian code):

clang -target mipsel-unknown-linux -ccc-clang-archs mipsel -O3
hello.c -o hello.bc -emit-llvm
llc -march=mipsel hello.bc -o hello.s
mips-linux-gnu-gcc hello.s -o hello -mips32 -EL

You can also generate object code with this command:

llc -march=mipsel hello.bc -o hello.o -filetype=obj

Then run the linker:
mips-linux-gnu-gcc hello.o -o hello -mips32 -EL

Thanks Akira,
it worked!

There is also:

  1. an alternate clang driver at http://code.google.com/p/alternate-clang-driver/ . This makes
    it more or less gcc compatible.

  2. there is a way to invoke it all directly with just a call to clang as is with x86/linux but it’s not totally
    finished. i will try and post something about this. the direct form will work if you are on a
    mips linux machine but there are still some issues running it as a cross.

Well, in principle it should be enough to make a symlink from clang to
mips-linux-gnu-clang and use that, if you also have mips-linux-gnu-ld and
mips-linux-gnu-as. Some fine tuning for the detection of crt*.o
locations might be needed, but -B ${PATH_TO_CRT1_O} etc can workaround
that as well.

Joerg

Great Job!
If I use alternate-clang-driver, will I need mips-gcc still?
I mean alternate-clang-driver use as&ld directly or by calling gcc?

Regards,
Jia Liu

In principle you can get rid of the dependence on mips-gcc for linking and assembly.
We just have not bothered to fix the scripts for that.

You should be able to do the last step with as and ld.
If you are using the direct object emitter, then you only need ld.

You can join the googlecode for that project as a developer and check in your changes
if you get that working.