简体   繁体   中英

Unable to cross-compile to SPARC using clang

So here's the situation: I need to be able to compile binaries from a Linux machine (on Ubuntu, for what it's worth) which are able to run from a SPARC server. The program I'm trying to compile is very simple:

#include <stdio.h>
#include <stdlib.h>

int main() {
    printf("Testing the SPARC program...");
    return EXIT_SUCCESS;
}

I've tried a number of different compile lines to get it to work, but unfortunately nothing appears to be working.

I tried the traditional:

 clang -target sparc blah.c -o blahsparc

But this doesn't work, with a bunch of assembler failures:

 /tmp/blah-519e77.s: Assembler messages:
 /tmp/blah-519e77.s:7: Error: unknown pseudo-op: '.register'
 /tmp/blah-519e77.s:8: Error: unknown pseudo-op: '.register'
 /tmp/blah-519e77.s:9: Error: unknown pseudo-op: '.register'
 /tmp/blah-519e77.s:10: Error: unknown pseudo-op: '.register'
 /tmp/blah-519e77.s:11: Error: no such instruction: 'save %sp,-240,%sp'
 /tmp/blah-519e77.s:12: Error: no such instruction: 'st %g0, [%fp+2043]'
 ...
 clang: error: assembler (via gcc) command failed with exit code 1 (use -v to see invocation)

I've tried this also:

clang -cc1 -triple "sparc-unknown-Linux" blah.c -o blahsparc

which complains about the missing headers, so instead of using -cc1, I use -Xclang:

clang -Xclang -triple -Xclang "sparc-unknown-Linux" blah.c -o blahsparc

however, this also fails due to "error: unknown target CPU 'x86-64'". I'm not sure where to proceed with this. I've tried using crosstool-ng as well with very little success.

As of the 3.4.2 release (June 2014), llvm is missing code necessary to be able to generate object files for sparc targets. Older releases (1.x & 2.x) had support for it, but llvm's framework for emitting object files was less mature back then. When the current framework was rolled out it looks like they didn't migrate all platforms.

The documentation seems to imply that a combination of llvm/gcc is known to work, but I think that table was tabulated based on a much earlier version of llvm when they had a less mature framework for emitting object files.

Support for emitting object files was added to their SVN trunk in revision r198533 ( this thread discusses the commit), but as you can see in the 3.4.2 final release , files & changes added in r198533 aren't present.


As an aside, clang currently isn't functional in sparc solaris (not sure about sparc in general). The parser seems to have trouble parsing templates; I get coredumps & the like. I ran across a thread a week or so ago discussing alignment problems in sparc/solaris clang, and this may be one of the reasons clang isn't yet usable on this platform.

If you need a cross compiler for Sparc that runs on an Ubuntu machine, the simplest way I know of is to use Buildroot. Here's a small tutorial on how to obtain a cross compiler and test the generated executables on a Sparc emulator.

LLVM 3.6.2 has some support for sparc now... I was able to build llvm 3.6.2 and clang 3.6.2-r100 on my T2000. I haven't gotten C++ support working but I have built moderately complex C applications like htop.

I did compile LLVM using gcc 5.2 however I lower version should work as well although I'd suggested at least gcc 4.9 and no lower than gcc 4.7.

The LLVM emerge on gentoo crashed during the compile but I was able to resume it by moving to the portage directory with the llvm ebuilds and restarting the build manually:

cd  /usr/portage/*/llvm/
ebuild llvm-3.6.2.ebuild merge

I had to override some of the default compiler:

CC="clang -target sparc-unknown-linux-gnu" 
CXX="clang++ -target sparc-unknown-linux-gnu" 
CFLAGS="-O2 -pipe"
CXXFLAGS="${CFLAGS}"

I don't know if you will be able to use this to build from an x86 machine... though clang is supposed to be able to do that. But worst case you might be able to get this going in qemu-system-sparc64 vm or on some real hardware that you can find cheap on ebay (T5xxx hardware is coming down in price and blades are dirt cheap)

I recently updated to clang 3.8 (which is as yet unreleased) and I was able to compile a c++ application by passing -lstdc++ in addition to the options above. I believe this is the same behavior as gcc when invoked as gcc rather than g++.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM