C++ LLVM 和 Clang 无法为受支持的架构编译

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13944340/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 17:50:25  来源:igfitidea点击:

LLVM & Clang can't compile for a supported arch

c++architecturearmllvmclang

提问by user1849534

Under Ubuntu 64 bit I got

在 Ubuntu 64 位下我得到了

llc --version
LLVM (http://llvm.org/):
  LLVM version 3.1
  Optimized build with assertions.
  Built Oct 15 2012 (18:15:59).
  Default target: x86_64-pc-linux-gnu
  Host CPU: btver1

  Registered Targets:
    arm      - ARM
    mips     - Mips
    mips64   - Mips64 [experimental]
    mips64el - Mips64el [experimental]
    mipsel   - Mipsel
    thumb    - Thumb
    x86      - 32-bit X86: Pentium-Pro and above
    x86-64   - 64-bit X86: EM64T and AMD64

I can't do this

我不能这样做

clang -march=arm -x c++ /tmp/cpp.cpp 
error: unknown target CPU 'arm'

I'm missing something here ? Why I can't compile for ARM ?

我在这里遗漏了什么?为什么我不能为 ARM 编译?

采纳答案by user1849534

As this commentsays this option it's not supported yet under linux, for now.

如此评论所说,目前在 linux 下尚不支持此选项。

回答by Anton Korobeynikov

-march is LLVM's internal tools command line option and is not connected with clang at all. If you need to compile for other target you need to specify the target triplet. This can be done in several ways (I do not remember offhand, whether they work with 3.1, but they definitely work with 3.2):

-march 是 LLVM 的内部工具命令行选项,根本与 clang 无关。如果需要为其他目标编译,则需要指定目标三元组。这可以通过多种方式完成(我不记得了,它们是否适用于 3.1,但它们肯定适用于 3.2):

  • Make a link from clang to your-target-triple-clang, e.g. to arm-none-linux-gnueabi-clang and compile everything via it
  • Provide -targetoption, e.g. clang -target arm-none-linux-gnueabi
  • 建立从 clang 到 your-target-triple-clang 的链接,例如到 arm-none-linux-gnueabi-clang 并通过它编译所有内容
  • 提供-target选项,例如clang -target arm-none-linux-gnueabi

回答by old_timer

the llvm linker links for the host, which is only one of the targets, it wont link to every target in the list. it will definitely compile for any target. Basically clang goes from C/C++ to bytecode, then llc takes bytecode and makes assembly for the specific target (new experrimental option to take the bytecode straight to object file) then you need to get a cross assembler and a cross linker to take it the final mile (I use gnu binutils). Unfortunately I found that clang to bytecode is not completely generic (I had hoped and expected that it would be), it does in fact change the target independent output based on the target. The example below using the host triple instead of using -march allowed for my examples to build properly on more hosts.

主机的 llvm 链接器链接,它只是目标之一,它不会链接到列表中的每个目标。它肯定会为任何目标编译。基本上 clang 从 C/C++ 到字节码,然后 llc 获取字节码并为特定目标进行汇编(新的实验选项将字节码直接带到目标文件)然后你需要得到一个交叉汇编器和一个交叉链接器来获取它最后一英里(我使用 gnu binutils)。不幸的是,我发现 clang 到字节码并不是完全通用的(我曾希望并期望它会如此),它实际上确实根据目标更改了目标独立输出。下面的示例使用主机三元组而不是使用 -march 允许我的示例在更多主机上正确构建。

ARMGNU?=arm-none-eabi
LOPS = -Wall -m32 -emit-llvm -ccc-host-triple $(ARMGNU)
OOPS = -std-compile-opts
LLCOPS = -march=thumb -mtriple=$(ARMGNU)

    clang $(LOPS) -c blinker03.c -o blinker03.clang.bc
    opt $(OOPS) blinker03.clang.bc -o blinker03.clang.thumb.opt.bc
    llc $(LLCOPS) blinker03.clang.thumb.opt.bc -o blinker03.clang.thumb.opt.s
    $(ARMGNU)-as blinker03.clang.thumb.opt.s -o blinker03.clang.thumb.opt.o
    $(ARMGNU)-ld -o blinker03.clang.thumb.opt.elf -T memmap vectors.o blinker03.clang.thumb.opt.o

I have not, but before long will experiment with using the llc straight to object (actually I tried it on a simple test but have not used it on anything larger or posted it anywhere).

我没有,但不久将尝试使用 llc 直接对象(实际上我在一个简单的测试中尝试过,但没有在任何更大的地方使用它或将它张贴在任何地方)。

回答by Lei Mou

To get a list of options of the clang compiler, use:

要获取 clang 编译器的选项列表,请使用:

clang -cc1 -help

clang -cc1 -help

To specify the target, use -triple:

要指定目标,请使用-triple

clang -cc1 -triple "arm-vendor-os" filename

clang -cc1 -triple "arm-vendor-os" 文件名

where "vendor" and "os" should be replaced with the actual vendor and OS name. It can also be replaced with unknown.

其中“vendor”和“os”应替换为实际的供应商和操作系统名称。也可以替换为unknown

-tripleis a string of the form ARCHITECTURE-VENDOR-OSor ARCHITECTURE-VENDOR-OS-ENVIRONMENT. For example: x86_64-apple-darwin10

-triple是形式为ARCHITECTURE-VENDOR-OSor的字符串ARCHITECTURE-VENDOR-OS-ENVIRONMENT。例如:x86_64-apple-darwin10

回答by Lily Ballard

You're confusing your flags. clang's -march=wants a processor family. You probably meant to use clang -arch arminstead.

你混淆了你的标志。clang-march=想要一个处理器系列。您可能打算clang -arch arm改用。

回答by LeoTh3o

"-arch arm" is equivalent to "-arch armv4t" in clang. I suppose that a generic "arm" target is not allowed with "-march=", which should require something more precise, such as "armv6", "thumbv7", "armv4t", ...

“-arch arm”相当于clang中的“-arch armv4t”。我想“-march=”不允许使用通用的“arm”目标,这应该需要更精确的东西,例如“armv6”、“thumbv7”、“armv4t”……

Try selecting a specific subarch.

尝试选择一个特定的 subarch。