LLVM Cross-Compiler: Difference between revisions
[unchecked revision] | [unchecked revision] |
No edit summary |
|||
Line 2:
= Introduction =
NOTE: This article is not complete.
Having working and production ready llvm cross-compiler involves much more work than just what is explained here
(such that having llvm/clang use correct target associated sysroot, static linker, C/C++ libraries, etc.)
See [http://clang.llvm.org/UniversalDriver.html clang Universal driver].
For working and production ready clang/llvm cross-compiler use tools generating one for you sush as [http://www.embtoolkit.org EmbToolkit]
=== About ===
Line 86 ⟶ 91:
== TODO ==
TODO: describe non-svn build from released tarballs.
|
Revision as of 19:04, 31 July 2013
Difficulty level |
---|
Advanced |
Introduction
NOTE: This article is not complete. Having working and production ready llvm cross-compiler involves much more work than just what is explained here (such that having llvm/clang use correct target associated sysroot, static linker, C/C++ libraries, etc.) See clang Universal driver. For working and production ready clang/llvm cross-compiler use tools generating one for you sush as EmbToolkit
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)
- git (if using git build)
- cmake
Building
Git Build (Possibly Unstable)
In bash, run
mkdir crossllvm
cd crossllvm
git clone http://llvm.org/git/llvm.git
cd llvm/tools
git clone http://llvm.org/git/clang.git
cd ../..
mkdir build
cd build
cmake ../llvm
make
Now you have got llvm built!
A faster and more up-to-date way is posted here. It uses ninja for much faster building.
A Clang cross-compiler is generated by this buildscript. Dissect it to learn more. It uses some gcc and binutils to provide a fully working toolchain.
Debian
Open a terminal
sudo apt-get install clang
Note, you might have to disable host functionality. See Useful Flags
Building libc++
$ git clone http://llvm.org/git/libcxx.git
$ export TRIPLE=-apple-
$ cd libcxx/lib
$ ./buildit
Built libc++ is not installed by default, you can use make install or copy files manually.
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 headers are not included.
-nostdinc++
Makes sure the standard C++ library headers are not included. This makes sense if you build a custom version of libc++ and want to avoid including system one.
TODO
TODO: describe non-svn build from released tarballs. TODO: EmbToolkit project recently added support to clang/llvm based cross compiler, ddd note about how it works.