LLVM Cross-Compiler: Difference between revisions
[unchecked revision] | [unchecked revision] |
No edit summary |
No edit summary |
||
Line 7: | Line 7: | ||
TODO: Add note about how it works. |
TODO: Add note about how it works. |
||
= Introduction = |
|||
Is as simple as that: |
|||
=== About === |
|||
Generally speaking, a cross-compiler is a compiler that runs on platform A (the '''host'''), but generates executables for platform B (the '''target'''). These two platforms may (but do not need to) differ in CPU, operating system, and/or [[:Category:Executable Formats|executable format]]. |
|||
Clang (and llvm) are host cross compilers. They by default have the capability to cross compile, but also produce host binaries. See Usage |
|||
=== Requirements === |
|||
* A host system with a ''working'' compiler. |
|||
* A bash shell or comparable environment. If you are not using a bash shell, you might have to modify some of the command lines below. If you have just installed the basic [[Cygwin]] package, you have to run the setup.exe again and install the following packages: |
|||
** [[GCC]] (even if you have something like MinGW installed) |
|||
** make |
|||
⚫ | |||
** subversion (if using svn build |
|||
** cmake |
|||
== Building == |
|||
=== Subversion Build (Possibly Unstable) === |
|||
In bash, run |
|||
<source lang="bash"> |
<source lang="bash"> |
||
mkdir crossllvm |
mkdir crossllvm |
||
Line 21: | Line 40: | ||
make |
make |
||
</source> |
</source> |
||
Now you have got llvm built! |
|||
=== Debian === |
|||
Open a terminal |
|||
<source lang="bash"> |
|||
sudo apt-get install clang |
|||
</source> |
|||
Note, you might have to disable host functionality. See Useful Flags |
|||
== Usage == |
|||
After building you will have a compiler able to output multiple output formats regardless of your current platform. |
After building you will have a compiler able to output multiple output formats regardless of your current platform. |
||
For example, for ARM, you can use |
For example, for cross compiling to ARM, you can use |
||
<source lang="bash"> |
<source lang="bash"> |
||
-march=armv7-a -mfloat-abi=soft -ccc-host-triple arm-elf |
-march=armv7-a -mfloat-abi=soft -ccc-host-triple arm-elf |
||
Line 33: | Line 59: | ||
</source> |
</source> |
||
=== Useful Flags === |
|||
Some usefull flags for OS development. |
|||
==== -ffreestanding ==== |
|||
Indicated that the file should be compiled for a freestanding enviroment (like a kernel), not a hosted (userspace), environment. |
|||
==== -fno-builtin ==== |
|||
Disable special handling and optimizations of builtin functions like strlen and malloc. |
|||
==== -nostdlib ==== |
|||
Disables standard library |
|||
==== -nostdinc ==== |
|||
Makes sure the standard library is not included. |
|||
== TODO == |
|||
TODO: beware that clang is both a cross-compiler and a host-compiler and you would have to specify some options to disable host functionality. |
|||
⚫ | |||
TODO: describe non-svn build from released tarballs. |
TODO: describe non-svn build from released tarballs. |
Revision as of 03:12, 31 March 2013
Difficulty level |
---|
Advanced |
EDIT: A mostly working Clang cross-compiler is generated by this buildscript. Dissect it to learn more. TODO: move details to this page.
EDIT: EmbToolkit project recently added support to clang/llvm based cross compiler. TODO: Add note about how it works.
Introduction
About
Generally speaking, a cross-compiler is a compiler that runs on platform A (the host), but generates executables for platform B (the target). These two platforms may (but do not need to) differ in CPU, operating system, and/or executable format.
Clang (and llvm) are host cross compilers. They by default have the capability to cross compile, but also produce host binaries. See Usage
Requirements
- A host system with a working compiler.
- A bash shell or comparable environment. If you are not using a bash shell, you might have to modify some of the command lines below. If you have just installed the basic Cygwin package, you have to run the setup.exe again and install the following packages:
- GCC (even if you have something like MinGW installed)
- make
- binutils (a fairly recent version of binutils, try 2.21 or above if you get assembly compilation errors)
- subversion (if using svn build
- cmake
Building
Subversion Build (Possibly Unstable)
In bash, run
mkdir crossllvm
cd crossllvm
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
cd llvm/tools
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
cd ../..
mkdir build
cd build
cmake ../llvm
make
Now you have got llvm built!
Debian
Open a terminal
sudo apt-get install clang
Note, you might have to disable host functionality. See Useful Flags
Usage
After building you will have a compiler able to output multiple output formats regardless of your current platform.
For example, for cross compiling to ARM, you can use
-march=armv7-a -mfloat-abi=soft -ccc-host-triple arm-elf
Since 3.1, it can be shortened to
-target armv7--eabi -mcpu=cortex-a9
Useful Flags
Some usefull flags for OS development.
-ffreestanding
Indicated that the file should be compiled for a freestanding enviroment (like a kernel), not a hosted (userspace), environment.
-fno-builtin
Disable special handling and optimizations of builtin functions like strlen and malloc.
-nostdlib
Disables standard library
-nostdinc
Makes sure the standard library is not included.
TODO
TODO: describe non-svn build from released tarballs.
TODO: integrate libc++ build instructions