目前我对ARM一般感兴趣,特别是iphone/android目标.但我只想更多地了解铿锵声,因为它感觉在未来几年中扮演重要角色.
我试过了
clang -cc1 --help|grep -i list
clang -cc1 --help|grep arch|grep -v search
clang -cc1 --help|grep target
-triple <value> Specify target triple (e.g. i686-apple-darwin9)
Run Code Online (Sandbox Code Playgroud)
我知道clang有-triplet参数,但是如何列出所有可能的值呢?我发现clang在交叉编译方面与gcc非常不同,在GCC世界中你应该为所有东西都有单独的二进制文件,比如PLATFORM_make或PLATFORM_ld(i*86-pc-cygwin i*86 - * - linux-gnu等.http: ://git.savannah.gnu.org/cgit/libtool.git/tree/doc/PLATFORMS)
在clang世界中,它只有一个二进制文件(正如我在一些论坛上看到的那样).但是如何获得支持的目标列表?如果我的目标不支持我的发行版(linux/windows/macos/whatever),我怎么能得到支持更多平台的那个?
如果我SVN最新铿锵如下:
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
Run Code Online (Sandbox Code Playgroud)
我会获得大多数平台吗?看起来Clang并没有立即考虑交叉编译,但是因为它基于llvm,它理论上应该是非常交叉友好的?谢谢!
pnd*_*ndc 42
据我所知,没有命令行选项列出给定clang二进制文件支持哪些体系结构,甚至strings在其上运行也没有用.Clang本质上只是一个C到LLVM的翻译器,它的LLVM本身处理生成实际机器代码的细节,因此Clang对底层架构不太关注也就不足为奇了.
正如其他人已经注意到的那样,您可以询问llc它支持哪些体系结构.这不仅仅是因为可能没有安装这些LLVM组件,而且由于搜索路径和打包系统的变幻莫测,因此您llc和clang二进制文件可能与同一版本的LLVM不对应.
但是,为了争论,让我们说你自己编译了LLVM和Clang,或者你很乐意接受你的LLVM二进制文件:
llc --version将列出其支持的所有体系结构.默认情况下,它被编译为支持所有体系结构.您可能认为像ARM这样的单一架构可能有几种LLVM架构,例如常规ARM,Thumb和AArch64.这主要是为了实现方便,因为不同的执行模式具有非常不同的指令编码和语义.llc -march=ARCH -mattr=help将列出"可用CPU"和"可用功能".CPU通常只是设置默认功能集的便捷方式.但现在是坏消息.Clang或LLVM中没有方便的三元组表可以转储,因为特定于体系结构的后端可以选择将三元组字符串解析为一个llvm::Triple对象(在include/llvm/ADT/Triple.h中定义).换句话说,要转储所有可用的三元组需要解决停机问题.例如,请参阅llvm::ARM_MC::ParseARMTriple(...)解析字符串的特殊情况"generic".
但最终,"三联"主要是向后兼容功能,使Clang成为GCC的直接替代品,因此除非将Clang或LLVM移植到新平台,否则通常不需要太多关注它或建筑.相反,您可能会发现llc -march=arm -mattr=help大量不同ARM功能的输出和令人难以置信的功能在您的调查中更有用.
祝你的研究顺利!
小智 31
我正在使用Clang 3.3,我认为获得答案的最佳方法是阅读源代码.在llvm/ADT/Triple.h中(http://llvm.org/doxygen/Triple_8h_source.html):
enum ArchType {
UnknownArch,
arm, // ARM: arm, armv.*, xscale
aarch64, // AArch64: aarch64
hexagon, // Hexagon: hexagon
mips, // MIPS: mips, mipsallegrex
mipsel, // MIPSEL: mipsel, mipsallegrexel
mips64, // MIPS64: mips64
mips64el,// MIPS64EL: mips64el
msp430, // MSP430: msp430
ppc, // PPC: powerpc
ppc64, // PPC64: powerpc64, ppu
r600, // R600: AMD GPUs HD2XXX - HD6XXX
sparc, // Sparc: sparc
sparcv9, // Sparcv9: Sparcv9
systemz, // SystemZ: s390x
tce, // TCE (http://tce.cs.tut.fi/): tce
thumb, // Thumb: thumb, thumbv.*
x86, // X86: i[3-9]86
x86_64, // X86-64: amd64, x86_64
xcore, // XCore: xcore
mblaze, // MBlaze: mblaze
nvptx, // NVPTX: 32-bit
nvptx64, // NVPTX: 64-bit
le32, // le32: generic little-endian 32-bit CPU (PNaCl / Emscripten)
amdil, // amdil: amd IL
spir, // SPIR: standard portable IR for OpenCL 32-bit version
spir64 // SPIR: standard portable IR for OpenCL 64-bit version
};
Run Code Online (Sandbox Code Playgroud)
在clang/lib/Driver/ToolChains.cpp中,有关于arm的信息.
static const char *GetArmArchForMArch(StringRef Value) {
return llvm::StringSwitch<const char*>(Value)
.Case("armv6k", "armv6")
.Case("armv6m", "armv6m")
.Case("armv5tej", "armv5")
.Case("xscale", "xscale")
.Case("armv4t", "armv4t")
.Case("armv7", "armv7")
.Cases("armv7a", "armv7-a", "armv7")
.Cases("armv7r", "armv7-r", "armv7")
.Cases("armv7em", "armv7e-m", "armv7em")
.Cases("armv7f", "armv7-f", "armv7f")
.Cases("armv7k", "armv7-k", "armv7k")
.Cases("armv7m", "armv7-m", "armv7m")
.Cases("armv7s", "armv7-s", "armv7s")
.Default(0);
}
static const char *GetArmArchForMCpu(StringRef Value) {
return llvm::StringSwitch<const char *>(Value)
.Cases("arm9e", "arm946e-s", "arm966e-s", "arm968e-s", "arm926ej-s","armv5")
.Cases("arm10e", "arm10tdmi", "armv5")
.Cases("arm1020t", "arm1020e", "arm1022e", "arm1026ej-s", "armv5")
.Case("xscale", "xscale")
.Cases("arm1136j-s", "arm1136jf-s", "arm1176jz-s", "arm1176jzf-s", "armv6")
.Case("cortex-m0", "armv6m")
.Cases("cortex-a8", "cortex-r4", "cortex-a9", "cortex-a15", "armv7")
.Case("cortex-a9-mp", "armv7f")
.Case("cortex-m3", "armv7m")
.Case("cortex-m4", "armv7em")
.Case("swift", "armv7s")
.Default(0);
}
Run Code Online (Sandbox Code Playgroud)
rog*_*ack 16
你可以做一个提示:如果你想找到一个特定的目标三元组,就是在该系统上安装llvm 然后做一个
$ llc --version | grep Default
Default target: x86_64-apple-darwin16.1.0
Run Code Online (Sandbox Code Playgroud)
或者:
$ llvm-config --host-target
x86_64-apple-darwin16.0.0
or
$ clang -v 2>&1 | grep Target
Target: x86_64-apple-darwin16.1.0
Run Code Online (Sandbox Code Playgroud)
然后你知道如何在交叉编译时将其作为目标.
显然有很多目标,这里是一个列表,随意添加,社区维基风格:
arm-none-eabi
armv7a-none-eabi
arm-linux-gnueabihf
arm-none-linux-gnueabi
i386-pc-linux-gnu
x86_64-apple-darwin10
i686-w64-windows-gnu # same as i686-w64-mingw32
x86_64-pc-linux-gnu # from ubuntu 64 bit
x86_64-unknown-windows-cygnus # cygwin 64-bit
x86_64-w64-windows-gnu # same as x86_64-w64-mingw32
i686-pc-windows-gnu # MSVC
x86_64-pc-windows-gnu # MSVC 64-BIT
Run Code Online (Sandbox Code Playgroud)
以下是文档列出的内容(显然它是四倍[或五倍?]而不是这些天的三倍):
The triple has the general format <arch><sub>-<vendor>-<sys>-<abi>, where:
arch = x86, arm, thumb, mips, etc.
sub = for ex. on ARM: v5, v6m, v7a, v7m, etc.
vendor = pc, apple, nvidia, ibm, etc.
sys = none, linux, win32, darwin, cuda, etc.
abi = eabi, gnu, android, macho, elf, etc.
Run Code Online (Sandbox Code Playgroud)
并且您甚至可以微调指定超出此范围的目标cpu,尽管它使用基于三元组的目标cpu的合理默认值.
有时目标"解决"到同一个东西,所以要看到目标实际上被视为什么:
$ clang -target x86_64-w64-mingw32 -v 2>&1 | grep Target
Target: x86_64-w64-windows-gnu
Run Code Online (Sandbox Code Playgroud)
jww*_*jww 10
根据Jonathan Roelofs的演讲,"Clang支持哪些目标?":
$ llc --version
LLVM (http://llvm.org/):
LLVM version 3.6.0
Optimized build with assertions.
Built Apr 2 2015 (01:25:22).
Default target: x86_64-apple-darwin12.6.0
Host CPU: corei7-avx
Registered Targets:
aarch64 - AArch64 (little endian)
aarch64_be - AArch64 (big endian)
amdgcn - AMD GCN GPUs
arm - ARM
arm64 - ARM64 (little endian)
armeb - ARM (big endian)
cpp - C++ backend
hexagon - Hexagon
mips - Mips
mips64 - Mips64 [experimental]
mips64el - Mips64el [experimental]
mipsel - Mipsel
msp430 - MSP430 [experimental]
nvptx - NVIDIA PTX 32-bit
nvptx64 - NVIDIA PTX 64-bit
ppc32 - PowerPC 32
ppc64 - PowerPC 64
ppc64le - PowerPC 64 LE
r600 - AMD GPUs HD2XXX-HD6XXX
sparc - Sparc
sparcv9 - Sparc V9
systemz - SystemZ
thumb - Thumb
thumbeb - Thumb (big endian)
x86 - 32-bit X86: Pentium-Pro and above
x86-64 - 64-bit X86: EM64T and AMD64
xcore - XCore
Run Code Online (Sandbox Code Playgroud)
Clang的未来版本可能提供以下内容.它们被列为"建议",但至少从v3.9.0开始尚未提供:
$ clang -target <target_from_list_above> --print-multi-libs
$ clang -print-supported-archs
$ clang -march x86 -print-supported-systems
$ clang -march x86 -print-available-systems
Run Code Online (Sandbox Code Playgroud)
从 Clang 11(主干)开始,可以使用新添加的-print-targets标志轻松打印支持的目标架构列表:
$ clang-11 -print-targets
Registered Targets:
aarch64 - AArch64 (little endian)
aarch64_32 - AArch64 (little endian ILP32)
aarch64_be - AArch64 (big endian)
amdgcn - AMD GCN GPUs
arm - ARM
arm64 - ARM64 (little endian)
arm64_32 - ARM64 (little endian ILP32)
armeb - ARM (big endian)
avr - Atmel AVR Microcontroller
bpf - BPF (host endian)
bpfeb - BPF (big endian)
bpfel - BPF (little endian)
hexagon - Hexagon
lanai - Lanai
mips - MIPS (32-bit big endian)
mips64 - MIPS (64-bit big endian)
mips64el - MIPS (64-bit little endian)
mipsel - MIPS (32-bit little endian)
msp430 - MSP430 [experimental]
nvptx - NVIDIA PTX 32-bit
nvptx64 - NVIDIA PTX 64-bit
ppc32 - PowerPC 32
ppc64 - PowerPC 64
ppc64le - PowerPC 64 LE
r600 - AMD GPUs HD2XXX-HD6XXX
riscv32 - 32-bit RISC-V
riscv64 - 64-bit RISC-V
sparc - Sparc
sparcel - Sparc LE
sparcv9 - Sparc V9
systemz - SystemZ
thumb - Thumb
thumbeb - Thumb (big endian)
wasm32 - WebAssembly 32-bit
wasm64 - WebAssembly 64-bit
x86 - 32-bit X86: Pentium-Pro and above
x86-64 - 64-bit X86: EM64T and AMD64
xcore - XCore
Run Code Online (Sandbox Code Playgroud)
参考资料:LLVM PR、LLVM commit、Clang 11 文档。
也试试
> llc -mattr=help
Available CPUs for this target:
amdfam10 - Select the amdfam10 processor.
athlon - Select the athlon processor.
athlon-4 - Select the athlon-4 processor.
athlon-fx - Select the athlon-fx processor.
athlon-mp - Select the athlon-mp processor.
athlon-tbird - Select the athlon-tbird processor.
athlon-xp - Select the athlon-xp processor.
athlon64 - Select the athlon64 processor.
athlon64-sse3 - Select the athlon64-sse3 processor.
atom - Select the atom processor.
...
Available features for this target:
16bit-mode - 16-bit mode (i8086).
32bit-mode - 32-bit mode (80386).
3dnow - Enable 3DNow! instructions.
3dnowa - Enable 3DNow! Athlon instructions.
64bit - Support 64-bit instructions.
64bit-mode - 64-bit mode (x86_64).
adx - Support ADX instructions.
...
Run Code Online (Sandbox Code Playgroud)