LLVM and little-endian 32-bit MIPS code generation

We are trying to use LLVM (Clang as the C frontend) to generate code for 32-bit MIPS (little-endian)l, which can run on simplescalar 3.0 sslittle-na-sstrix platform. Can you advise what would be the right way to use the LLVM compiler infrastructure?

The following is the one I used, but it appears that it produce the code in big-endian (and I wonder whether the calling convention is right.) To check the correctness of code generation in a quick and dirty way, I don’t invoke LLVM “opt”

(1) clang -emit-llvm hello.c -S -o hello.ll
(2) llvm-as hello.ll
(2) llc -march=mips hello.bc

Thanks in advance.

It will produce little-endian code if you replace “mips” with “mipsel”.

  1. clang -ccc-host-triple mipsel-unknown-linux -ccc-clang-archs mipsel -O3 -S -emit-llvm foo.c -o foo.ll
  2. llc -march=mipsel -mcpu=4ke foo.ll -o foo.s (the -march option is redundant)

If you do not specify the target cpu with -mcpu, by default it will generate code for Mips1, which has not been tested as thoroughly as Mips32r2 (-mcpu=4ke) or Mips2 (-mcpu=mips2).

The default ABI is o32.


We have tried and generate assembly code for very simple test C code. But, binutils-2.5.2 (simplesim-3.0) cannot handle the produced assembly code with the following complaints. Could you advise which version of bitutils that we need to use for mips code with LLVM with Clang? Thanks,

$ GCC addr01.s
addr01.s: Assembler messages:
addr01.s:1: Error: Unknown pseudo-op: .section' addr01.s:2: Error: Unknown pseudo-op: .previous’
addr01.s:3: Error: Bad expression
addr01.s:3: Warning: Missing string
addr01.s:3: Error: Rest of line ignored. First ignored character is a'. addr01.s:3: Error: Rest of line ignored. First ignored character valued 0x9. addr01.s:6: Warning: .type pseudo-op used outside of .def/.endef; ignored addr01.s:6: Error: Rest of line ignored. First ignored character is f’.
addr01.s:9: Warning: Unrecognized register name
addr01.s:17: Error: ERROR: Illegal operands sw $ra,28($sp)' addr01.s:19: Warning: Instruction addiu requires absolute expression addr01.s:19: Error: ERROR: Illegal operands addiu $5,$zero,1’
addr01.s:21: Error: Bad expression
addr01.s:21: Error: Bad expression

Something released in the last 10 years maybe? Just download something recent from gnu.org and you should be fine.



We would like to assemble .s file using binutils-2.5.2 which comes with simple-scalar3.0. Unfortunately, this particular version of binutils doesn’t seem to handle global-offset-table (position independent code) and the some of the mips instructions. Thanks,

There's nothing I can say here other than to upgrade. You're using a version of binutils released before 1996. Seriously.