Sparc back end problem

Hi everyone,

I'm trying to make a cross-compiler based on llvm to target sparc (solaris) from x86_64 (linux). I couldn't compile llvm-gcc on my system so have to use the precompiled binaries from the website, but already have a gcc cross-compiler so can use this. So far, my compilation steps are these:

1) Preprocess the (C) sources using gcc cross-compiler
2) Use llvm-gcc to transform to llvm IR
3) Run llc to emit sparc assembly
4) Assemble and link using gcc cross-compiler

This works for a simple 'Hello World' program, but I'm getting problems when trying more complicated things. One thing in particular is with a simple printf that I want to write that prints out the size of an integer. I've attached an example program source, preprocessed source, llvm code and assembly. Instead of printing 'Value is 4' I get 'Value is 0'! I don't know sparc assembly at all, but a quick scan over the code shows that the value '4' is definitely used in an instruction near the printf call. Anyone know why this isn't working or point out where I'm going wrong? I'm using llvm 2.8.

Cheers
Tim

test-printf.bc (680 Bytes)

test-printf.c (112 Bytes)

test-printf.i (9.82 KB)

test-printf.s (657 Bytes)

Since your first step is a 64-bit environment, size_t is understood to be 64 bits and the result of sizeof is passed that way, which doesn't match your eventual target environment. You can see this in the generated IR (use llvm-dis). You'll get farther if you use a 32-bit environment as your first step (-m32 works some places), but you'll still have problems because of incompatibilities in the calling convention between x86-32 and Sparc. I recommend trying harder to compile llvm-gcc.

Hi,

Hi everyone,

I'm trying to make a cross-compiler based on llvm to target sparc (solaris)
from x86_64 (linux). I couldn't compile llvm-gcc on my system so have to
use the precompiled binaries from the website, but already have a gcc
cross-compiler so can use this. So far, my compilation steps are these:

1) Preprocess the (C) sources using gcc cross-compiler
2) Use llvm-gcc to transform to llvm IR
3) Run llc to emit sparc assembly
4) Assemble and link using gcc cross-compiler

This works for a simple 'Hello World' program, but I'm getting problems when
trying more complicated things. One thing in particular is with a simple
printf that I want to write that prints out the size of an integer. I've
attached an example program source, preprocessed source, llvm code and
assembly. Instead of printing 'Value is 4' I get 'Value is 0'! I don't
know sparc assembly at all, but a quick scan over the code shows that the
value '4' is definitely used in an instruction near the printf call. Anyone
know why this isn't working or point out where I'm going wrong? I'm using
llvm 2.8.

Try to generate sparc llvm IR using clang and see what happens, you can
use -ccc-host-triple and -ccc-clang-archs command line options.