简体   繁体   English

无法使用clang交叉编译到SPARC

[英]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. 所以情况就是这样:我需要能够从Linux机器(在Ubuntu上,它的价值)编译二进制文件,它们能够从SPARC服务器运行。 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: 抱怨丢失的标题,所以不使用-cc1,我使用-Xclang:

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

however, this also fails due to "error: unknown target CPU 'x86-64'". 但是,由于“错误:未知目标CPU'x86-64'”,这也会失败。 I'm not sure where to proceed with this. 我不知道在哪里继续这个。 I've tried using crosstool-ng as well with very little success. 我尝试过使用crosstool-ng,但收效甚微。

As of the 3.4.2 release (June 2014), llvm is missing code necessary to be able to generate object files for sparc targets. 从3.4.2版本(2014年6月)开始,llvm缺少能够为sparc目标生成目标文件所需的代码。 Older releases (1.x & 2.x) had support for it, but llvm's framework for emitting object files was less mature back then. 旧版本(1.x和2.x)支持它,但是llvm的发布目标文件的框架在那时还不太成熟。 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. 文档似乎暗示llvm / gcc的组合已知可行,但我认为该表是基于llvm的早期版本制表的,当它们具有用于发出目标文件的不太成熟的框架时。

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. 对于发送目标文件的支持已添加到修订版r198533中的SVN主干( 此主题讨论了提交),但正如您在3.4.2最终版本所见r198533中添加的文件和更改不存在。


As an aside, clang currently isn't functional in sparc solaris (not sure about sparc in general). 顺便说一句,clang目前在sparc solaris中不起作用(一般不确定sparc)。 The parser seems to have trouble parsing templates; 解析器似乎无法解析模板; I get coredumps & the like. 我得到了coredumps之类的东西。 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. 我碰到一个跑线一个星期前讨论在SPARC / Solaris上铛对准问题,这可能是原因铛,尚无法使用此平台上的一个。

If you need a cross compiler for Sparc that runs on an Ubuntu machine, the simplest way I know of is to use Buildroot. 如果你需要一个在Ubuntu机器上运行的Sparc的交叉编译器,我所知道的最简单的方法是使用Buildroot。 Here's a small tutorial on how to obtain a cross compiler and test the generated executables on a Sparc emulator. 这是一个关于如何获取交叉编译器并在Sparc模拟器上测试生成的可执行文件的小教程

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. LLVM 3.6.2现在对sparc有一些支持......我能够在我的T2000上构建llvm 3.6.2和clang 3.6.2-r100。 I haven't gotten C++ support working but I have built moderately complex C applications like htop. 我没有得到C ++支持,但我已经构建了像htop这样复杂的C语言应用程序。

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. 我确实使用gcc 5.2编译LLVM但是我的低版本应该也可以工作,尽管我建议至少gcc 4.9并且不低于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: 在编译期间,gentoo上出现了LLVM崩溃,但我可以通过移植到llvm ebuilds的portage目录并手动重新启动构建来恢复它:

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. 我不知道你是否能够使用它来从x86机器构建......虽然clang应该能够做到这一点。 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) 但最糟糕的情况是你可能能够在qemu-system-sparc64 vm或者你可以在ebay上找到便宜的一些真正的硬件(T5xxx硬件价格下降,刀片便宜)

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. 我最近更新到了clang 3.8(尚未发布),除了上面的选项之外,我还能通过传递-lstdc ++来编译c ++应用程序。 I believe this is the same behavior as gcc when invoked as gcc rather than g++. 我相信当gcc作为gcc而不是g ++调用时,这与gcc的行为相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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