@@ -5,20 +5,21 @@ Cross-compilation using Clang/LLVM
5
5
Introduction
6
6
============
7
7
8
- This document will guide you in choosing the right cross-compilation options
9
- to hopefully help you target your code to a different architecture. It assumes
10
- you already know how to compile the code in question for the host architecture,
8
+ This document will guide you in choosing the right Clang options
9
+ for cross-compiling your code to a different architecture. It assumes you
10
+ already know how to compile the code in question for the host architecture,
11
11
and that you know how to choose additional include and library paths.
12
12
13
- However, this document is `not ` a `HowTo ` and wont help you setting your build
14
- system or Makefiles, nor choosing the right CMake options. Also, it does not
15
- cover all the possible options, nor it contains specific examples for specific
16
- architectures. There are other documents in LLVM that do that in greater
17
- details (ex. http://llvm.org/docs/HowToCrossCompileLLVM.html).
13
+ However, this document is *not * a "how to" and won't help you setting your
14
+ build system or Makefiles, nor choosing the right CMake options, etc.
15
+ Also, it does not cover all the possible options, nor does it contain
16
+ specific examples for specific architectures. For a concrete example, the
17
+ `instructions for cross-compiling LLVM itself
18
+ <http://llvm.org/docs/HowToCrossCompileLLVM.html> `_ may be of interest.
18
19
19
20
After reading this document, you should be familiar with the main issues
20
- related to, and what main compiler options Clang provides for performing
21
- cross-compilation.
21
+ related to cross-compilation , and what main compiler options Clang provides
22
+ for performing cross-compilation.
22
23
23
24
Cross compilation issues
24
25
========================
@@ -30,36 +31,36 @@ that compiler, that will know about its location and find all it needs to
30
31
when compiling your code.
31
32
32
33
On the other hand, Clang/LLVM is natively a cross-compiler, meaning that
33
- one set of programs can compile to all targets by setting the -target
34
- option. That makes it a lot easier to programers wishing to compile to
35
- different platforms and architectures, and to compiler developers that
36
- only have to maintain one build system, and to OS distributions, that
34
+ one set of programs can compile to all targets by setting the `` -target ``
35
+ option. That makes it a lot easier for programers wishing to compile to
36
+ different platforms and architectures, and for compiler developers that
37
+ only have to maintain one build system, and for OS distributions, that
37
38
need only one set of main packages.
38
39
39
40
But, as is true to any cross-compiler, and given the complexity of
40
- different architectures, OSs and options, it's not always easy finding
41
+ different architectures, OS's and options, it's not always easy finding
41
42
the headers, libraries or binutils to generate target specific code.
42
43
So you'll need special options to help Clang understand what target
43
- you're compiling to, where are your tools, etc.
44
+ you're compiling to, where your tools are , etc.
44
45
45
46
Another problem is that compilers come with standard libraries only (like
46
- icompiler -rt, libcxx, libgcc, libm, etc), so you'll have to find and make
47
- available to the build system, every other library required to build your
48
- software, that is specific to your target. It's not enough to have your
49
- host's libraries installed.
47
+ `` compiler -rt``, `` libcxx ``, `` libgcc ``, `` libm `` , etc), so you'll have to
48
+ find and make available to the build system, every other library required
49
+ to build your software, that is specific to your target. It's not enough to
50
+ have your host's libraries installed.
50
51
51
52
Finally, not all toolchains are the same, and consequently, not every Clang
52
- option will work magically. Some options, like --sysroot (which
53
+ option will work magically. Some options, like `` --sysroot `` (which
53
54
effectively changes the logical root for headers and libraries), assume
54
55
all your binaries and libraries are in the same directory, which may not
55
56
true when your cross-compiler was installed by the distribution's package
56
57
management. So, for each specific case, you may use more than one
57
- option, and in most cases, you'll end up setting include paths (-I ) and
58
- library paths (-L ) manually.
58
+ option, and in most cases, you'll end up setting include paths (`` -I `` ) and
59
+ library paths (`` -L `` ) manually.
59
60
60
61
To sum up, different toolchains can:
61
62
* be host/target specific or more flexible
62
- * be in a single directory, or spread out your system
63
+ * be in a single directory, or spread out across your system
63
64
* have different sets of libraries and headers by default
64
65
* need special options, which your build system won't be able to figure
65
66
out by itself
@@ -77,11 +78,11 @@ go ahead, creating code for the host platform, which will break later
77
78
on when assembling or linking.
78
79
79
80
The triple has the general format ``<arch><sub>-<vendor>-<sys>-<abi> ``, where:
80
- * ``arch `` = x86, arm, thumb, mips, etc.
81
- * ``sub `` = for ex. on ARM: v5, v6m, v7a, v7m, etc.
82
- * ``vendor `` = pc, apple, nvidia, ibm, etc.
83
- * ``sys `` = none, linux, win32, darwin, cuda, etc.
84
- * ``abi `` = eabi, gnu, android, macho, elf, etc.
81
+ * ``arch `` = `` x86 ``, `` arm ``, `` thumb ``, `` mips `` , etc.
82
+ * ``sub `` = for ex. on ARM: `` v5 ``, `` v6m ``, `` v7a ``, `` v7m `` , etc.
83
+ * ``vendor `` = `` pc ``, `` apple ``, `` nvidia ``, `` ibm `` , etc.
84
+ * ``sys `` = `` none ``, `` linux ``, `` win32 ``, `` darwin ``, `` cuda `` , etc.
85
+ * ``abi `` = `` eabi ``, `` gnu ``, `` android ``, `` macho ``, `` elf `` , etc.
85
86
86
87
The sub-architecture options are available for their own architectures,
87
88
of course, so "x86v7a" doesn't make sense. The vendor needs to be
@@ -92,9 +93,9 @@ The system name is generally the OS (linux, darwin), but could be special
92
93
like the bare-metal "none".
93
94
94
95
When a parameter is not important, they can be omitted, or you can
95
- choose " unknown" and the defaults will be used. If you choose a parameter
96
- that Clang doesn't know, like " blerg" , it'll ignore and assume ` Unknown `,
97
- which is not always desired, so be careful.
96
+ choose `` unknown `` and the defaults will be used. If you choose a parameter
97
+ that Clang doesn't know, like `` blerg `` , it'll ignore and assume
98
+ `` unknown ``, which is not always desired, so be careful.
98
99
99
100
Finally, the ABI option is something that will pick default CPU/FPU,
100
101
define the specific behaviour of your code (PCS, extensions),
@@ -118,17 +119,17 @@ generate code that breaks. But that also means you won't get the best
118
119
code for your specific hardware, which may mean orders of magnitude
119
120
slower than you expect.
120
121
121
- For example, if your target is " arm-none-eabi" , the default CPU will
122
- be " arm7tdmi" using soft float, which is extremely slow on modern cores,
123
- whereas if your triple is " armv7a-none-eabi" , it'll be Cortex-A8 with
122
+ For example, if your target is `` arm-none-eabi `` , the default CPU will
123
+ be `` arm7tdmi `` using soft float, which is extremely slow on modern cores,
124
+ whereas if your triple is `` armv7a-none-eabi `` , it'll be Cortex-A8 with
124
125
NEON, but still using soft-float, which is much better, but still not
125
126
great.
126
127
127
128
Toolchain Options
128
129
-----------------
129
130
130
- There are four main options to control access to your cross-compiler:
131
- ``--sysroot ``, ``-I `` and ``-L ``. The two last ones are well known,
131
+ There are three main options to control access to your cross-compiler:
132
+ ``--sysroot ``, ``-I ``, and ``-L ``. The two last ones are well known,
132
133
but they're particularly important for additional libraries
133
134
and headers that are specific to your target.
134
135
@@ -145,7 +146,7 @@ There are two main ways to have a cross-compiler:
145
146
146
147
#. When you have installed via a package manager (modern Linux
147
148
distributions have cross-compiler packages available), make
148
- sure the target triple you set is ` also ` the prefix of your
149
+ sure the target triple you set is * also * the prefix of your
149
150
cross-compiler toolchain.
150
151
151
152
In this case, Clang will find the other binaries (assembler,
@@ -163,7 +164,7 @@ Target-Specific Libraries
163
164
All libraries that you compile as part of your build will be
164
165
cross-compiled to your target, and your build system will probably
165
166
find them in the right place. But all dependencies that are
166
- normally checked against (like libxml or libz etc) will match
167
+ normally checked against (like `` libxml `` or `` libz `` etc) will match
167
168
against the host platform, not the target.
168
169
169
170
So, if the build system is not aware that you want to cross-compile
@@ -172,7 +173,7 @@ will fail during build time, not configure time.
172
173
173
174
Also, finding the libraries for your target are not as easy
174
175
as for your host machine. There aren't many cross-libraries available
175
- as packages to most OSs , so you'll have to either cross-compile them
176
+ as packages to most OS's , so you'll have to either cross-compile them
176
177
from source, or download the package for your target platform,
177
178
extract the libraries and headers, put them in specific directories
178
179
and add ``-I `` and ``-L `` pointing to them.
@@ -199,5 +200,5 @@ uses hard-float), Clang will pick the ``armv7l-linux-gnueabi-ld``
199
200
200
201
The same is true if you're compiling for different ABIs, like ``gnueabi ``
201
202
and ``androideabi ``, and might even link and run, but produce run-time
202
- errors, which are much harder to track and fix.
203
+ errors, which are much harder to track down and fix.
203
204
0 commit comments