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 -- Timothy M. Jones http://homepages.inf.ed.ac.uk/tjones1 The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336. -------------- next part -------------- A non-text attachment was scrubbed... Name: test-printf.bc Type: application/octet-stream Size: 680 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20101115/4168bc8b/attachment.obj> -------------- next part -------------- A non-text attachment was scrubbed... Name: test-printf.c Type: application/octet-stream Size: 112 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20101115/4168bc8b/attachment-0001.obj> -------------- next part -------------- A non-text attachment was scrubbed... Name: test-printf.i Type: application/octet-stream Size: 10057 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20101115/4168bc8b/attachment-0002.obj> -------------- next part -------------- A non-text attachment was scrubbed... Name: test-printf.s Type: application/octet-stream Size: 657 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20101115/4168bc8b/attachment-0003.obj>
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. On Nov 15, 2010, at 12:46 PM, Timothy M Jones wrote:> 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 > > > -- > Timothy M. Jones > http://homepages.inf.ed.ac.uk/tjones1 > The University of Edinburgh is a charitable body, registered in > Scotland, with registration number SC005336. > > <test-printf.bc><test-printf.c><test-printf.i><test-printf.s>_______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Hi, On Mon, Nov 15, 2010 at 6:46 PM, Timothy M Jones <tjones1 at inf.ed.ac.uk> wrote:> 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.> > Cheers > Tim > > > -- > Timothy M. Jones > http://homepages.inf.ed.ac.uk/tjones1 > The University of Edinburgh is a charitable body, registered in > Scotland, with registration number SC005336. > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-- Bruno Cardoso Lopes http://www.brunocardoso.cc