[llvm-dev] clang triple and clang target

5,981 views
Skip to first unread message

Rail Shafigulin via llvm-dev

unread,
Mar 11, 2016, 4:20:20 PM3/11/16
to llvm-dev
Can someone explain what exactly a clang triple is (--triple option) and what is the connection between triple and a target? I know there is an article ( http://clang.llvm.org/docs/CrossCompilation.html) that show how to cross compile code, but I'm not clear about is why I need to specify triple, why I can't just say compile for a given target?

Any help is appreciated.

--
Rail Shafigulin
Software Engineer
Esencia Technologies

Joerg Sonnenberger via llvm-dev

unread,
Mar 11, 2016, 9:39:00 PM3/11/16
to llvm...@lists.llvm.org
On Fri, Mar 11, 2016 at 01:20:11PM -0800, Rail Shafigulin via llvm-dev wrote:
> Can someone explain what exactly a clang triple is (--triple option) and
> what is the connection between triple and a target? I know there is an
> article ( http://clang.llvm.org/docs/CrossCompilation.html) that show how
> to cross compile code, but I'm not clear about is why I need to specify
> triple, why I can't just say compile for a given target?

I assume with target you mean the backend? Consider the x86 backend. It
supports 32bit and 64bit mode, with the GNU x32 ABI in between. There
are three different executable formats support (ELF, PE, MachO) with
different constraints. Some platforms require 32bit alignment of the
stack, others require 128bit alignment. The list goes on. The triple specifies
the combination of target, OS and potentially file format and sub-ABI.

Joerg
_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

Rail Shafigulin via llvm-dev

unread,
Mar 12, 2016, 2:51:39 PM3/12/16
to Joerg Sonnenberger, llvm-dev
I assume with target you mean the backend? Consider the x86 backend. It
supports 32bit and 64bit mode, with the GNU x32 ABI in between. There
are three different executable formats support (ELF, PE, MachO) with
different constraints. Some platforms require 32bit alignment of the
stack, others require 128bit alignment. The list goes on. The triple specifies
the combination of target, OS and potentially file format and sub-ABI.

Joerg
_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

Thanks for the response. I was trying to generate assembly which would use vector instructions. I need to see how they look, whether it is ARM, Mips or X86. However for some reason clang would generate an error saying that a given target does not exist. Here is the command line I used:

clang -S test.c -o test.sse2.x86-64.s --target=x86-unknown-linux-eabi -mfloat-abi=hard -mcpu=x86-64 -mfpu=SSE2 -fslp-vectorize-aggressive -fslp-vectorize-aggressive -fslp-vectorize -fvectorize -fno-lax-vector-conversions

Here is the response I got:
clang: warning: argument unused during compilation: '-mfloat-abi=hard'
clang: warning: argument unused during compilation: '-mcpu=x86-64'
clang: warning: argument unused during compilation: '-mfpu=SSE2'
error: unknown target triple 'x86-unknown-linux-eabi', please use -triple or -arch


I tried every possible combination of --target I could think of but nothing worked. Would you mind helping me out? 

Tim Northover via llvm-dev

unread,
Mar 12, 2016, 5:39:01 PM3/12/16
to Rail Shafigulin, llvm-dev
On 12 March 2016 at 11:51, Rail Shafigulin via llvm-dev

<llvm...@lists.llvm.org> wrote:
> I tried every possible combination of --target I could think of but nothing
> worked. Would you mind helping me out?

First, 64-bit x86 is "x86_64", and 32-bit is "i386" in the triple. For
ARM you'd probably want "thumbv8" or "aarch64". Also, "eabi" is only a
thing on ARM targets, try "gnu" for x86.

Cheers.

Tim.

Daniel Sanders via llvm-dev

unread,
Mar 14, 2016, 11:28:08 AM3/14/16
to Rail Shafigulin, Joerg Sonnenberger, llvm-dev

> I need to see how they look, whether it is ARM, Mips or X86.

 

The Mips triples you're most likely to need are:

·         mips-linux-gnu – 32-bit big-endian on GNU/Linux

·         mipsel-linux-gnu – 32-bit little-endian on GNU/Linux

·         mips64-linux-gnu – 64-bit big-endian on GNU/Linux

·         mips64el-linux-gnu – 64-bit little-endian on GNU/Linux

 

I should mention that Mips has quite a few triple-related bugs but if you're just looking at assembly the one you're most likely to encounter is that mips-*/mipsel-* only work for 32-bit subtargets and mips64-*/mips64el-* only work for 64-bit subtargets. If you don't match them up correctly then you'll either get an assertion from the code generator or a crash. This isn't supposed to be the case but there's been some unfortunate misunderstandings about GNU triples and Clang triples (they're not quite the same thing) that are difficult to resolve.

Rail Shafigulin via llvm-dev

unread,
Mar 14, 2016, 2:19:50 PM3/14/16
to Daniel Sanders, llvm-dev
On Mon, Mar 14, 2016 at 8:27 AM, Daniel Sanders <Daniel....@imgtec.com> wrote:

> I need to see how they look, whether it is ARM, Mips or X86.

 

The Mips triples you're most likely to need are:

·         mips-linux-gnu – 32-bit big-endian on GNU/Linux

·         mipsel-linux-gnu – 32-bit little-endian on GNU/Linux

·         mips64-linux-gnu – 64-bit big-endian on GNU/Linux

·         mips64el-linux-gnu – 64-bit little-endian on GNU/Linux

 

I should mention that Mips has quite a few triple-related bugs but if you're just looking at assembly the one you're most likely to encounter is that mips-*/mipsel-* only work for 32-bit subtargets and mips64-*/mips64el-* only work for 64-bit subtargets. If you don't match them up correctly then you'll either get an assertion from the code generator or a crash. This isn't supposed to be the case but there's been some unfortunate misunderstandings about GNU triples and Clang triples (they're not quite the same thing) that are difficult to resolve.

 


Daniel,

Thanks for the response. I tried using the option you recommended but for some reason I didn't see any vector instructions in the output. Can you explain what am I doing wrong? Here is the command line I ran

clang -S test.c -o test.msa.mips.s --target=mips-pc-linux-gnu -mmsa -mfp64 -mfloat-abi=hard -mcpu=mips32 -fslp-vectorize-aggressive  -fslp-vectorize-aggressive -fslp-vectorize -fvectorize -fno-lax-vector-conversions -O3

I'm attaching test.c as well as test.msa.mips.s so you could see input as well as output.

Any help is appreciated.


test.c
test.msa.mips.s

Rail Shafigulin via llvm-dev

unread,
Mar 14, 2016, 2:37:35 PM3/14/16
to Tim Northover, llvm-dev

On Sat, Mar 12, 2016 at 2:38 PM, Tim Northover <t.p.no...@gmail.com> wrote:
On 12 March 2016 at 11:51, Rail Shafigulin via llvm-dev
<llvm...@lists.llvm.org> wrote:
> I tried every possible combination of --target I could think of but nothing
> worked. Would you mind helping me out?

First, 64-bit x86 is "x86_64", and 32-bit is "i386" in the triple. For
ARM you'd probably want "thumbv8" or "aarch64". Also, "eabi" is only a
thing on ARM targets, try "gnu" for x86.

Cheers.

Tim.

Hi Tim.

Thanks for the response. I tried the x86 suggestion but it didn't work. Clearly I'm doing something wrong, but I don't know what exactly. I would really appreciate your help in this. Here is the command line I'm using

clang -S test.c -o test.sse2.x86_64.s --target=x86_64-pc-linux-gnu -mfloat-abi=hard -mcpu=k8 -mfpu=SSE2 -fslp-vectorize-aggressive -fslp-vectorize-aggressive -fslp-vectorize -fvectorize -fno-lax-vector-conversions -O3

Here is the response that I get:

clang-3.5: warning: argument unused during compilation: '-mfloat-abi=hard'
clang-3.5: warning: argument unused during compilation: '-mcpu=k8'
clang-3.5: warning: argument unused during compilation: '-mfpu=SSE2'
error: unable to create target: 'No available targets are compatible with this triple, see -version for the available targets.'

clang --version command produces the following result:

clang version 3.5.0 
Target: x86_64-unknown-linux-gnu
Thread model: posix

test.c is attached to this email. 

So what am I doing wrong?
test.c

Tim Northover via llvm-dev

unread,
Mar 14, 2016, 3:16:05 PM3/14/16
to Rail Shafigulin, llvm-dev
Hi Rail,

In general we follow the GCC options, documented at
https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html for x86 (and
similar places for ARM etc). There may be gaps in what Clang supports,
and possibly even oddities that we support but GNU doesn't (--target
being a case in point). But in general if you're trying to use an
option not listed there you should expect to have a bad time of it.

On 14 March 2016 at 11:37, Rail Shafigulin <ra...@esenciatech.com> wrote:
> clang-3.5: warning: argument unused during compilation: '-mfloat-abi=hard'

Fair enough, there's no soft-float ABI for x86_64.

> clang-3.5: warning: argument unused during compilation: '-mcpu=k8'

x86 uses -march and -mtune instead of -mcpu.


> clang-3.5: warning: argument unused during compilation: '-mfpu=SSE2'

I believe x86 uses "-msse2" for this, but since k8 already has SSE2
(like all 64-bit chips) it shouldn't be needed anyway.

> error: unable to create target: 'No available targets are compatible with
> this triple, see -version for the available targets.'

This I can't explain. It works for me here, where are you getting your
clang from?

> clang version 3.5.0
> Target: x86_64-unknown-linux-gnu
> Thread model: posix

Perhaps try updating Clang? Version 3.5 is getting long in the tooth now.

Ramakrishna Mallireddy via llvm-dev

unread,
Mar 14, 2016, 3:33:02 PM3/14/16
to Tim Northover, llvm-dev
As --version output, your native target triple is:  x86_64-unknown-linux-gnu, & for cross-compilation need to check the build make file settings.

try with x86_64-unknown-linux-gnu, for linux-X86 target.

This is related to llvm 3.9.0,

  if (LLVM_NATIVE_ARCH MATCHES "i[2-6]86")
  set(LLVM_NATIVE_ARCH X86)
elseif (LLVM_NATIVE_ARCH STREQUAL "x86")
  set(LLVM_NATIVE_ARCH X86)
elseif (LLVM_NATIVE_ARCH STREQUAL "amd64")
  set(LLVM_NATIVE_ARCH X86)
elseif (LLVM_NATIVE_ARCH STREQUAL "x86_64")
  set(LLVM_NATIVE_ARCH X86)
elseif (LLVM_NATIVE_ARCH MATCHES "sparc")
  set(LLVM_NATIVE_ARCH Sparc)
elseif (LLVM_NATIVE_ARCH MATCHES "powerpc")
  set(LLVM_NATIVE_ARCH PowerPC)
elseif (LLVM_NATIVE_ARCH MATCHES "aarch64")
  set(LLVM_NATIVE_ARCH AArch64)
elseif (LLVM_NATIVE_ARCH MATCHES "arm64")
  set(LLVM_NATIVE_ARCH AArch64)
elseif (LLVM_NATIVE_ARCH MATCHES "arm")
  set(LLVM_NATIVE_ARCH ARM)
elseif (LLVM_NATIVE_ARCH MATCHES "mips")
  set(LLVM_NATIVE_ARCH Mips)
elseif (LLVM_NATIVE_ARCH MATCHES "xcore")
  set(LLVM_NATIVE_ARCH XCore)
elseif (LLVM_NATIVE_ARCH MATCHES "msp430")
  set(LLVM_NATIVE_ARCH MSP430)
elseif (LLVM_NATIVE_ARCH MATCHES "hexagon")
  set(LLVM_NATIVE_ARCH Hexagon)
elseif (LLVM_NATIVE_ARCH MATCHES "s390x")
  set(LLVM_NATIVE_ARCH SystemZ)
elseif (LLVM_NATIVE_ARCH MATCHES "wasm32")
  set(LLVM_NATIVE_ARCH WebAssembly)
elseif (LLVM_NATIVE_ARCH MATCHES "wasm64")
  set(LLVM_NATIVE_ARCH WebAssembly)
else ()
  message(FATAL_ERROR "Unknown architecture ${LLVM_NATIVE_ARCH}")
endif ()


Rail Shafigulin via llvm-dev

unread,
Mar 14, 2016, 5:28:56 PM3/14/16
to Tim Northover, llvm-dev
Thanks for the info. I'm currently stuck with 3.5, can't really upgrade. As far as not having an available target, it turns out I was using a wrong clang binary (I have several installed). Really appreciate the help.

Daniel Sanders via llvm-dev

unread,
Mar 15, 2016, 11:00:09 AM3/15/16
to Rail Shafigulin, llvm-dev

> clang -S test.c -o test.msa.mips.s --target=mips-pc-linux-gnu -mmsa -mfp64 -mfloat-abi=hard -mcpu=mips32 -fslp-vectorize-aggressive  -fslp-vectorize-aggressive -fslp-vectorize -fvectorize -fno-lax-vector-conversions -O3

'-mcpu=mips32' should be '-mcpu=mips32r2' but even with that it doesn't vectorize your case. We haven't implemented TargetTransformInfo yet so we only get a very small amount of vectorization at the moment. As a quick experiment this afternoon, I tried a small implementation that only reports the number of vector registers and their width. This seems to make a significant improvement to some of the tests in SingleSource/UnitTests/Vector but makes your test case considerably worse. We'll have to find time to implement a proper TargetTransformInfo.

Also, you mentioned you were using clang 3.5 on another part of this thread. The 64-bit MIPS ABI's had a lot of bugs around that time, IIRC the majority of them were fixed in 3.5.1 and a couple rarer ones were fixed in 3.5.2 and 3.6.0.

 


From: Rail Shafigulin [ra...@esenciatech.com]
Sent: 14 March 2016 18:19
To: Daniel Sanders
Cc: Joerg Sonnenberger; llvm-dev
Subject: Re: [llvm-dev] clang triple and clang target

 

On Mon, Mar 14, 2016 at 8:27 AM, Daniel Sanders <Daniel....@imgtec.com> wrote:

Reply all
Reply to author
Forward
0 new messages