Unable to cross compile SPARC using clang

So, here is the situation: I need to compile binary files from a Linux machine (on Ubuntu, for what it costs), which can be run from the 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 tried several different compilation lines to make it work, but unfortunately nothing works.

I tried the traditional one:

  clang -target sparc blah.c -o blahsparc 

But this will not work with assembler crashes:

  /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 also tried this:

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

which complains about 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 processorโ€œ x86-64. โ€I donโ€™t know where to start. I also tried using crosstool-ng with very little success.

+7
source share
4 answers

Starting with version 3.4.2 (June 2014), llvm lacks the code needed to create object files for sparc purposes. Older versions (1.x and 2.x) supported it, but the llvm framework for emitting object files was then less mature. When the current structure was deployed, it looks like they did not migrate all the platforms.

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

Support for emitting object files was added to their SVN trunk in the r198533 edition ( this thread discusses commit), but as you can see in the 3.4.2 final version , there are no files and changes added to r198533 .


In contrast, clang currently does not work in sparc solaris (not sure if in most cases sparc). It seems that the parser is having problems parsing patterns; I get crowns and the like. I came across thread a week ago discussing alignment problems in sparc / solaris clang, and this may be one of the reasons why clang is not but usable on this platform.

+4
source

If you need a cross-compiler for Sparc that runs on an Ubuntu machine, the easiest way I know is to use Buildroot. Here is a short tutorial on how to get the cross-compiler and test the generated executables on the Sparc emulator.

+3
source

LLVM 3.6.2 now has some sparc support ... I was able to build llvm 3.6.2 and clang 3.6.2-r100 on my T2000. I did not get C ++ support, but I have complex C applications like htop.

I compiled LLVM using gcc 5.2, but I have to work with a lower version, although I suggested at least gcc 4.9 and not lower than gcc 4.7.

LLVM appears during gentoo compilation, but I was able to resume it by going to the portage directory with ebuilds llvm and restarting the build manually:

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

I had to override some 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 can use this to build from an x86 machine ... although, as expected, clang should do this. But in the worst case, you can get it in qemu-system-sparc64 vm or on some real equipment that you can find on ebay cheaply (T5xxx equipment is reduced in price and blades are cheap)

I recently upgraded to clang 3.8 (which has not yet been released), 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 calling gcc, not g ++.

+3
source

How about the following: clang -arch sparc blah.c -o blahsparc

0
source

Source: https://habr.com/ru/post/955031/


All Articles