如何在clang中列出支持的目标架构?

137

我对ARM有兴趣,尤其是iPhone/Android目标。但我想更多地了解clang,因为它在未来几年中扮演重要角色。

我尝试过。

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)

我知道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/任何其他系统),那么我该如何获得支持更多平台的目标?
如果我像这样SVN最新的clang:
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang

我会获得大多数平台吗?

看起来 Clang 最初并不是为交叉编译而构建的,但由于它基于 LLVM,理论上应该非常适合跨平台。


10
不是完整答案,但llc --version会给出目标。 - old_timer
1
我认为你需要查看源代码才能看到三元组。据我所知,Clang 的默认构建将包含基本的跨平台编译支持。仅具备基本支持功能只会将代码转换为目标文件(只要集成的汇编器支持三元组,否则您将不得不使用 .s 文件)。您将需要提供头文件、库、链接器(直到 lld 起作用)等。 - bames53
1
尽管默认安装只有clang和clang++可执行文件,但与其他平台一样,您可以使用三元组和四元组编码在名称中创建副本或硬链接。 clang++和clang实际上只是彼此的副本,它检查可执行文件的名称以确定如何处理输入。 - LB--
1
相关 - Clang支持哪些目标? - Royi
14个回答

3

如果您对从源代码构建LLVM或Clang所支持的目标感兴趣(-DLLVM_TARGETS_TO_BUILD的值),请查看源分发中llvm/lib/Target文件夹中的子目录列表。截至9.0.1,有以下内容:

AArch64
AMDGPU
ARC
ARM
AVR
BPF
Hexagon
Lanai
MSP430
Mips
NVPTX
PowerPC
RISCV
Sparc
SystemZ
WebAssembly
X86

我尝试重新配置失败的构建,这是我找到的唯一可行的方法。 - saulius2

1

如果你想知道你的特定x86 CPU家族架构是否有llvm/clang优化目标(例如:zen3、zen1、skylake、penryn等),可以查看下面的列表或运行以下命令:

$ llc -march=x86 -mattr=help
Available CPUs for this target:

  alderlake      - Select the alderlake processor.
  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.
  barcelona      - Select the barcelona processor.
  bdver1         - Select the bdver1 processor.
  bdver2         - Select the bdver2 processor.
  bdver3         - Select the bdver3 processor.
  bdver4         - Select the bdver4 processor.
  bonnell        - Select the bonnell processor.
  broadwell      - Select the broadwell processor.
  btver1         - Select the btver1 processor.
  btver2         - Select the btver2 processor.
  c3             - Select the c3 processor.
  c3-2           - Select the c3-2 processor.
  cannonlake     - Select the cannonlake processor.
  cascadelake    - Select the cascadelake processor.
  cooperlake     - Select the cooperlake processor.
  core-avx-i     - Select the core-avx-i processor.
  core-avx2      - Select the core-avx2 processor.
  core2          - Select the core2 processor.
  corei7         - Select the corei7 processor.
  corei7-avx     - Select the corei7-avx processor.
  generic        - Select the generic processor.
  geode          - Select the geode processor.
  goldmont       - Select the goldmont processor.
  goldmont-plus  - Select the goldmont-plus processor.
  haswell        - Select the haswell processor.
  i386           - Select the i386 processor.
  i486           - Select the i486 processor.
  i586           - Select the i586 processor.
  i686           - Select the i686 processor.
  icelake-client - Select the icelake-client processor.
  icelake-server - Select the icelake-server processor.
  ivybridge      - Select the ivybridge processor.
  k6             - Select the k6 processor.
  k6-2           - Select the k6-2 processor.
  k6-3           - Select the k6-3 processor.
  k8             - Select the k8 processor.
  k8-sse3        - Select the k8-sse3 processor.
  knl            - Select the knl processor.
  knm            - Select the knm processor.
  lakemont       - Select the lakemont processor.
  nehalem        - Select the nehalem processor.
  nocona         - Select the nocona processor.
  opteron        - Select the opteron processor.
  opteron-sse3   - Select the opteron-sse3 processor.
  penryn         - Select the penryn processor.
  pentium        - Select the pentium processor.
  pentium-m      - Select the pentium-m processor.
  pentium-mmx    - Select the pentium-mmx processor.
  pentium2       - Select the pentium2 processor.
  pentium3       - Select the pentium3 processor.
  pentium3m      - Select the pentium3m processor.
  pentium4       - Select the pentium4 processor.
  pentium4m      - Select the pentium4m processor.
  pentiumpro     - Select the pentiumpro processor.
  prescott       - Select the prescott processor.
  rocketlake     - Select the rocketlake processor.
  sandybridge    - Select the sandybridge processor.
  sapphirerapids - Select the sapphirerapids processor.
  silvermont     - Select the silvermont processor.
  skx            - Select the skx processor.
  skylake        - Select the skylake processor.
  skylake-avx512 - Select the skylake-avx512 processor.
  slm            - Select the slm processor.
  tigerlake      - Select the tigerlake processor.
  tremont        - Select the tremont processor.
  westmere       - Select the westmere processor.
  winchip-c6     - Select the winchip-c6 processor.
  winchip2       - Select the winchip2 processor.
  x86-64         - Select the x86-64 processor.
  x86-64-v2      - Select the x86-64-v2 processor.
  x86-64-v3      - Select the x86-64-v3 processor.
  x86-64-v4      - Select the x86-64-v4 processor.
  yonah          - Select the yonah processor.
  znver1         - Select the znver1 processor.
  znver2         - Select the znver2 processor.
  znver3         - Select the znver3 processor.

以上列表截止至llvm-13版本。

要运行以上代码,您需要安装至少llvm,并且要获得与上述相同的结果,您需要至少安装llvm-13。


问题是列出所有“-三元组”或至少列出所有架构,而不是x86微架构。 - phuclv

1

对于那些想要针对CPU进行调整的人,您可以使用--print-supported-cpus(在此处添加)。如果您的clang二进制文件可以编译多个架构,则还必须传递--target以选择正确的架构;例如,要列出Android交叉编译器上可用的ARM CPU,您可以使用--target=aarch64-unknown-linux-gui


0

只有第一个(CPU架构)需要精确,其他参数会以智能和复杂的方式进行处理,您可以使用 "clang++ ... --verbose ..." 查看处理结果,例如:

Command Line Input      After triple processing
x86_64                  x86_64
x86_64-foo              x86_64-foo
x86_64-windows          x86_64-unknown-windows-msvc19.28.29335
x86_64-windows-bar      x86_64-unknown-windows-msvc19.28.29335
x86_64-foo-windows-bar  x86_64-foo-windows-msvc19.28.29335
x86_64-foo-bar-foobar   x86_64-foo-bar-foobar

通常情况下,除了第一个参数外,其他参数只有在正确时才会生效(经过三重处理过程后,可能会聪明地将错误的参数变为正确的)。例如,“windows”将影响代码:

/// Tests whether the OS is Windows.
bool isOSWindows() const {
    return getOS() == Triple::Win32;
}

这个方法被Clang/LLVM中的其他代码用于影响编译结果,只有当参数为“windows”时才返回true,如果是“foo”等其他内容则返回false。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接