1*9880d681SAndroid Build Coastguard Worker==================================== 2*9880d681SAndroid Build Coastguard WorkerGetting Started with the LLVM System 3*9880d681SAndroid Build Coastguard Worker==================================== 4*9880d681SAndroid Build Coastguard Worker 5*9880d681SAndroid Build Coastguard Worker.. contents:: 6*9880d681SAndroid Build Coastguard Worker :local: 7*9880d681SAndroid Build Coastguard Worker 8*9880d681SAndroid Build Coastguard WorkerOverview 9*9880d681SAndroid Build Coastguard Worker======== 10*9880d681SAndroid Build Coastguard Worker 11*9880d681SAndroid Build Coastguard WorkerWelcome to LLVM! In order to get started, you first need to know some basic 12*9880d681SAndroid Build Coastguard Workerinformation. 13*9880d681SAndroid Build Coastguard Worker 14*9880d681SAndroid Build Coastguard WorkerFirst, LLVM comes in three pieces. The first piece is the LLVM suite. This 15*9880d681SAndroid Build Coastguard Workercontains all of the tools, libraries, and header files needed to use LLVM. It 16*9880d681SAndroid Build Coastguard Workercontains an assembler, disassembler, bitcode analyzer and bitcode optimizer. It 17*9880d681SAndroid Build Coastguard Workeralso contains basic regression tests that can be used to test the LLVM tools and 18*9880d681SAndroid Build Coastguard Workerthe Clang front end. 19*9880d681SAndroid Build Coastguard Worker 20*9880d681SAndroid Build Coastguard WorkerThe second piece is the `Clang <http://clang.llvm.org/>`_ front end. This 21*9880d681SAndroid Build Coastguard Workercomponent compiles C, C++, Objective C, and Objective C++ code into LLVM 22*9880d681SAndroid Build Coastguard Workerbitcode. Once compiled into LLVM bitcode, a program can be manipulated with the 23*9880d681SAndroid Build Coastguard WorkerLLVM tools from the LLVM suite. 24*9880d681SAndroid Build Coastguard Worker 25*9880d681SAndroid Build Coastguard WorkerThere is a third, optional piece called Test Suite. It is a suite of programs 26*9880d681SAndroid Build Coastguard Workerwith a testing harness that can be used to further test LLVM's functionality 27*9880d681SAndroid Build Coastguard Workerand performance. 28*9880d681SAndroid Build Coastguard Worker 29*9880d681SAndroid Build Coastguard WorkerGetting Started Quickly (A Summary) 30*9880d681SAndroid Build Coastguard Worker=================================== 31*9880d681SAndroid Build Coastguard Worker 32*9880d681SAndroid Build Coastguard WorkerThe LLVM Getting Started documentation may be out of date. So, the `Clang 33*9880d681SAndroid Build Coastguard WorkerGetting Started <http://clang.llvm.org/get_started.html>`_ page might also be a 34*9880d681SAndroid Build Coastguard Workergood place to start. 35*9880d681SAndroid Build Coastguard Worker 36*9880d681SAndroid Build Coastguard WorkerHere's the short story for getting up and running quickly with LLVM: 37*9880d681SAndroid Build Coastguard Worker 38*9880d681SAndroid Build Coastguard Worker#. Read the documentation. 39*9880d681SAndroid Build Coastguard Worker#. Read the documentation. 40*9880d681SAndroid Build Coastguard Worker#. Remember that you were warned twice about reading the documentation. 41*9880d681SAndroid Build Coastguard Worker 42*9880d681SAndroid Build Coastguard Worker * In particular, the *relative paths specified are important*. 43*9880d681SAndroid Build Coastguard Worker 44*9880d681SAndroid Build Coastguard Worker#. Checkout LLVM: 45*9880d681SAndroid Build Coastguard Worker 46*9880d681SAndroid Build Coastguard Worker * ``cd where-you-want-llvm-to-live`` 47*9880d681SAndroid Build Coastguard Worker * ``svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm`` 48*9880d681SAndroid Build Coastguard Worker 49*9880d681SAndroid Build Coastguard Worker#. Checkout Clang: 50*9880d681SAndroid Build Coastguard Worker 51*9880d681SAndroid Build Coastguard Worker * ``cd where-you-want-llvm-to-live`` 52*9880d681SAndroid Build Coastguard Worker * ``cd llvm/tools`` 53*9880d681SAndroid Build Coastguard Worker * ``svn co http://llvm.org/svn/llvm-project/cfe/trunk clang`` 54*9880d681SAndroid Build Coastguard Worker 55*9880d681SAndroid Build Coastguard Worker#. Checkout Compiler-RT (required to build the sanitizers) **[Optional]**: 56*9880d681SAndroid Build Coastguard Worker 57*9880d681SAndroid Build Coastguard Worker * ``cd where-you-want-llvm-to-live`` 58*9880d681SAndroid Build Coastguard Worker * ``cd llvm/projects`` 59*9880d681SAndroid Build Coastguard Worker * ``svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt`` 60*9880d681SAndroid Build Coastguard Worker 61*9880d681SAndroid Build Coastguard Worker#. Checkout Libomp (required for OpenMP support) **[Optional]**: 62*9880d681SAndroid Build Coastguard Worker 63*9880d681SAndroid Build Coastguard Worker * ``cd where-you-want-llvm-to-live`` 64*9880d681SAndroid Build Coastguard Worker * ``cd llvm/projects`` 65*9880d681SAndroid Build Coastguard Worker * ``svn co http://llvm.org/svn/llvm-project/openmp/trunk openmp`` 66*9880d681SAndroid Build Coastguard Worker 67*9880d681SAndroid Build Coastguard Worker#. Checkout libcxx and libcxxabi **[Optional]**: 68*9880d681SAndroid Build Coastguard Worker 69*9880d681SAndroid Build Coastguard Worker * ``cd where-you-want-llvm-to-live`` 70*9880d681SAndroid Build Coastguard Worker * ``cd llvm/projects`` 71*9880d681SAndroid Build Coastguard Worker * ``svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx`` 72*9880d681SAndroid Build Coastguard Worker * ``svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi`` 73*9880d681SAndroid Build Coastguard Worker 74*9880d681SAndroid Build Coastguard Worker#. Get the Test Suite Source Code **[Optional]** 75*9880d681SAndroid Build Coastguard Worker 76*9880d681SAndroid Build Coastguard Worker * ``cd where-you-want-llvm-to-live`` 77*9880d681SAndroid Build Coastguard Worker * ``cd llvm/projects`` 78*9880d681SAndroid Build Coastguard Worker * ``svn co http://llvm.org/svn/llvm-project/test-suite/trunk test-suite`` 79*9880d681SAndroid Build Coastguard Worker 80*9880d681SAndroid Build Coastguard Worker#. Configure and build LLVM and Clang: 81*9880d681SAndroid Build Coastguard Worker 82*9880d681SAndroid Build Coastguard Worker *Warning:* Make sure you've checked out *all of* the source code 83*9880d681SAndroid Build Coastguard Worker before trying to configure with cmake. cmake does not pickup newly 84*9880d681SAndroid Build Coastguard Worker added source directories in incremental builds. 85*9880d681SAndroid Build Coastguard Worker 86*9880d681SAndroid Build Coastguard Worker The build uses `CMake <CMake.html>`_. LLVM requires CMake 3.4.3 to build. It 87*9880d681SAndroid Build Coastguard Worker is generally recommended to use a recent CMake, especially if you're 88*9880d681SAndroid Build Coastguard Worker generating Ninja build files. This is because the CMake project is constantly 89*9880d681SAndroid Build Coastguard Worker improving the quality of the generators, and the Ninja generator gets a lot 90*9880d681SAndroid Build Coastguard Worker of attention. 91*9880d681SAndroid Build Coastguard Worker 92*9880d681SAndroid Build Coastguard Worker * ``cd where you want to build llvm`` 93*9880d681SAndroid Build Coastguard Worker * ``mkdir build`` 94*9880d681SAndroid Build Coastguard Worker * ``cd build`` 95*9880d681SAndroid Build Coastguard Worker * ``cmake -G <generator> [options] <path to llvm sources>`` 96*9880d681SAndroid Build Coastguard Worker 97*9880d681SAndroid Build Coastguard Worker Some common generators are: 98*9880d681SAndroid Build Coastguard Worker 99*9880d681SAndroid Build Coastguard Worker * ``Unix Makefiles`` --- for generating make-compatible parallel makefiles. 100*9880d681SAndroid Build Coastguard Worker * ``Ninja`` --- for generating `Ninja <https://ninja-build.org>`_ 101*9880d681SAndroid Build Coastguard Worker build files. Most llvm developers use Ninja. 102*9880d681SAndroid Build Coastguard Worker * ``Visual Studio`` --- for generating Visual Studio projects and 103*9880d681SAndroid Build Coastguard Worker solutions. 104*9880d681SAndroid Build Coastguard Worker * ``Xcode`` --- for generating Xcode projects. 105*9880d681SAndroid Build Coastguard Worker 106*9880d681SAndroid Build Coastguard Worker Some Common options: 107*9880d681SAndroid Build Coastguard Worker 108*9880d681SAndroid Build Coastguard Worker * ``-DCMAKE_INSTALL_PREFIX=directory`` --- Specify for *directory* the full 109*9880d681SAndroid Build Coastguard Worker pathname of where you want the LLVM tools and libraries to be installed 110*9880d681SAndroid Build Coastguard Worker (default ``/usr/local``). 111*9880d681SAndroid Build Coastguard Worker 112*9880d681SAndroid Build Coastguard Worker * ``-DCMAKE_BUILD_TYPE=type`` --- Valid options for *type* are Debug, 113*9880d681SAndroid Build Coastguard Worker Release, RelWithDebInfo, and MinSizeRel. Default is Debug. 114*9880d681SAndroid Build Coastguard Worker 115*9880d681SAndroid Build Coastguard Worker * ``-DLLVM_ENABLE_ASSERTIONS=On`` --- Compile with assertion checks enabled 116*9880d681SAndroid Build Coastguard Worker (default is Yes for Debug builds, No for all other build types). 117*9880d681SAndroid Build Coastguard Worker 118*9880d681SAndroid Build Coastguard Worker * Run your build tool of choice! 119*9880d681SAndroid Build Coastguard Worker 120*9880d681SAndroid Build Coastguard Worker * The default target (i.e. ``make``) will build all of LLVM 121*9880d681SAndroid Build Coastguard Worker 122*9880d681SAndroid Build Coastguard Worker * The ``check-all`` target (i.e. ``make check-all``) will run the 123*9880d681SAndroid Build Coastguard Worker regression tests to ensure everything is in working order. 124*9880d681SAndroid Build Coastguard Worker 125*9880d681SAndroid Build Coastguard Worker * CMake will generate build targets for each tool and library, and most 126*9880d681SAndroid Build Coastguard Worker LLVM sub-projects generate their own ``check-<project>`` target. 127*9880d681SAndroid Build Coastguard Worker 128*9880d681SAndroid Build Coastguard Worker * Running a serial build will be *slow*. Make sure you run a 129*9880d681SAndroid Build Coastguard Worker parallel build; for ``make``, use ``make -j``. 130*9880d681SAndroid Build Coastguard Worker 131*9880d681SAndroid Build Coastguard Worker * For more information see `CMake <CMake.html>`_ 132*9880d681SAndroid Build Coastguard Worker 133*9880d681SAndroid Build Coastguard Worker * If you get an "internal compiler error (ICE)" or test failures, see 134*9880d681SAndroid Build Coastguard Worker `below`_. 135*9880d681SAndroid Build Coastguard Worker 136*9880d681SAndroid Build Coastguard WorkerConsult the `Getting Started with LLVM`_ section for detailed information on 137*9880d681SAndroid Build Coastguard Workerconfiguring and compiling LLVM. Go to `Directory Layout`_ to learn about the 138*9880d681SAndroid Build Coastguard Workerlayout of the source code tree. 139*9880d681SAndroid Build Coastguard Worker 140*9880d681SAndroid Build Coastguard WorkerRequirements 141*9880d681SAndroid Build Coastguard Worker============ 142*9880d681SAndroid Build Coastguard Worker 143*9880d681SAndroid Build Coastguard WorkerBefore you begin to use the LLVM system, review the requirements given below. 144*9880d681SAndroid Build Coastguard WorkerThis may save you some trouble by knowing ahead of time what hardware and 145*9880d681SAndroid Build Coastguard Workersoftware you will need. 146*9880d681SAndroid Build Coastguard Worker 147*9880d681SAndroid Build Coastguard WorkerHardware 148*9880d681SAndroid Build Coastguard Worker-------- 149*9880d681SAndroid Build Coastguard Worker 150*9880d681SAndroid Build Coastguard WorkerLLVM is known to work on the following host platforms: 151*9880d681SAndroid Build Coastguard Worker 152*9880d681SAndroid Build Coastguard Worker================== ===================== ============= 153*9880d681SAndroid Build Coastguard WorkerOS Arch Compilers 154*9880d681SAndroid Build Coastguard Worker================== ===================== ============= 155*9880d681SAndroid Build Coastguard WorkerLinux x86\ :sup:`1` GCC, Clang 156*9880d681SAndroid Build Coastguard WorkerLinux amd64 GCC, Clang 157*9880d681SAndroid Build Coastguard WorkerLinux ARM\ :sup:`4` GCC, Clang 158*9880d681SAndroid Build Coastguard WorkerLinux PowerPC GCC, Clang 159*9880d681SAndroid Build Coastguard WorkerSolaris V9 (Ultrasparc) GCC 160*9880d681SAndroid Build Coastguard WorkerFreeBSD x86\ :sup:`1` GCC, Clang 161*9880d681SAndroid Build Coastguard WorkerFreeBSD amd64 GCC, Clang 162*9880d681SAndroid Build Coastguard WorkerMacOS X\ :sup:`2` PowerPC GCC 163*9880d681SAndroid Build Coastguard WorkerMacOS X x86 GCC, Clang 164*9880d681SAndroid Build Coastguard WorkerCygwin/Win32 x86\ :sup:`1, 3` GCC 165*9880d681SAndroid Build Coastguard WorkerWindows x86\ :sup:`1` Visual Studio 166*9880d681SAndroid Build Coastguard WorkerWindows x64 x86-64 Visual Studio 167*9880d681SAndroid Build Coastguard Worker================== ===================== ============= 168*9880d681SAndroid Build Coastguard Worker 169*9880d681SAndroid Build Coastguard Worker.. note:: 170*9880d681SAndroid Build Coastguard Worker 171*9880d681SAndroid Build Coastguard Worker #. Code generation supported for Pentium processors and up 172*9880d681SAndroid Build Coastguard Worker #. Code generation supported for 32-bit ABI only 173*9880d681SAndroid Build Coastguard Worker #. To use LLVM modules on Win32-based system, you may configure LLVM 174*9880d681SAndroid Build Coastguard Worker with ``-DBUILD_SHARED_LIBS=On``. 175*9880d681SAndroid Build Coastguard Worker #. MCJIT not working well pre-v7, old JIT engine not supported any more. 176*9880d681SAndroid Build Coastguard Worker 177*9880d681SAndroid Build Coastguard WorkerNote that Debug builds require a lot of time and disk space. An LLVM-only build 178*9880d681SAndroid Build Coastguard Workerwill need about 1-3 GB of space. A full build of LLVM and Clang will need around 179*9880d681SAndroid Build Coastguard Worker15-20 GB of disk space. The exact space requirements will vary by system. (It 180*9880d681SAndroid Build Coastguard Workeris so large because of all the debugging information and the fact that the 181*9880d681SAndroid Build Coastguard Workerlibraries are statically linked into multiple tools). 182*9880d681SAndroid Build Coastguard Worker 183*9880d681SAndroid Build Coastguard WorkerIf you you are space-constrained, you can build only selected tools or only 184*9880d681SAndroid Build Coastguard Workerselected targets. The Release build requires considerably less space. 185*9880d681SAndroid Build Coastguard Worker 186*9880d681SAndroid Build Coastguard WorkerThe LLVM suite *may* compile on other platforms, but it is not guaranteed to do 187*9880d681SAndroid Build Coastguard Workerso. If compilation is successful, the LLVM utilities should be able to 188*9880d681SAndroid Build Coastguard Workerassemble, disassemble, analyze, and optimize LLVM bitcode. Code generation 189*9880d681SAndroid Build Coastguard Workershould work as well, although the generated native code may not work on your 190*9880d681SAndroid Build Coastguard Workerplatform. 191*9880d681SAndroid Build Coastguard Worker 192*9880d681SAndroid Build Coastguard WorkerSoftware 193*9880d681SAndroid Build Coastguard Worker-------- 194*9880d681SAndroid Build Coastguard Worker 195*9880d681SAndroid Build Coastguard WorkerCompiling LLVM requires that you have several software packages installed. The 196*9880d681SAndroid Build Coastguard Workertable below lists those required packages. The Package column is the usual name 197*9880d681SAndroid Build Coastguard Workerfor the software package that LLVM depends on. The Version column provides 198*9880d681SAndroid Build Coastguard Worker"known to work" versions of the package. The Notes column describes how LLVM 199*9880d681SAndroid Build Coastguard Workeruses the package and provides other details. 200*9880d681SAndroid Build Coastguard Worker 201*9880d681SAndroid Build Coastguard Worker=========================================================== ============ ========================================== 202*9880d681SAndroid Build Coastguard WorkerPackage Version Notes 203*9880d681SAndroid Build Coastguard Worker=========================================================== ============ ========================================== 204*9880d681SAndroid Build Coastguard Worker`GNU Make <http://savannah.gnu.org/projects/make>`_ 3.79, 3.79.1 Makefile/build processor 205*9880d681SAndroid Build Coastguard Worker`GCC <http://gcc.gnu.org/>`_ >=4.7.0 C/C++ compiler\ :sup:`1` 206*9880d681SAndroid Build Coastguard Worker`python <http://www.python.org/>`_ >=2.7 Automated test suite\ :sup:`2` 207*9880d681SAndroid Build Coastguard Worker`zlib <http://zlib.net>`_ >=1.2.3.4 Compression library\ :sup:`3` 208*9880d681SAndroid Build Coastguard Worker=========================================================== ============ ========================================== 209*9880d681SAndroid Build Coastguard Worker 210*9880d681SAndroid Build Coastguard Worker.. note:: 211*9880d681SAndroid Build Coastguard Worker 212*9880d681SAndroid Build Coastguard Worker #. Only the C and C++ languages are needed so there's no need to build the 213*9880d681SAndroid Build Coastguard Worker other languages for LLVM's purposes. See `below` for specific version 214*9880d681SAndroid Build Coastguard Worker info. 215*9880d681SAndroid Build Coastguard Worker #. Only needed if you want to run the automated test suite in the 216*9880d681SAndroid Build Coastguard Worker ``llvm/test`` directory. 217*9880d681SAndroid Build Coastguard Worker #. Optional, adds compression / uncompression capabilities to selected LLVM 218*9880d681SAndroid Build Coastguard Worker tools. 219*9880d681SAndroid Build Coastguard Worker 220*9880d681SAndroid Build Coastguard WorkerAdditionally, your compilation host is expected to have the usual plethora of 221*9880d681SAndroid Build Coastguard WorkerUnix utilities. Specifically: 222*9880d681SAndroid Build Coastguard Worker 223*9880d681SAndroid Build Coastguard Worker* **ar** --- archive library builder 224*9880d681SAndroid Build Coastguard Worker* **bzip2** --- bzip2 command for distribution generation 225*9880d681SAndroid Build Coastguard Worker* **bunzip2** --- bunzip2 command for distribution checking 226*9880d681SAndroid Build Coastguard Worker* **chmod** --- change permissions on a file 227*9880d681SAndroid Build Coastguard Worker* **cat** --- output concatenation utility 228*9880d681SAndroid Build Coastguard Worker* **cp** --- copy files 229*9880d681SAndroid Build Coastguard Worker* **date** --- print the current date/time 230*9880d681SAndroid Build Coastguard Worker* **echo** --- print to standard output 231*9880d681SAndroid Build Coastguard Worker* **egrep** --- extended regular expression search utility 232*9880d681SAndroid Build Coastguard Worker* **find** --- find files/dirs in a file system 233*9880d681SAndroid Build Coastguard Worker* **grep** --- regular expression search utility 234*9880d681SAndroid Build Coastguard Worker* **gzip** --- gzip command for distribution generation 235*9880d681SAndroid Build Coastguard Worker* **gunzip** --- gunzip command for distribution checking 236*9880d681SAndroid Build Coastguard Worker* **install** --- install directories/files 237*9880d681SAndroid Build Coastguard Worker* **mkdir** --- create a directory 238*9880d681SAndroid Build Coastguard Worker* **mv** --- move (rename) files 239*9880d681SAndroid Build Coastguard Worker* **ranlib** --- symbol table builder for archive libraries 240*9880d681SAndroid Build Coastguard Worker* **rm** --- remove (delete) files and directories 241*9880d681SAndroid Build Coastguard Worker* **sed** --- stream editor for transforming output 242*9880d681SAndroid Build Coastguard Worker* **sh** --- Bourne shell for make build scripts 243*9880d681SAndroid Build Coastguard Worker* **tar** --- tape archive for distribution generation 244*9880d681SAndroid Build Coastguard Worker* **test** --- test things in file system 245*9880d681SAndroid Build Coastguard Worker* **unzip** --- unzip command for distribution checking 246*9880d681SAndroid Build Coastguard Worker* **zip** --- zip command for distribution generation 247*9880d681SAndroid Build Coastguard Worker 248*9880d681SAndroid Build Coastguard Worker.. _below: 249*9880d681SAndroid Build Coastguard Worker.. _check here: 250*9880d681SAndroid Build Coastguard Worker 251*9880d681SAndroid Build Coastguard WorkerHost C++ Toolchain, both Compiler and Standard Library 252*9880d681SAndroid Build Coastguard Worker------------------------------------------------------ 253*9880d681SAndroid Build Coastguard Worker 254*9880d681SAndroid Build Coastguard WorkerLLVM is very demanding of the host C++ compiler, and as such tends to expose 255*9880d681SAndroid Build Coastguard Workerbugs in the compiler. We are also planning to follow improvements and 256*9880d681SAndroid Build Coastguard Workerdevelopments in the C++ language and library reasonably closely. As such, we 257*9880d681SAndroid Build Coastguard Workerrequire a modern host C++ toolchain, both compiler and standard library, in 258*9880d681SAndroid Build Coastguard Workerorder to build LLVM. 259*9880d681SAndroid Build Coastguard Worker 260*9880d681SAndroid Build Coastguard WorkerFor the most popular host toolchains we check for specific minimum versions in 261*9880d681SAndroid Build Coastguard Workerour build systems: 262*9880d681SAndroid Build Coastguard Worker 263*9880d681SAndroid Build Coastguard Worker* Clang 3.1 264*9880d681SAndroid Build Coastguard Worker* GCC 4.7 265*9880d681SAndroid Build Coastguard Worker* Visual Studio 2013 266*9880d681SAndroid Build Coastguard Worker 267*9880d681SAndroid Build Coastguard WorkerAnything older than these toolchains *may* work, but will require forcing the 268*9880d681SAndroid Build Coastguard Workerbuild system with a special option and is not really a supported host platform. 269*9880d681SAndroid Build Coastguard WorkerAlso note that older versions of these compilers have often crashed or 270*9880d681SAndroid Build Coastguard Workermiscompiled LLVM. 271*9880d681SAndroid Build Coastguard Worker 272*9880d681SAndroid Build Coastguard WorkerFor less widely used host toolchains such as ICC or xlC, be aware that a very 273*9880d681SAndroid Build Coastguard Workerrecent version may be required to support all of the C++ features used in LLVM. 274*9880d681SAndroid Build Coastguard Worker 275*9880d681SAndroid Build Coastguard WorkerWe track certain versions of software that are *known* to fail when used as 276*9880d681SAndroid Build Coastguard Workerpart of the host toolchain. These even include linkers at times. 277*9880d681SAndroid Build Coastguard Worker 278*9880d681SAndroid Build Coastguard Worker**GCC 4.6.3 on ARM**: Miscompiles ``llvm-readobj`` at ``-O3``. A test failure 279*9880d681SAndroid Build Coastguard Workerin ``test/Object/readobj-shared-object.test`` is one symptom of the problem. 280*9880d681SAndroid Build Coastguard Worker 281*9880d681SAndroid Build Coastguard Worker**GNU ld 2.16.X**. Some 2.16.X versions of the ld linker will produce very long 282*9880d681SAndroid Build Coastguard Workerwarning messages complaining that some "``.gnu.linkonce.t.*``" symbol was 283*9880d681SAndroid Build Coastguard Workerdefined in a discarded section. You can safely ignore these messages as they are 284*9880d681SAndroid Build Coastguard Workererroneous and the linkage is correct. These messages disappear using ld 2.17. 285*9880d681SAndroid Build Coastguard Worker 286*9880d681SAndroid Build Coastguard Worker**GNU binutils 2.17**: Binutils 2.17 contains `a bug 287*9880d681SAndroid Build Coastguard Worker<http://sourceware.org/bugzilla/show_bug.cgi?id=3111>`__ which causes huge link 288*9880d681SAndroid Build Coastguard Workertimes (minutes instead of seconds) when building LLVM. We recommend upgrading 289*9880d681SAndroid Build Coastguard Workerto a newer version (2.17.50.0.4 or later). 290*9880d681SAndroid Build Coastguard Worker 291*9880d681SAndroid Build Coastguard Worker**GNU Binutils 2.19.1 Gold**: This version of Gold contained `a bug 292*9880d681SAndroid Build Coastguard Worker<http://sourceware.org/bugzilla/show_bug.cgi?id=9836>`__ which causes 293*9880d681SAndroid Build Coastguard Workerintermittent failures when building LLVM with position independent code. The 294*9880d681SAndroid Build Coastguard Workersymptom is an error about cyclic dependencies. We recommend upgrading to a 295*9880d681SAndroid Build Coastguard Workernewer version of Gold. 296*9880d681SAndroid Build Coastguard Worker 297*9880d681SAndroid Build Coastguard Worker**Clang 3.0 with libstdc++ 4.7.x**: a few Linux distributions (Ubuntu 12.10, 298*9880d681SAndroid Build Coastguard WorkerFedora 17) have both Clang 3.0 and libstdc++ 4.7 in their repositories. Clang 299*9880d681SAndroid Build Coastguard Worker3.0 does not implement a few builtins that are used in this library. We 300*9880d681SAndroid Build Coastguard Workerrecommend using the system GCC to compile LLVM and Clang in this case. 301*9880d681SAndroid Build Coastguard Worker 302*9880d681SAndroid Build Coastguard Worker**Clang 3.0 on Mageia 2**. There's a packaging issue: Clang can not find at 303*9880d681SAndroid Build Coastguard Workerleast some (``cxxabi.h``) libstdc++ headers. 304*9880d681SAndroid Build Coastguard Worker 305*9880d681SAndroid Build Coastguard Worker**Clang in C++11 mode and libstdc++ 4.7.2**. This version of libstdc++ 306*9880d681SAndroid Build Coastguard Workercontained `a bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53841>`__ which 307*9880d681SAndroid Build Coastguard Workercauses Clang to refuse to compile condition_variable header file. At the time 308*9880d681SAndroid Build Coastguard Workerof writing, this breaks LLD build. 309*9880d681SAndroid Build Coastguard Worker 310*9880d681SAndroid Build Coastguard WorkerGetting a Modern Host C++ Toolchain 311*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 312*9880d681SAndroid Build Coastguard Worker 313*9880d681SAndroid Build Coastguard WorkerThis section mostly applies to Linux and older BSDs. On Mac OS X, you should 314*9880d681SAndroid Build Coastguard Workerhave a sufficiently modern Xcode, or you will likely need to upgrade until you 315*9880d681SAndroid Build Coastguard Workerdo. On Windows, just use Visual Studio 2013 as the host compiler, it is 316*9880d681SAndroid Build Coastguard Workerexplicitly supported and widely available. FreeBSD 10.0 and newer have a modern 317*9880d681SAndroid Build Coastguard WorkerClang as the system compiler. 318*9880d681SAndroid Build Coastguard Worker 319*9880d681SAndroid Build Coastguard WorkerHowever, some Linux distributions and some other or older BSDs sometimes have 320*9880d681SAndroid Build Coastguard Workerextremely old versions of GCC. These steps attempt to help you upgrade you 321*9880d681SAndroid Build Coastguard Workercompiler even on such a system. However, if at all possible, we encourage you 322*9880d681SAndroid Build Coastguard Workerto use a recent version of a distribution with a modern system compiler that 323*9880d681SAndroid Build Coastguard Workermeets these requirements. Note that it is tempting to to install a prior 324*9880d681SAndroid Build Coastguard Workerversion of Clang and libc++ to be the host compiler, however libc++ was not 325*9880d681SAndroid Build Coastguard Workerwell tested or set up to build on Linux until relatively recently. As 326*9880d681SAndroid Build Coastguard Workera consequence, this guide suggests just using libstdc++ and a modern GCC as the 327*9880d681SAndroid Build Coastguard Workerinitial host in a bootstrap, and then using Clang (and potentially libc++). 328*9880d681SAndroid Build Coastguard Worker 329*9880d681SAndroid Build Coastguard WorkerThe first step is to get a recent GCC toolchain installed. The most common 330*9880d681SAndroid Build Coastguard Workerdistribution on which users have struggled with the version requirements is 331*9880d681SAndroid Build Coastguard WorkerUbuntu Precise, 12.04 LTS. For this distribution, one easy option is to install 332*9880d681SAndroid Build Coastguard Workerthe `toolchain testing PPA`_ and use it to install a modern GCC. There is 333*9880d681SAndroid Build Coastguard Workera really nice discussions of this on the `ask ubuntu stack exchange`_. However, 334*9880d681SAndroid Build Coastguard Workernot all users can use PPAs and there are many other distributions, so it may be 335*9880d681SAndroid Build Coastguard Workernecessary (or just useful, if you're here you *are* doing compiler development 336*9880d681SAndroid Build Coastguard Workerafter all) to build and install GCC from source. It is also quite easy to do 337*9880d681SAndroid Build Coastguard Workerthese days. 338*9880d681SAndroid Build Coastguard Worker 339*9880d681SAndroid Build Coastguard Worker.. _toolchain testing PPA: 340*9880d681SAndroid Build Coastguard Worker https://launchpad.net/~ubuntu-toolchain-r/+archive/test 341*9880d681SAndroid Build Coastguard Worker.. _ask ubuntu stack exchange: 342*9880d681SAndroid Build Coastguard Worker http://askubuntu.com/questions/271388/how-to-install-gcc-4-8-in-ubuntu-12-04-from-the-terminal 343*9880d681SAndroid Build Coastguard Worker 344*9880d681SAndroid Build Coastguard WorkerEasy steps for installing GCC 4.8.2: 345*9880d681SAndroid Build Coastguard Worker 346*9880d681SAndroid Build Coastguard Worker.. code-block:: console 347*9880d681SAndroid Build Coastguard Worker 348*9880d681SAndroid Build Coastguard Worker % wget https://ftp.gnu.org/gnu/gcc/gcc-4.8.2/gcc-4.8.2.tar.bz2 349*9880d681SAndroid Build Coastguard Worker % wget https://ftp.gnu.org/gnu/gcc/gcc-4.8.2/gcc-4.8.2.tar.bz2.sig 350*9880d681SAndroid Build Coastguard Worker % wget https://ftp.gnu.org/gnu/gnu-keyring.gpg 351*9880d681SAndroid Build Coastguard Worker % signature_invalid=`gpg --verify --no-default-keyring --keyring ./gnu-keyring.gpg gcc-4.8.2.tar.bz2.sig` 352*9880d681SAndroid Build Coastguard Worker % if [ $signature_invalid ]; then echo "Invalid signature" ; exit 1 ; fi 353*9880d681SAndroid Build Coastguard Worker % tar -xvjf gcc-4.8.2.tar.bz2 354*9880d681SAndroid Build Coastguard Worker % cd gcc-4.8.2 355*9880d681SAndroid Build Coastguard Worker % ./contrib/download_prerequisites 356*9880d681SAndroid Build Coastguard Worker % cd .. 357*9880d681SAndroid Build Coastguard Worker % mkdir gcc-4.8.2-build 358*9880d681SAndroid Build Coastguard Worker % cd gcc-4.8.2-build 359*9880d681SAndroid Build Coastguard Worker % $PWD/../gcc-4.8.2/configure --prefix=$HOME/toolchains --enable-languages=c,c++ 360*9880d681SAndroid Build Coastguard Worker % make -j$(nproc) 361*9880d681SAndroid Build Coastguard Worker % make install 362*9880d681SAndroid Build Coastguard Worker 363*9880d681SAndroid Build Coastguard WorkerFor more details, check out the excellent `GCC wiki entry`_, where I got most 364*9880d681SAndroid Build Coastguard Workerof this information from. 365*9880d681SAndroid Build Coastguard Worker 366*9880d681SAndroid Build Coastguard Worker.. _GCC wiki entry: 367*9880d681SAndroid Build Coastguard Worker http://gcc.gnu.org/wiki/InstallingGCC 368*9880d681SAndroid Build Coastguard Worker 369*9880d681SAndroid Build Coastguard WorkerOnce you have a GCC toolchain, configure your build of LLVM to use the new 370*9880d681SAndroid Build Coastguard Workertoolchain for your host compiler and C++ standard library. Because the new 371*9880d681SAndroid Build Coastguard Workerversion of libstdc++ is not on the system library search path, you need to pass 372*9880d681SAndroid Build Coastguard Workerextra linker flags so that it can be found at link time (``-L``) and at runtime 373*9880d681SAndroid Build Coastguard Worker(``-rpath``). If you are using CMake, this invocation should produce working 374*9880d681SAndroid Build Coastguard Workerbinaries: 375*9880d681SAndroid Build Coastguard Worker 376*9880d681SAndroid Build Coastguard Worker.. code-block:: console 377*9880d681SAndroid Build Coastguard Worker 378*9880d681SAndroid Build Coastguard Worker % mkdir build 379*9880d681SAndroid Build Coastguard Worker % cd build 380*9880d681SAndroid Build Coastguard Worker % CC=$HOME/toolchains/bin/gcc CXX=$HOME/toolchains/bin/g++ \ 381*9880d681SAndroid Build Coastguard Worker cmake .. -DCMAKE_CXX_LINK_FLAGS="-Wl,-rpath,$HOME/toolchains/lib64 -L$HOME/toolchains/lib64" 382*9880d681SAndroid Build Coastguard Worker 383*9880d681SAndroid Build Coastguard WorkerIf you fail to set rpath, most LLVM binaries will fail on startup with a message 384*9880d681SAndroid Build Coastguard Workerfrom the loader similar to ``libstdc++.so.6: version `GLIBCXX_3.4.20' not 385*9880d681SAndroid Build Coastguard Workerfound``. This means you need to tweak the -rpath linker flag. 386*9880d681SAndroid Build Coastguard Worker 387*9880d681SAndroid Build Coastguard WorkerWhen you build Clang, you will need to give *it* access to modern C++11 388*9880d681SAndroid Build Coastguard Workerstandard library in order to use it as your new host in part of a bootstrap. 389*9880d681SAndroid Build Coastguard WorkerThere are two easy ways to do this, either build (and install) libc++ along 390*9880d681SAndroid Build Coastguard Workerwith Clang and then use it with the ``-stdlib=libc++`` compile and link flag, 391*9880d681SAndroid Build Coastguard Workeror install Clang into the same prefix (``$HOME/toolchains`` above) as GCC. 392*9880d681SAndroid Build Coastguard WorkerClang will look within its own prefix for libstdc++ and use it if found. You 393*9880d681SAndroid Build Coastguard Workercan also add an explicit prefix for Clang to look in for a GCC toolchain with 394*9880d681SAndroid Build Coastguard Workerthe ``--gcc-toolchain=/opt/my/gcc/prefix`` flag, passing it to both compile and 395*9880d681SAndroid Build Coastguard Workerlink commands when using your just-built-Clang to bootstrap. 396*9880d681SAndroid Build Coastguard Worker 397*9880d681SAndroid Build Coastguard Worker.. _Getting Started with LLVM: 398*9880d681SAndroid Build Coastguard Worker 399*9880d681SAndroid Build Coastguard WorkerGetting Started with LLVM 400*9880d681SAndroid Build Coastguard Worker========================= 401*9880d681SAndroid Build Coastguard Worker 402*9880d681SAndroid Build Coastguard WorkerThe remainder of this guide is meant to get you up and running with LLVM and to 403*9880d681SAndroid Build Coastguard Workergive you some basic information about the LLVM environment. 404*9880d681SAndroid Build Coastguard Worker 405*9880d681SAndroid Build Coastguard WorkerThe later sections of this guide describe the `general layout`_ of the LLVM 406*9880d681SAndroid Build Coastguard Workersource tree, a `simple example`_ using the LLVM tool chain, and `links`_ to find 407*9880d681SAndroid Build Coastguard Workermore information about LLVM or to get help via e-mail. 408*9880d681SAndroid Build Coastguard Worker 409*9880d681SAndroid Build Coastguard WorkerTerminology and Notation 410*9880d681SAndroid Build Coastguard Worker------------------------ 411*9880d681SAndroid Build Coastguard Worker 412*9880d681SAndroid Build Coastguard WorkerThroughout this manual, the following names are used to denote paths specific to 413*9880d681SAndroid Build Coastguard Workerthe local system and working environment. *These are not environment variables 414*9880d681SAndroid Build Coastguard Workeryou need to set but just strings used in the rest of this document below*. In 415*9880d681SAndroid Build Coastguard Workerany of the examples below, simply replace each of these names with the 416*9880d681SAndroid Build Coastguard Workerappropriate pathname on your local system. All these paths are absolute: 417*9880d681SAndroid Build Coastguard Worker 418*9880d681SAndroid Build Coastguard Worker``SRC_ROOT`` 419*9880d681SAndroid Build Coastguard Worker 420*9880d681SAndroid Build Coastguard Worker This is the top level directory of the LLVM source tree. 421*9880d681SAndroid Build Coastguard Worker 422*9880d681SAndroid Build Coastguard Worker``OBJ_ROOT`` 423*9880d681SAndroid Build Coastguard Worker 424*9880d681SAndroid Build Coastguard Worker This is the top level directory of the LLVM object tree (i.e. the tree where 425*9880d681SAndroid Build Coastguard Worker object files and compiled programs will be placed. It can be the same as 426*9880d681SAndroid Build Coastguard Worker SRC_ROOT). 427*9880d681SAndroid Build Coastguard Worker 428*9880d681SAndroid Build Coastguard WorkerUnpacking the LLVM Archives 429*9880d681SAndroid Build Coastguard Worker--------------------------- 430*9880d681SAndroid Build Coastguard Worker 431*9880d681SAndroid Build Coastguard WorkerIf you have the LLVM distribution, you will need to unpack it before you can 432*9880d681SAndroid Build Coastguard Workerbegin to compile it. LLVM is distributed as a set of two files: the LLVM suite 433*9880d681SAndroid Build Coastguard Workerand the LLVM GCC front end compiled for your platform. There is an additional 434*9880d681SAndroid Build Coastguard Workertest suite that is optional. Each file is a TAR archive that is compressed with 435*9880d681SAndroid Build Coastguard Workerthe gzip program. 436*9880d681SAndroid Build Coastguard Worker 437*9880d681SAndroid Build Coastguard WorkerThe files are as follows, with *x.y* marking the version number: 438*9880d681SAndroid Build Coastguard Worker 439*9880d681SAndroid Build Coastguard Worker``llvm-x.y.tar.gz`` 440*9880d681SAndroid Build Coastguard Worker 441*9880d681SAndroid Build Coastguard Worker Source release for the LLVM libraries and tools. 442*9880d681SAndroid Build Coastguard Worker 443*9880d681SAndroid Build Coastguard Worker``llvm-test-x.y.tar.gz`` 444*9880d681SAndroid Build Coastguard Worker 445*9880d681SAndroid Build Coastguard Worker Source release for the LLVM test-suite. 446*9880d681SAndroid Build Coastguard Worker 447*9880d681SAndroid Build Coastguard Worker.. _checkout: 448*9880d681SAndroid Build Coastguard Worker 449*9880d681SAndroid Build Coastguard WorkerCheckout LLVM from Subversion 450*9880d681SAndroid Build Coastguard Worker----------------------------- 451*9880d681SAndroid Build Coastguard Worker 452*9880d681SAndroid Build Coastguard WorkerIf you have access to our Subversion repository, you can get a fresh copy of the 453*9880d681SAndroid Build Coastguard Workerentire source code. All you need to do is check it out from Subversion as 454*9880d681SAndroid Build Coastguard Workerfollows: 455*9880d681SAndroid Build Coastguard Worker 456*9880d681SAndroid Build Coastguard Worker* ``cd where-you-want-llvm-to-live`` 457*9880d681SAndroid Build Coastguard Worker* Read-Only: ``svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm`` 458*9880d681SAndroid Build Coastguard Worker* Read-Write: ``svn co https://[email protected]/svn/llvm-project/llvm/trunk llvm`` 459*9880d681SAndroid Build Coastguard Worker 460*9880d681SAndroid Build Coastguard WorkerThis will create an '``llvm``' directory in the current directory and fully 461*9880d681SAndroid Build Coastguard Workerpopulate it with the LLVM source code, Makefiles, test directories, and local 462*9880d681SAndroid Build Coastguard Workercopies of documentation files. 463*9880d681SAndroid Build Coastguard Worker 464*9880d681SAndroid Build Coastguard WorkerIf you want to get a specific release (as opposed to the most recent revision), 465*9880d681SAndroid Build Coastguard Workeryou can checkout it from the '``tags``' directory (instead of '``trunk``'). The 466*9880d681SAndroid Build Coastguard Workerfollowing releases are located in the following subdirectories of the '``tags``' 467*9880d681SAndroid Build Coastguard Workerdirectory: 468*9880d681SAndroid Build Coastguard Worker 469*9880d681SAndroid Build Coastguard Worker* Release 3.4: **RELEASE_34/final** 470*9880d681SAndroid Build Coastguard Worker* Release 3.3: **RELEASE_33/final** 471*9880d681SAndroid Build Coastguard Worker* Release 3.2: **RELEASE_32/final** 472*9880d681SAndroid Build Coastguard Worker* Release 3.1: **RELEASE_31/final** 473*9880d681SAndroid Build Coastguard Worker* Release 3.0: **RELEASE_30/final** 474*9880d681SAndroid Build Coastguard Worker* Release 2.9: **RELEASE_29/final** 475*9880d681SAndroid Build Coastguard Worker* Release 2.8: **RELEASE_28** 476*9880d681SAndroid Build Coastguard Worker* Release 2.7: **RELEASE_27** 477*9880d681SAndroid Build Coastguard Worker* Release 2.6: **RELEASE_26** 478*9880d681SAndroid Build Coastguard Worker* Release 2.5: **RELEASE_25** 479*9880d681SAndroid Build Coastguard Worker* Release 2.4: **RELEASE_24** 480*9880d681SAndroid Build Coastguard Worker* Release 2.3: **RELEASE_23** 481*9880d681SAndroid Build Coastguard Worker* Release 2.2: **RELEASE_22** 482*9880d681SAndroid Build Coastguard Worker* Release 2.1: **RELEASE_21** 483*9880d681SAndroid Build Coastguard Worker* Release 2.0: **RELEASE_20** 484*9880d681SAndroid Build Coastguard Worker* Release 1.9: **RELEASE_19** 485*9880d681SAndroid Build Coastguard Worker* Release 1.8: **RELEASE_18** 486*9880d681SAndroid Build Coastguard Worker* Release 1.7: **RELEASE_17** 487*9880d681SAndroid Build Coastguard Worker* Release 1.6: **RELEASE_16** 488*9880d681SAndroid Build Coastguard Worker* Release 1.5: **RELEASE_15** 489*9880d681SAndroid Build Coastguard Worker* Release 1.4: **RELEASE_14** 490*9880d681SAndroid Build Coastguard Worker* Release 1.3: **RELEASE_13** 491*9880d681SAndroid Build Coastguard Worker* Release 1.2: **RELEASE_12** 492*9880d681SAndroid Build Coastguard Worker* Release 1.1: **RELEASE_11** 493*9880d681SAndroid Build Coastguard Worker* Release 1.0: **RELEASE_1** 494*9880d681SAndroid Build Coastguard Worker 495*9880d681SAndroid Build Coastguard WorkerIf you would like to get the LLVM test suite (a separate package as of 1.4), you 496*9880d681SAndroid Build Coastguard Workerget it from the Subversion repository: 497*9880d681SAndroid Build Coastguard Worker 498*9880d681SAndroid Build Coastguard Worker.. code-block:: console 499*9880d681SAndroid Build Coastguard Worker 500*9880d681SAndroid Build Coastguard Worker % cd llvm/projects 501*9880d681SAndroid Build Coastguard Worker % svn co http://llvm.org/svn/llvm-project/test-suite/trunk test-suite 502*9880d681SAndroid Build Coastguard Worker 503*9880d681SAndroid Build Coastguard WorkerBy placing it in the ``llvm/projects``, it will be automatically configured by 504*9880d681SAndroid Build Coastguard Workerthe LLVM cmake configuration. 505*9880d681SAndroid Build Coastguard Worker 506*9880d681SAndroid Build Coastguard WorkerGit Mirror 507*9880d681SAndroid Build Coastguard Worker---------- 508*9880d681SAndroid Build Coastguard Worker 509*9880d681SAndroid Build Coastguard WorkerGit mirrors are available for a number of LLVM subprojects. These mirrors sync 510*9880d681SAndroid Build Coastguard Workerautomatically with each Subversion commit and contain all necessary git-svn 511*9880d681SAndroid Build Coastguard Workermarks (so, you can recreate git-svn metadata locally). Note that right now 512*9880d681SAndroid Build Coastguard Workermirrors reflect only ``trunk`` for each project. You can do the read-only Git 513*9880d681SAndroid Build Coastguard Workerclone of LLVM via: 514*9880d681SAndroid Build Coastguard Worker 515*9880d681SAndroid Build Coastguard Worker.. code-block:: console 516*9880d681SAndroid Build Coastguard Worker 517*9880d681SAndroid Build Coastguard Worker % git clone http://llvm.org/git/llvm.git 518*9880d681SAndroid Build Coastguard Worker 519*9880d681SAndroid Build Coastguard WorkerIf you want to check out clang too, run: 520*9880d681SAndroid Build Coastguard Worker 521*9880d681SAndroid Build Coastguard Worker.. code-block:: console 522*9880d681SAndroid Build Coastguard Worker 523*9880d681SAndroid Build Coastguard Worker % cd llvm/tools 524*9880d681SAndroid Build Coastguard Worker % git clone http://llvm.org/git/clang.git 525*9880d681SAndroid Build Coastguard Worker 526*9880d681SAndroid Build Coastguard WorkerIf you want to check out compiler-rt (required to build the sanitizers), run: 527*9880d681SAndroid Build Coastguard Worker 528*9880d681SAndroid Build Coastguard Worker.. code-block:: console 529*9880d681SAndroid Build Coastguard Worker 530*9880d681SAndroid Build Coastguard Worker % cd llvm/projects 531*9880d681SAndroid Build Coastguard Worker % git clone http://llvm.org/git/compiler-rt.git 532*9880d681SAndroid Build Coastguard Worker 533*9880d681SAndroid Build Coastguard WorkerIf you want to check out libomp (required for OpenMP support), run: 534*9880d681SAndroid Build Coastguard Worker 535*9880d681SAndroid Build Coastguard Worker.. code-block:: console 536*9880d681SAndroid Build Coastguard Worker 537*9880d681SAndroid Build Coastguard Worker % cd llvm/projects 538*9880d681SAndroid Build Coastguard Worker % git clone http://llvm.org/git/openmp.git 539*9880d681SAndroid Build Coastguard Worker 540*9880d681SAndroid Build Coastguard WorkerIf you want to check out libcxx and libcxxabi (optional), run: 541*9880d681SAndroid Build Coastguard Worker 542*9880d681SAndroid Build Coastguard Worker.. code-block:: console 543*9880d681SAndroid Build Coastguard Worker 544*9880d681SAndroid Build Coastguard Worker % cd llvm/projects 545*9880d681SAndroid Build Coastguard Worker % git clone http://llvm.org/git/libcxx.git 546*9880d681SAndroid Build Coastguard Worker % git clone http://llvm.org/git/libcxxabi.git 547*9880d681SAndroid Build Coastguard Worker 548*9880d681SAndroid Build Coastguard WorkerIf you want to check out the Test Suite Source Code (optional), run: 549*9880d681SAndroid Build Coastguard Worker 550*9880d681SAndroid Build Coastguard Worker.. code-block:: console 551*9880d681SAndroid Build Coastguard Worker 552*9880d681SAndroid Build Coastguard Worker % cd llvm/projects 553*9880d681SAndroid Build Coastguard Worker % git clone http://llvm.org/git/test-suite.git 554*9880d681SAndroid Build Coastguard Worker 555*9880d681SAndroid Build Coastguard WorkerSince the upstream repository is in Subversion, you should use ``git 556*9880d681SAndroid Build Coastguard Workerpull --rebase`` instead of ``git pull`` to avoid generating a non-linear history 557*9880d681SAndroid Build Coastguard Workerin your clone. To configure ``git pull`` to pass ``--rebase`` by default on the 558*9880d681SAndroid Build Coastguard Workermaster branch, run the following command: 559*9880d681SAndroid Build Coastguard Worker 560*9880d681SAndroid Build Coastguard Worker.. code-block:: console 561*9880d681SAndroid Build Coastguard Worker 562*9880d681SAndroid Build Coastguard Worker % git config branch.master.rebase true 563*9880d681SAndroid Build Coastguard Worker 564*9880d681SAndroid Build Coastguard WorkerSending patches with Git 565*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^ 566*9880d681SAndroid Build Coastguard Worker 567*9880d681SAndroid Build Coastguard WorkerPlease read `Developer Policy <DeveloperPolicy.html#one-off-patches>`_, too. 568*9880d681SAndroid Build Coastguard Worker 569*9880d681SAndroid Build Coastguard WorkerAssume ``master`` points the upstream and ``mybranch`` points your working 570*9880d681SAndroid Build Coastguard Workerbranch, and ``mybranch`` is rebased onto ``master``. At first you may check 571*9880d681SAndroid Build Coastguard Workersanity of whitespaces: 572*9880d681SAndroid Build Coastguard Worker 573*9880d681SAndroid Build Coastguard Worker.. code-block:: console 574*9880d681SAndroid Build Coastguard Worker 575*9880d681SAndroid Build Coastguard Worker % git diff --check master..mybranch 576*9880d681SAndroid Build Coastguard Worker 577*9880d681SAndroid Build Coastguard WorkerThe easiest way to generate a patch is as below: 578*9880d681SAndroid Build Coastguard Worker 579*9880d681SAndroid Build Coastguard Worker.. code-block:: console 580*9880d681SAndroid Build Coastguard Worker 581*9880d681SAndroid Build Coastguard Worker % git diff master..mybranch > /path/to/mybranch.diff 582*9880d681SAndroid Build Coastguard Worker 583*9880d681SAndroid Build Coastguard WorkerIt is a little different from svn-generated diff. git-diff-generated diff has 584*9880d681SAndroid Build Coastguard Workerprefixes like ``a/`` and ``b/``. Don't worry, most developers might know it 585*9880d681SAndroid Build Coastguard Workercould be accepted with ``patch -p1 -N``. 586*9880d681SAndroid Build Coastguard Worker 587*9880d681SAndroid Build Coastguard WorkerBut you may generate patchset with git-format-patch. It generates by-each-commit 588*9880d681SAndroid Build Coastguard Workerpatchset. To generate patch files to attach to your article: 589*9880d681SAndroid Build Coastguard Worker 590*9880d681SAndroid Build Coastguard Worker.. code-block:: console 591*9880d681SAndroid Build Coastguard Worker 592*9880d681SAndroid Build Coastguard Worker % git format-patch --no-attach master..mybranch -o /path/to/your/patchset 593*9880d681SAndroid Build Coastguard Worker 594*9880d681SAndroid Build Coastguard WorkerIf you would like to send patches directly, you may use git-send-email or 595*9880d681SAndroid Build Coastguard Workergit-imap-send. Here is an example to generate the patchset in Gmail's [Drafts]. 596*9880d681SAndroid Build Coastguard Worker 597*9880d681SAndroid Build Coastguard Worker.. code-block:: console 598*9880d681SAndroid Build Coastguard Worker 599*9880d681SAndroid Build Coastguard Worker % git format-patch --attach master..mybranch --stdout | git imap-send 600*9880d681SAndroid Build Coastguard Worker 601*9880d681SAndroid Build Coastguard WorkerThen, your .git/config should have [imap] sections. 602*9880d681SAndroid Build Coastguard Worker 603*9880d681SAndroid Build Coastguard Worker.. code-block:: ini 604*9880d681SAndroid Build Coastguard Worker 605*9880d681SAndroid Build Coastguard Worker [imap] 606*9880d681SAndroid Build Coastguard Worker host = imaps://imap.gmail.com 607*9880d681SAndroid Build Coastguard Worker user = [email protected] 608*9880d681SAndroid Build Coastguard Worker pass = himitsu! 609*9880d681SAndroid Build Coastguard Worker port = 993 610*9880d681SAndroid Build Coastguard Worker sslverify = false 611*9880d681SAndroid Build Coastguard Worker ; in English 612*9880d681SAndroid Build Coastguard Worker folder = "[Gmail]/Drafts" 613*9880d681SAndroid Build Coastguard Worker ; example for Japanese, "Modified UTF-7" encoded. 614*9880d681SAndroid Build Coastguard Worker folder = "[Gmail]/&Tgtm+DBN-" 615*9880d681SAndroid Build Coastguard Worker ; example for Traditional Chinese 616*9880d681SAndroid Build Coastguard Worker folder = "[Gmail]/&g0l6Pw-" 617*9880d681SAndroid Build Coastguard Worker 618*9880d681SAndroid Build Coastguard Worker.. _developers-work-with-git-svn: 619*9880d681SAndroid Build Coastguard Worker 620*9880d681SAndroid Build Coastguard WorkerFor developers to work with git-svn 621*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 622*9880d681SAndroid Build Coastguard Worker 623*9880d681SAndroid Build Coastguard WorkerTo set up clone from which you can submit code using ``git-svn``, run: 624*9880d681SAndroid Build Coastguard Worker 625*9880d681SAndroid Build Coastguard Worker.. code-block:: console 626*9880d681SAndroid Build Coastguard Worker 627*9880d681SAndroid Build Coastguard Worker % git clone http://llvm.org/git/llvm.git 628*9880d681SAndroid Build Coastguard Worker % cd llvm 629*9880d681SAndroid Build Coastguard Worker % git svn init https://llvm.org/svn/llvm-project/llvm/trunk --username=<username> 630*9880d681SAndroid Build Coastguard Worker % git config svn-remote.svn.fetch :refs/remotes/origin/master 631*9880d681SAndroid Build Coastguard Worker % git svn rebase -l # -l avoids fetching ahead of the git mirror. 632*9880d681SAndroid Build Coastguard Worker 633*9880d681SAndroid Build Coastguard Worker # If you have clang too: 634*9880d681SAndroid Build Coastguard Worker % cd tools 635*9880d681SAndroid Build Coastguard Worker % git clone http://llvm.org/git/clang.git 636*9880d681SAndroid Build Coastguard Worker % cd clang 637*9880d681SAndroid Build Coastguard Worker % git svn init https://llvm.org/svn/llvm-project/cfe/trunk --username=<username> 638*9880d681SAndroid Build Coastguard Worker % git config svn-remote.svn.fetch :refs/remotes/origin/master 639*9880d681SAndroid Build Coastguard Worker % git svn rebase -l 640*9880d681SAndroid Build Coastguard Worker 641*9880d681SAndroid Build Coastguard WorkerLikewise for compiler-rt, libomp and test-suite. 642*9880d681SAndroid Build Coastguard Worker 643*9880d681SAndroid Build Coastguard WorkerTo update this clone without generating git-svn tags that conflict with the 644*9880d681SAndroid Build Coastguard Workerupstream Git repo, run: 645*9880d681SAndroid Build Coastguard Worker 646*9880d681SAndroid Build Coastguard Worker.. code-block:: console 647*9880d681SAndroid Build Coastguard Worker 648*9880d681SAndroid Build Coastguard Worker % git fetch && (cd tools/clang && git fetch) # Get matching revisions of both trees. 649*9880d681SAndroid Build Coastguard Worker % git checkout master 650*9880d681SAndroid Build Coastguard Worker % git svn rebase -l 651*9880d681SAndroid Build Coastguard Worker % (cd tools/clang && 652*9880d681SAndroid Build Coastguard Worker git checkout master && 653*9880d681SAndroid Build Coastguard Worker git svn rebase -l) 654*9880d681SAndroid Build Coastguard Worker 655*9880d681SAndroid Build Coastguard WorkerLikewise for compiler-rt, libomp and test-suite. 656*9880d681SAndroid Build Coastguard Worker 657*9880d681SAndroid Build Coastguard WorkerThis leaves your working directories on their master branches, so you'll need to 658*9880d681SAndroid Build Coastguard Worker``checkout`` each working branch individually and ``rebase`` it on top of its 659*9880d681SAndroid Build Coastguard Workerparent branch. 660*9880d681SAndroid Build Coastguard Worker 661*9880d681SAndroid Build Coastguard WorkerFor those who wish to be able to update an llvm repo/revert patches easily using 662*9880d681SAndroid Build Coastguard Workergit-svn, please look in the directory for the scripts ``git-svnup`` and 663*9880d681SAndroid Build Coastguard Worker``git-svnrevert``. 664*9880d681SAndroid Build Coastguard Worker 665*9880d681SAndroid Build Coastguard WorkerTo perform the aforementioned update steps go into your source directory and 666*9880d681SAndroid Build Coastguard Workerjust type ``git-svnup`` or ``git svnup`` and everything will just work. 667*9880d681SAndroid Build Coastguard Worker 668*9880d681SAndroid Build Coastguard WorkerIf one wishes to revert a commit with git-svn, but do not want the git hash to 669*9880d681SAndroid Build Coastguard Workerescape into the commit message, one can use the script ``git-svnrevert`` or 670*9880d681SAndroid Build Coastguard Worker``git svnrevert`` which will take in the git hash for the commit you want to 671*9880d681SAndroid Build Coastguard Workerrevert, look up the appropriate svn revision, and output a message where all 672*9880d681SAndroid Build Coastguard Workerreferences to the git hash have been replaced with the svn revision. 673*9880d681SAndroid Build Coastguard Worker 674*9880d681SAndroid Build Coastguard WorkerTo commit back changes via git-svn, use ``git svn dcommit``: 675*9880d681SAndroid Build Coastguard Worker 676*9880d681SAndroid Build Coastguard Worker.. code-block:: console 677*9880d681SAndroid Build Coastguard Worker 678*9880d681SAndroid Build Coastguard Worker % git svn dcommit 679*9880d681SAndroid Build Coastguard Worker 680*9880d681SAndroid Build Coastguard WorkerNote that git-svn will create one SVN commit for each Git commit you have pending, 681*9880d681SAndroid Build Coastguard Workerso squash and edit each commit before executing ``dcommit`` to make sure they all 682*9880d681SAndroid Build Coastguard Workerconform to the coding standards and the developers' policy. 683*9880d681SAndroid Build Coastguard Worker 684*9880d681SAndroid Build Coastguard WorkerOn success, ``dcommit`` will rebase against the HEAD of SVN, so to avoid conflict, 685*9880d681SAndroid Build Coastguard Workerplease make sure your current branch is up-to-date (via fetch/rebase) before 686*9880d681SAndroid Build Coastguard Workerproceeding. 687*9880d681SAndroid Build Coastguard Worker 688*9880d681SAndroid Build Coastguard WorkerThe git-svn metadata can get out of sync after you mess around with branches and 689*9880d681SAndroid Build Coastguard Worker``dcommit``. When that happens, ``git svn dcommit`` stops working, complaining 690*9880d681SAndroid Build Coastguard Workerabout files with uncommitted changes. The fix is to rebuild the metadata: 691*9880d681SAndroid Build Coastguard Worker 692*9880d681SAndroid Build Coastguard Worker.. code-block:: console 693*9880d681SAndroid Build Coastguard Worker 694*9880d681SAndroid Build Coastguard Worker % rm -rf .git/svn 695*9880d681SAndroid Build Coastguard Worker % git svn rebase -l 696*9880d681SAndroid Build Coastguard Worker 697*9880d681SAndroid Build Coastguard WorkerPlease, refer to the Git-SVN manual (``man git-svn``) for more information. 698*9880d681SAndroid Build Coastguard Worker 699*9880d681SAndroid Build Coastguard WorkerLocal LLVM Configuration 700*9880d681SAndroid Build Coastguard Worker------------------------ 701*9880d681SAndroid Build Coastguard Worker 702*9880d681SAndroid Build Coastguard WorkerOnce checked out from the Subversion repository, the LLVM suite source code must 703*9880d681SAndroid Build Coastguard Workerbe configured before being built. This process uses CMake. 704*9880d681SAndroid Build Coastguard WorkerUnlinke the normal ``configure`` script, CMake 705*9880d681SAndroid Build Coastguard Workergenerates the build files in whatever format you request as well as various 706*9880d681SAndroid Build Coastguard Worker``*.inc`` files, and ``llvm/include/Config/config.h``. 707*9880d681SAndroid Build Coastguard Worker 708*9880d681SAndroid Build Coastguard WorkerVariables are passed to ``cmake`` on the command line using the format 709*9880d681SAndroid Build Coastguard Worker``-D<variable name>=<value>``. The following variables are some common options 710*9880d681SAndroid Build Coastguard Workerused by people developing LLVM. 711*9880d681SAndroid Build Coastguard Worker 712*9880d681SAndroid Build Coastguard Worker+-------------------------+----------------------------------------------------+ 713*9880d681SAndroid Build Coastguard Worker| Variable | Purpose | 714*9880d681SAndroid Build Coastguard Worker+=========================+====================================================+ 715*9880d681SAndroid Build Coastguard Worker| CMAKE_C_COMPILER | Tells ``cmake`` which C compiler to use. By | 716*9880d681SAndroid Build Coastguard Worker| | default, this will be /usr/bin/cc. | 717*9880d681SAndroid Build Coastguard Worker+-------------------------+----------------------------------------------------+ 718*9880d681SAndroid Build Coastguard Worker| CMAKE_CXX_COMPILER | Tells ``cmake`` which C++ compiler to use. By | 719*9880d681SAndroid Build Coastguard Worker| | default, this will be /usr/bin/c++. | 720*9880d681SAndroid Build Coastguard Worker+-------------------------+----------------------------------------------------+ 721*9880d681SAndroid Build Coastguard Worker| CMAKE_BUILD_TYPE | Tells ``cmake`` what type of build you are trying | 722*9880d681SAndroid Build Coastguard Worker| | to generate files for. Valid options are Debug, | 723*9880d681SAndroid Build Coastguard Worker| | Release, RelWithDebInfo, and MinSizeRel. Default | 724*9880d681SAndroid Build Coastguard Worker| | is Debug. | 725*9880d681SAndroid Build Coastguard Worker+-------------------------+----------------------------------------------------+ 726*9880d681SAndroid Build Coastguard Worker| CMAKE_INSTALL_PREFIX | Specifies the install directory to target when | 727*9880d681SAndroid Build Coastguard Worker| | running the install action of the build files. | 728*9880d681SAndroid Build Coastguard Worker+-------------------------+----------------------------------------------------+ 729*9880d681SAndroid Build Coastguard Worker| LLVM_TARGETS_TO_BUILD | A semicolon delimited list controlling which | 730*9880d681SAndroid Build Coastguard Worker| | targets will be built and linked into llc. This is | 731*9880d681SAndroid Build Coastguard Worker| | equivalent to the ``--enable-targets`` option in | 732*9880d681SAndroid Build Coastguard Worker| | the configure script. The default list is defined | 733*9880d681SAndroid Build Coastguard Worker| | as ``LLVM_ALL_TARGETS``, and can be set to include | 734*9880d681SAndroid Build Coastguard Worker| | out-of-tree targets. The default value includes: | 735*9880d681SAndroid Build Coastguard Worker| | ``AArch64, AMDGPU, ARM, BPF, Hexagon, Mips, | 736*9880d681SAndroid Build Coastguard Worker| | MSP430, NVPTX, PowerPC, Sparc, SystemZ, X86, | 737*9880d681SAndroid Build Coastguard Worker| | XCore``. | 738*9880d681SAndroid Build Coastguard Worker+-------------------------+----------------------------------------------------+ 739*9880d681SAndroid Build Coastguard Worker| LLVM_ENABLE_DOXYGEN | Build doxygen-based documentation from the source | 740*9880d681SAndroid Build Coastguard Worker| | code This is disabled by default because it is | 741*9880d681SAndroid Build Coastguard Worker| | slow and generates a lot of output. | 742*9880d681SAndroid Build Coastguard Worker+-------------------------+----------------------------------------------------+ 743*9880d681SAndroid Build Coastguard Worker| LLVM_ENABLE_SPHINX | Build sphinx-based documentation from the source | 744*9880d681SAndroid Build Coastguard Worker| | code. This is disabled by default because it is | 745*9880d681SAndroid Build Coastguard Worker| | slow and generates a lot of output. | 746*9880d681SAndroid Build Coastguard Worker+-------------------------+----------------------------------------------------+ 747*9880d681SAndroid Build Coastguard Worker| LLVM_BUILD_LLVM_DYLIB | Generate libLLVM.so. This library contains a | 748*9880d681SAndroid Build Coastguard Worker| | default set of LLVM components that can be | 749*9880d681SAndroid Build Coastguard Worker| | overridden with ``LLVM_DYLIB_COMPONENTS``. The | 750*9880d681SAndroid Build Coastguard Worker| | default contains most of LLVM and is defined in | 751*9880d681SAndroid Build Coastguard Worker| | ``tools/llvm-shlib/CMakelists.txt``. | 752*9880d681SAndroid Build Coastguard Worker+-------------------------+----------------------------------------------------+ 753*9880d681SAndroid Build Coastguard Worker| LLVM_OPTIMIZED_TABLEGEN | Builds a release tablegen that gets used during | 754*9880d681SAndroid Build Coastguard Worker| | the LLVM build. This can dramatically speed up | 755*9880d681SAndroid Build Coastguard Worker| | debug builds. | 756*9880d681SAndroid Build Coastguard Worker+-------------------------+----------------------------------------------------+ 757*9880d681SAndroid Build Coastguard Worker 758*9880d681SAndroid Build Coastguard WorkerTo configure LLVM, follow these steps: 759*9880d681SAndroid Build Coastguard Worker 760*9880d681SAndroid Build Coastguard Worker#. Change directory into the object root directory: 761*9880d681SAndroid Build Coastguard Worker 762*9880d681SAndroid Build Coastguard Worker .. code-block:: console 763*9880d681SAndroid Build Coastguard Worker 764*9880d681SAndroid Build Coastguard Worker % cd OBJ_ROOT 765*9880d681SAndroid Build Coastguard Worker 766*9880d681SAndroid Build Coastguard Worker#. Run the ``cmake``: 767*9880d681SAndroid Build Coastguard Worker 768*9880d681SAndroid Build Coastguard Worker .. code-block:: console 769*9880d681SAndroid Build Coastguard Worker 770*9880d681SAndroid Build Coastguard Worker % cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=prefix=/install/path 771*9880d681SAndroid Build Coastguard Worker [other options] SRC_ROOT 772*9880d681SAndroid Build Coastguard Worker 773*9880d681SAndroid Build Coastguard WorkerCompiling the LLVM Suite Source Code 774*9880d681SAndroid Build Coastguard Worker------------------------------------ 775*9880d681SAndroid Build Coastguard Worker 776*9880d681SAndroid Build Coastguard WorkerUnlike with autotools, with CMake your build type is defined at configuration. 777*9880d681SAndroid Build Coastguard WorkerIf you want to change your build type, you can re-run cmake with the following 778*9880d681SAndroid Build Coastguard Workerinvocation: 779*9880d681SAndroid Build Coastguard Worker 780*9880d681SAndroid Build Coastguard Worker .. code-block:: console 781*9880d681SAndroid Build Coastguard Worker 782*9880d681SAndroid Build Coastguard Worker % cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=type SRC_ROOT 783*9880d681SAndroid Build Coastguard Worker 784*9880d681SAndroid Build Coastguard WorkerBetween runs, CMake preserves the values set for all options. CMake has the 785*9880d681SAndroid Build Coastguard Workerfollowing build types defined: 786*9880d681SAndroid Build Coastguard Worker 787*9880d681SAndroid Build Coastguard WorkerDebug 788*9880d681SAndroid Build Coastguard Worker 789*9880d681SAndroid Build Coastguard Worker These builds are the default. The build system will compile the tools and 790*9880d681SAndroid Build Coastguard Worker libraries unoptimized, with debugging information, and asserts enabled. 791*9880d681SAndroid Build Coastguard Worker 792*9880d681SAndroid Build Coastguard WorkerRelease 793*9880d681SAndroid Build Coastguard Worker 794*9880d681SAndroid Build Coastguard Worker For these builds, the build system will compile the tools and libraries 795*9880d681SAndroid Build Coastguard Worker with optimizations enabled and not generate debug info. CMakes default 796*9880d681SAndroid Build Coastguard Worker optimization level is -O3. This can be configured by setting the 797*9880d681SAndroid Build Coastguard Worker ``CMAKE_CXX_FLAGS_RELEASE`` variable on the CMake command line. 798*9880d681SAndroid Build Coastguard Worker 799*9880d681SAndroid Build Coastguard WorkerRelWithDebInfo 800*9880d681SAndroid Build Coastguard Worker 801*9880d681SAndroid Build Coastguard Worker These builds are useful when debugging. They generate optimized binaries with 802*9880d681SAndroid Build Coastguard Worker debug information. CMakes default optimization level is -O2. This can be 803*9880d681SAndroid Build Coastguard Worker configured by setting the ``CMAKE_CXX_FLAGS_RELWITHDEBINFO`` variable on the 804*9880d681SAndroid Build Coastguard Worker CMake command line. 805*9880d681SAndroid Build Coastguard Worker 806*9880d681SAndroid Build Coastguard WorkerOnce you have LLVM configured, you can build it by entering the *OBJ_ROOT* 807*9880d681SAndroid Build Coastguard Workerdirectory and issuing the following command: 808*9880d681SAndroid Build Coastguard Worker 809*9880d681SAndroid Build Coastguard Worker.. code-block:: console 810*9880d681SAndroid Build Coastguard Worker 811*9880d681SAndroid Build Coastguard Worker % make 812*9880d681SAndroid Build Coastguard Worker 813*9880d681SAndroid Build Coastguard WorkerIf the build fails, please `check here`_ to see if you are using a version of 814*9880d681SAndroid Build Coastguard WorkerGCC that is known not to compile LLVM. 815*9880d681SAndroid Build Coastguard Worker 816*9880d681SAndroid Build Coastguard WorkerIf you have multiple processors in your machine, you may wish to use some of the 817*9880d681SAndroid Build Coastguard Workerparallel build options provided by GNU Make. For example, you could use the 818*9880d681SAndroid Build Coastguard Workercommand: 819*9880d681SAndroid Build Coastguard Worker 820*9880d681SAndroid Build Coastguard Worker.. code-block:: console 821*9880d681SAndroid Build Coastguard Worker 822*9880d681SAndroid Build Coastguard Worker % make -j2 823*9880d681SAndroid Build Coastguard Worker 824*9880d681SAndroid Build Coastguard WorkerThere are several special targets which are useful when working with the LLVM 825*9880d681SAndroid Build Coastguard Workersource code: 826*9880d681SAndroid Build Coastguard Worker 827*9880d681SAndroid Build Coastguard Worker``make clean`` 828*9880d681SAndroid Build Coastguard Worker 829*9880d681SAndroid Build Coastguard Worker Removes all files generated by the build. This includes object files, 830*9880d681SAndroid Build Coastguard Worker generated C/C++ files, libraries, and executables. 831*9880d681SAndroid Build Coastguard Worker 832*9880d681SAndroid Build Coastguard Worker``make install`` 833*9880d681SAndroid Build Coastguard Worker 834*9880d681SAndroid Build Coastguard Worker Installs LLVM header files, libraries, tools, and documentation in a hierarchy 835*9880d681SAndroid Build Coastguard Worker under ``$PREFIX``, specified with ``CMAKE_INSTALL_PREFIX``, which 836*9880d681SAndroid Build Coastguard Worker defaults to ``/usr/local``. 837*9880d681SAndroid Build Coastguard Worker 838*9880d681SAndroid Build Coastguard Worker``make docs-llvm-html`` 839*9880d681SAndroid Build Coastguard Worker 840*9880d681SAndroid Build Coastguard Worker If configured with ``-DLLVM_ENABLE_SPHINX=On``, this will generate a directory 841*9880d681SAndroid Build Coastguard Worker at ``OBJ_ROOT/docs/html`` which contains the HTML formatted documentation. 842*9880d681SAndroid Build Coastguard Worker 843*9880d681SAndroid Build Coastguard WorkerCross-Compiling LLVM 844*9880d681SAndroid Build Coastguard Worker-------------------- 845*9880d681SAndroid Build Coastguard Worker 846*9880d681SAndroid Build Coastguard WorkerIt is possible to cross-compile LLVM itself. That is, you can create LLVM 847*9880d681SAndroid Build Coastguard Workerexecutables and libraries to be hosted on a platform different from the platform 848*9880d681SAndroid Build Coastguard Workerwhere they are built (a Canadian Cross build). To generate build files for 849*9880d681SAndroid Build Coastguard Workercross-compiling CMake provides a variable ``CMAKE_TOOLCHAIN_FILE`` which can 850*9880d681SAndroid Build Coastguard Workerdefine compiler flags and variables used during the CMake test operations. 851*9880d681SAndroid Build Coastguard Worker 852*9880d681SAndroid Build Coastguard WorkerThe result of such a build is executables that are not runnable on on the build 853*9880d681SAndroid Build Coastguard Workerhost but can be executed on the target. As an example the following CMake 854*9880d681SAndroid Build Coastguard Workerinvocation can generate build files targeting iOS. This will work on Mac OS X 855*9880d681SAndroid Build Coastguard Workerwith the latest Xcode: 856*9880d681SAndroid Build Coastguard Worker 857*9880d681SAndroid Build Coastguard Worker.. code-block:: console 858*9880d681SAndroid Build Coastguard Worker 859*9880d681SAndroid Build Coastguard Worker % cmake -G "Ninja" -DCMAKE_OSX_ARCHITECTURES="armv7;armv7s;arm64" 860*9880d681SAndroid Build Coastguard Worker -DCMAKE_TOOLCHAIN_FILE=<PATH_TO_LLVM>/cmake/platforms/iOS.cmake 861*9880d681SAndroid Build Coastguard Worker -DCMAKE_BUILD_TYPE=Release -DLLVM_BUILD_RUNTIME=Off -DLLVM_INCLUDE_TESTS=Off 862*9880d681SAndroid Build Coastguard Worker -DLLVM_INCLUDE_EXAMPLES=Off -DLLVM_ENABLE_BACKTRACES=Off [options] 863*9880d681SAndroid Build Coastguard Worker <PATH_TO_LLVM> 864*9880d681SAndroid Build Coastguard Worker 865*9880d681SAndroid Build Coastguard WorkerNote: There are some additional flags that need to be passed when building for 866*9880d681SAndroid Build Coastguard WorkeriOS due to limitations in the iOS SDK. 867*9880d681SAndroid Build Coastguard Worker 868*9880d681SAndroid Build Coastguard WorkerCheck :doc:`HowToCrossCompileLLVM` and `Clang docs on how to cross-compile in general 869*9880d681SAndroid Build Coastguard Worker<http://clang.llvm.org/docs/CrossCompilation.html>`_ for more information 870*9880d681SAndroid Build Coastguard Workerabout cross-compiling. 871*9880d681SAndroid Build Coastguard Worker 872*9880d681SAndroid Build Coastguard WorkerThe Location of LLVM Object Files 873*9880d681SAndroid Build Coastguard Worker--------------------------------- 874*9880d681SAndroid Build Coastguard Worker 875*9880d681SAndroid Build Coastguard WorkerThe LLVM build system is capable of sharing a single LLVM source tree among 876*9880d681SAndroid Build Coastguard Workerseveral LLVM builds. Hence, it is possible to build LLVM for several different 877*9880d681SAndroid Build Coastguard Workerplatforms or configurations using the same source tree. 878*9880d681SAndroid Build Coastguard Worker 879*9880d681SAndroid Build Coastguard Worker* Change directory to where the LLVM object files should live: 880*9880d681SAndroid Build Coastguard Worker 881*9880d681SAndroid Build Coastguard Worker .. code-block:: console 882*9880d681SAndroid Build Coastguard Worker 883*9880d681SAndroid Build Coastguard Worker % cd OBJ_ROOT 884*9880d681SAndroid Build Coastguard Worker 885*9880d681SAndroid Build Coastguard Worker* Run ``cmake``: 886*9880d681SAndroid Build Coastguard Worker 887*9880d681SAndroid Build Coastguard Worker .. code-block:: console 888*9880d681SAndroid Build Coastguard Worker 889*9880d681SAndroid Build Coastguard Worker % cmake -G "Unix Makefiles" SRC_ROOT 890*9880d681SAndroid Build Coastguard Worker 891*9880d681SAndroid Build Coastguard WorkerThe LLVM build will create a structure underneath *OBJ_ROOT* that matches the 892*9880d681SAndroid Build Coastguard WorkerLLVM source tree. At each level where source files are present in the source 893*9880d681SAndroid Build Coastguard Workertree there will be a corresponding ``CMakeFiles`` directory in the *OBJ_ROOT*. 894*9880d681SAndroid Build Coastguard WorkerUnderneath that directory there is another directory with a name ending in 895*9880d681SAndroid Build Coastguard Worker``.dir`` under which you'll find object files for each source. 896*9880d681SAndroid Build Coastguard Worker 897*9880d681SAndroid Build Coastguard WorkerFor example: 898*9880d681SAndroid Build Coastguard Worker 899*9880d681SAndroid Build Coastguard Worker .. code-block:: console 900*9880d681SAndroid Build Coastguard Worker 901*9880d681SAndroid Build Coastguard Worker % cd llvm_build_dir 902*9880d681SAndroid Build Coastguard Worker % find lib/Support/ -name APFloat* 903*9880d681SAndroid Build Coastguard Worker lib/Support/CMakeFiles/LLVMSupport.dir/APFloat.cpp.o 904*9880d681SAndroid Build Coastguard Worker 905*9880d681SAndroid Build Coastguard WorkerOptional Configuration Items 906*9880d681SAndroid Build Coastguard Worker---------------------------- 907*9880d681SAndroid Build Coastguard Worker 908*9880d681SAndroid Build Coastguard WorkerIf you're running on a Linux system that supports the `binfmt_misc 909*9880d681SAndroid Build Coastguard Worker<http://en.wikipedia.org/wiki/binfmt_misc>`_ 910*9880d681SAndroid Build Coastguard Workermodule, and you have root access on the system, you can set your system up to 911*9880d681SAndroid Build Coastguard Workerexecute LLVM bitcode files directly. To do this, use commands like this (the 912*9880d681SAndroid Build Coastguard Workerfirst command may not be required if you are already using the module): 913*9880d681SAndroid Build Coastguard Worker 914*9880d681SAndroid Build Coastguard Worker.. code-block:: console 915*9880d681SAndroid Build Coastguard Worker 916*9880d681SAndroid Build Coastguard Worker % mount -t binfmt_misc none /proc/sys/fs/binfmt_misc 917*9880d681SAndroid Build Coastguard Worker % echo ':llvm:M::BC::/path/to/lli:' > /proc/sys/fs/binfmt_misc/register 918*9880d681SAndroid Build Coastguard Worker % chmod u+x hello.bc (if needed) 919*9880d681SAndroid Build Coastguard Worker % ./hello.bc 920*9880d681SAndroid Build Coastguard Worker 921*9880d681SAndroid Build Coastguard WorkerThis allows you to execute LLVM bitcode files directly. On Debian, you can also 922*9880d681SAndroid Build Coastguard Workeruse this command instead of the 'echo' command above: 923*9880d681SAndroid Build Coastguard Worker 924*9880d681SAndroid Build Coastguard Worker.. code-block:: console 925*9880d681SAndroid Build Coastguard Worker 926*9880d681SAndroid Build Coastguard Worker % sudo update-binfmts --install llvm /path/to/lli --magic 'BC' 927*9880d681SAndroid Build Coastguard Worker 928*9880d681SAndroid Build Coastguard Worker.. _Program Layout: 929*9880d681SAndroid Build Coastguard Worker.. _general layout: 930*9880d681SAndroid Build Coastguard Worker 931*9880d681SAndroid Build Coastguard WorkerDirectory Layout 932*9880d681SAndroid Build Coastguard Worker================ 933*9880d681SAndroid Build Coastguard Worker 934*9880d681SAndroid Build Coastguard WorkerOne useful source of information about the LLVM source base is the LLVM `doxygen 935*9880d681SAndroid Build Coastguard Worker<http://www.doxygen.org/>`_ documentation available at 936*9880d681SAndroid Build Coastguard Worker`<http://llvm.org/doxygen/>`_. The following is a brief introduction to code 937*9880d681SAndroid Build Coastguard Workerlayout: 938*9880d681SAndroid Build Coastguard Worker 939*9880d681SAndroid Build Coastguard Worker``llvm/examples`` 940*9880d681SAndroid Build Coastguard Worker----------------- 941*9880d681SAndroid Build Coastguard Worker 942*9880d681SAndroid Build Coastguard WorkerSimple examples using the LLVM IR and JIT. 943*9880d681SAndroid Build Coastguard Worker 944*9880d681SAndroid Build Coastguard Worker``llvm/include`` 945*9880d681SAndroid Build Coastguard Worker---------------- 946*9880d681SAndroid Build Coastguard Worker 947*9880d681SAndroid Build Coastguard WorkerPublic header files exported from the LLVM library. The three main subdirectories: 948*9880d681SAndroid Build Coastguard Worker 949*9880d681SAndroid Build Coastguard Worker``llvm/include/llvm`` 950*9880d681SAndroid Build Coastguard Worker 951*9880d681SAndroid Build Coastguard Worker All LLVM-specific header files, and subdirectories for different portions of 952*9880d681SAndroid Build Coastguard Worker LLVM: ``Analysis``, ``CodeGen``, ``Target``, ``Transforms``, etc... 953*9880d681SAndroid Build Coastguard Worker 954*9880d681SAndroid Build Coastguard Worker``llvm/include/llvm/Support`` 955*9880d681SAndroid Build Coastguard Worker 956*9880d681SAndroid Build Coastguard Worker Generic support libraries provided with LLVM but not necessarily specific to 957*9880d681SAndroid Build Coastguard Worker LLVM. For example, some C++ STL utilities and a Command Line option processing 958*9880d681SAndroid Build Coastguard Worker library store header files here. 959*9880d681SAndroid Build Coastguard Worker 960*9880d681SAndroid Build Coastguard Worker``llvm/include/llvm/Config`` 961*9880d681SAndroid Build Coastguard Worker 962*9880d681SAndroid Build Coastguard Worker Header files configured by the ``configure`` script. 963*9880d681SAndroid Build Coastguard Worker They wrap "standard" UNIX and C header files. Source code can include these 964*9880d681SAndroid Build Coastguard Worker header files which automatically take care of the conditional #includes that 965*9880d681SAndroid Build Coastguard Worker the ``configure`` script generates. 966*9880d681SAndroid Build Coastguard Worker 967*9880d681SAndroid Build Coastguard Worker``llvm/lib`` 968*9880d681SAndroid Build Coastguard Worker------------ 969*9880d681SAndroid Build Coastguard Worker 970*9880d681SAndroid Build Coastguard WorkerMost source files are here. By putting code in libraries, LLVM makes it easy to 971*9880d681SAndroid Build Coastguard Workershare code among the `tools`_. 972*9880d681SAndroid Build Coastguard Worker 973*9880d681SAndroid Build Coastguard Worker``llvm/lib/IR/`` 974*9880d681SAndroid Build Coastguard Worker 975*9880d681SAndroid Build Coastguard Worker Core LLVM source files that implement core classes like Instruction and 976*9880d681SAndroid Build Coastguard Worker BasicBlock. 977*9880d681SAndroid Build Coastguard Worker 978*9880d681SAndroid Build Coastguard Worker``llvm/lib/AsmParser/`` 979*9880d681SAndroid Build Coastguard Worker 980*9880d681SAndroid Build Coastguard Worker Source code for the LLVM assembly language parser library. 981*9880d681SAndroid Build Coastguard Worker 982*9880d681SAndroid Build Coastguard Worker``llvm/lib/Bitcode/`` 983*9880d681SAndroid Build Coastguard Worker 984*9880d681SAndroid Build Coastguard Worker Code for reading and writing bitcode. 985*9880d681SAndroid Build Coastguard Worker 986*9880d681SAndroid Build Coastguard Worker``llvm/lib/Analysis/`` 987*9880d681SAndroid Build Coastguard Worker 988*9880d681SAndroid Build Coastguard Worker A variety of program analyses, such as Call Graphs, Induction Variables, 989*9880d681SAndroid Build Coastguard Worker Natural Loop Identification, etc. 990*9880d681SAndroid Build Coastguard Worker 991*9880d681SAndroid Build Coastguard Worker``llvm/lib/Transforms/`` 992*9880d681SAndroid Build Coastguard Worker 993*9880d681SAndroid Build Coastguard Worker IR-to-IR program transformations, such as Aggressive Dead Code Elimination, 994*9880d681SAndroid Build Coastguard Worker Sparse Conditional Constant Propagation, Inlining, Loop Invariant Code Motion, 995*9880d681SAndroid Build Coastguard Worker Dead Global Elimination, and many others. 996*9880d681SAndroid Build Coastguard Worker 997*9880d681SAndroid Build Coastguard Worker``llvm/lib/Target/`` 998*9880d681SAndroid Build Coastguard Worker 999*9880d681SAndroid Build Coastguard Worker Files describing target architectures for code generation. For example, 1000*9880d681SAndroid Build Coastguard Worker ``llvm/lib/Target/X86`` holds the X86 machine description. 1001*9880d681SAndroid Build Coastguard Worker 1002*9880d681SAndroid Build Coastguard Worker``llvm/lib/CodeGen/`` 1003*9880d681SAndroid Build Coastguard Worker 1004*9880d681SAndroid Build Coastguard Worker The major parts of the code generator: Instruction Selector, Instruction 1005*9880d681SAndroid Build Coastguard Worker Scheduling, and Register Allocation. 1006*9880d681SAndroid Build Coastguard Worker 1007*9880d681SAndroid Build Coastguard Worker``llvm/lib/MC/`` 1008*9880d681SAndroid Build Coastguard Worker 1009*9880d681SAndroid Build Coastguard Worker (FIXME: T.B.D.) ....? 1010*9880d681SAndroid Build Coastguard Worker 1011*9880d681SAndroid Build Coastguard Worker``llvm/lib/ExecutionEngine/`` 1012*9880d681SAndroid Build Coastguard Worker 1013*9880d681SAndroid Build Coastguard Worker Libraries for directly executing bitcode at runtime in interpreted and 1014*9880d681SAndroid Build Coastguard Worker JIT-compiled scenarios. 1015*9880d681SAndroid Build Coastguard Worker 1016*9880d681SAndroid Build Coastguard Worker``llvm/lib/Support/`` 1017*9880d681SAndroid Build Coastguard Worker 1018*9880d681SAndroid Build Coastguard Worker Source code that corresponding to the header files in ``llvm/include/ADT/`` 1019*9880d681SAndroid Build Coastguard Worker and ``llvm/include/Support/``. 1020*9880d681SAndroid Build Coastguard Worker 1021*9880d681SAndroid Build Coastguard Worker``llvm/projects`` 1022*9880d681SAndroid Build Coastguard Worker----------------- 1023*9880d681SAndroid Build Coastguard Worker 1024*9880d681SAndroid Build Coastguard WorkerProjects not strictly part of LLVM but shipped with LLVM. This is also the 1025*9880d681SAndroid Build Coastguard Workerdirectory for creating your own LLVM-based projects which leverage the LLVM 1026*9880d681SAndroid Build Coastguard Workerbuild system. 1027*9880d681SAndroid Build Coastguard Worker 1028*9880d681SAndroid Build Coastguard Worker``llvm/test`` 1029*9880d681SAndroid Build Coastguard Worker------------- 1030*9880d681SAndroid Build Coastguard Worker 1031*9880d681SAndroid Build Coastguard WorkerFeature and regression tests and other sanity checks on LLVM infrastructure. These 1032*9880d681SAndroid Build Coastguard Workerare intended to run quickly and cover a lot of territory without being exhaustive. 1033*9880d681SAndroid Build Coastguard Worker 1034*9880d681SAndroid Build Coastguard Worker``test-suite`` 1035*9880d681SAndroid Build Coastguard Worker-------------- 1036*9880d681SAndroid Build Coastguard Worker 1037*9880d681SAndroid Build Coastguard WorkerA comprehensive correctness, performance, and benchmarking test suite for LLVM. 1038*9880d681SAndroid Build Coastguard WorkerComes in a separate Subversion module because not every LLVM user is interested 1039*9880d681SAndroid Build Coastguard Workerin such a comprehensive suite. For details see the :doc:`Testing Guide 1040*9880d681SAndroid Build Coastguard Worker<TestingGuide>` document. 1041*9880d681SAndroid Build Coastguard Worker 1042*9880d681SAndroid Build Coastguard Worker.. _tools: 1043*9880d681SAndroid Build Coastguard Worker 1044*9880d681SAndroid Build Coastguard Worker``llvm/tools`` 1045*9880d681SAndroid Build Coastguard Worker-------------- 1046*9880d681SAndroid Build Coastguard Worker 1047*9880d681SAndroid Build Coastguard WorkerExecutables built out of the libraries 1048*9880d681SAndroid Build Coastguard Workerabove, which form the main part of the user interface. You can always get help 1049*9880d681SAndroid Build Coastguard Workerfor a tool by typing ``tool_name -help``. The following is a brief introduction 1050*9880d681SAndroid Build Coastguard Workerto the most important tools. More detailed information is in 1051*9880d681SAndroid Build Coastguard Workerthe `Command Guide <CommandGuide/index.html>`_. 1052*9880d681SAndroid Build Coastguard Worker 1053*9880d681SAndroid Build Coastguard Worker``bugpoint`` 1054*9880d681SAndroid Build Coastguard Worker 1055*9880d681SAndroid Build Coastguard Worker ``bugpoint`` is used to debug optimization passes or code generation backends 1056*9880d681SAndroid Build Coastguard Worker by narrowing down the given test case to the minimum number of passes and/or 1057*9880d681SAndroid Build Coastguard Worker instructions that still cause a problem, whether it is a crash or 1058*9880d681SAndroid Build Coastguard Worker miscompilation. See `<HowToSubmitABug.html>`_ for more information on using 1059*9880d681SAndroid Build Coastguard Worker ``bugpoint``. 1060*9880d681SAndroid Build Coastguard Worker 1061*9880d681SAndroid Build Coastguard Worker``llvm-ar`` 1062*9880d681SAndroid Build Coastguard Worker 1063*9880d681SAndroid Build Coastguard Worker The archiver produces an archive containing the given LLVM bitcode files, 1064*9880d681SAndroid Build Coastguard Worker optionally with an index for faster lookup. 1065*9880d681SAndroid Build Coastguard Worker 1066*9880d681SAndroid Build Coastguard Worker``llvm-as`` 1067*9880d681SAndroid Build Coastguard Worker 1068*9880d681SAndroid Build Coastguard Worker The assembler transforms the human readable LLVM assembly to LLVM bitcode. 1069*9880d681SAndroid Build Coastguard Worker 1070*9880d681SAndroid Build Coastguard Worker``llvm-dis`` 1071*9880d681SAndroid Build Coastguard Worker 1072*9880d681SAndroid Build Coastguard Worker The disassembler transforms the LLVM bitcode to human readable LLVM assembly. 1073*9880d681SAndroid Build Coastguard Worker 1074*9880d681SAndroid Build Coastguard Worker``llvm-link`` 1075*9880d681SAndroid Build Coastguard Worker 1076*9880d681SAndroid Build Coastguard Worker ``llvm-link``, not surprisingly, links multiple LLVM modules into a single 1077*9880d681SAndroid Build Coastguard Worker program. 1078*9880d681SAndroid Build Coastguard Worker 1079*9880d681SAndroid Build Coastguard Worker``lli`` 1080*9880d681SAndroid Build Coastguard Worker 1081*9880d681SAndroid Build Coastguard Worker ``lli`` is the LLVM interpreter, which can directly execute LLVM bitcode 1082*9880d681SAndroid Build Coastguard Worker (although very slowly...). For architectures that support it (currently x86, 1083*9880d681SAndroid Build Coastguard Worker Sparc, and PowerPC), by default, ``lli`` will function as a Just-In-Time 1084*9880d681SAndroid Build Coastguard Worker compiler (if the functionality was compiled in), and will execute the code 1085*9880d681SAndroid Build Coastguard Worker *much* faster than the interpreter. 1086*9880d681SAndroid Build Coastguard Worker 1087*9880d681SAndroid Build Coastguard Worker``llc`` 1088*9880d681SAndroid Build Coastguard Worker 1089*9880d681SAndroid Build Coastguard Worker ``llc`` is the LLVM backend compiler, which translates LLVM bitcode to a 1090*9880d681SAndroid Build Coastguard Worker native code assembly file or to C code (with the ``-march=c`` option). 1091*9880d681SAndroid Build Coastguard Worker 1092*9880d681SAndroid Build Coastguard Worker``opt`` 1093*9880d681SAndroid Build Coastguard Worker 1094*9880d681SAndroid Build Coastguard Worker ``opt`` reads LLVM bitcode, applies a series of LLVM to LLVM transformations 1095*9880d681SAndroid Build Coastguard Worker (which are specified on the command line), and outputs the resultant 1096*9880d681SAndroid Build Coastguard Worker bitcode. '``opt -help``' is a good way to get a list of the 1097*9880d681SAndroid Build Coastguard Worker program transformations available in LLVM. 1098*9880d681SAndroid Build Coastguard Worker 1099*9880d681SAndroid Build Coastguard Worker ``opt`` can also run a specific analysis on an input LLVM bitcode 1100*9880d681SAndroid Build Coastguard Worker file and print the results. Primarily useful for debugging 1101*9880d681SAndroid Build Coastguard Worker analyses, or familiarizing yourself with what an analysis does. 1102*9880d681SAndroid Build Coastguard Worker 1103*9880d681SAndroid Build Coastguard Worker``llvm/utils`` 1104*9880d681SAndroid Build Coastguard Worker-------------- 1105*9880d681SAndroid Build Coastguard Worker 1106*9880d681SAndroid Build Coastguard WorkerUtilities for working with LLVM source code; some are part of the build process 1107*9880d681SAndroid Build Coastguard Workerbecause they are code generators for parts of the infrastructure. 1108*9880d681SAndroid Build Coastguard Worker 1109*9880d681SAndroid Build Coastguard Worker 1110*9880d681SAndroid Build Coastguard Worker``codegen-diff`` 1111*9880d681SAndroid Build Coastguard Worker 1112*9880d681SAndroid Build Coastguard Worker ``codegen-diff`` finds differences between code that LLC 1113*9880d681SAndroid Build Coastguard Worker generates and code that LLI generates. This is useful if you are 1114*9880d681SAndroid Build Coastguard Worker debugging one of them, assuming that the other generates correct output. For 1115*9880d681SAndroid Build Coastguard Worker the full user manual, run ```perldoc codegen-diff'``. 1116*9880d681SAndroid Build Coastguard Worker 1117*9880d681SAndroid Build Coastguard Worker``emacs/`` 1118*9880d681SAndroid Build Coastguard Worker 1119*9880d681SAndroid Build Coastguard Worker Emacs and XEmacs syntax highlighting for LLVM assembly files and TableGen 1120*9880d681SAndroid Build Coastguard Worker description files. See the ``README`` for information on using them. 1121*9880d681SAndroid Build Coastguard Worker 1122*9880d681SAndroid Build Coastguard Worker``getsrcs.sh`` 1123*9880d681SAndroid Build Coastguard Worker 1124*9880d681SAndroid Build Coastguard Worker Finds and outputs all non-generated source files, 1125*9880d681SAndroid Build Coastguard Worker useful if one wishes to do a lot of development across directories 1126*9880d681SAndroid Build Coastguard Worker and does not want to find each file. One way to use it is to run, 1127*9880d681SAndroid Build Coastguard Worker for example: ``xemacs `utils/getsources.sh``` from the top of the LLVM source 1128*9880d681SAndroid Build Coastguard Worker tree. 1129*9880d681SAndroid Build Coastguard Worker 1130*9880d681SAndroid Build Coastguard Worker``llvmgrep`` 1131*9880d681SAndroid Build Coastguard Worker 1132*9880d681SAndroid Build Coastguard Worker Performs an ``egrep -H -n`` on each source file in LLVM and 1133*9880d681SAndroid Build Coastguard Worker passes to it a regular expression provided on ``llvmgrep``'s command 1134*9880d681SAndroid Build Coastguard Worker line. This is an efficient way of searching the source base for a 1135*9880d681SAndroid Build Coastguard Worker particular regular expression. 1136*9880d681SAndroid Build Coastguard Worker 1137*9880d681SAndroid Build Coastguard Worker``makellvm`` 1138*9880d681SAndroid Build Coastguard Worker 1139*9880d681SAndroid Build Coastguard Worker Compiles all files in the current directory, then 1140*9880d681SAndroid Build Coastguard Worker compiles and links the tool that is the first argument. For example, assuming 1141*9880d681SAndroid Build Coastguard Worker you are in ``llvm/lib/Target/Sparc``, if ``makellvm`` is in your 1142*9880d681SAndroid Build Coastguard Worker path, running ``makellvm llc`` will make a build of the current 1143*9880d681SAndroid Build Coastguard Worker directory, switch to directory ``llvm/tools/llc`` and build it, causing a 1144*9880d681SAndroid Build Coastguard Worker re-linking of LLC. 1145*9880d681SAndroid Build Coastguard Worker 1146*9880d681SAndroid Build Coastguard Worker``TableGen/`` 1147*9880d681SAndroid Build Coastguard Worker 1148*9880d681SAndroid Build Coastguard Worker Contains the tool used to generate register 1149*9880d681SAndroid Build Coastguard Worker descriptions, instruction set descriptions, and even assemblers from common 1150*9880d681SAndroid Build Coastguard Worker TableGen description files. 1151*9880d681SAndroid Build Coastguard Worker 1152*9880d681SAndroid Build Coastguard Worker``vim/`` 1153*9880d681SAndroid Build Coastguard Worker 1154*9880d681SAndroid Build Coastguard Worker vim syntax-highlighting for LLVM assembly files 1155*9880d681SAndroid Build Coastguard Worker and TableGen description files. See the ``README`` for how to use them. 1156*9880d681SAndroid Build Coastguard Worker 1157*9880d681SAndroid Build Coastguard Worker.. _simple example: 1158*9880d681SAndroid Build Coastguard Worker 1159*9880d681SAndroid Build Coastguard WorkerAn Example Using the LLVM Tool Chain 1160*9880d681SAndroid Build Coastguard Worker==================================== 1161*9880d681SAndroid Build Coastguard Worker 1162*9880d681SAndroid Build Coastguard WorkerThis section gives an example of using LLVM with the Clang front end. 1163*9880d681SAndroid Build Coastguard Worker 1164*9880d681SAndroid Build Coastguard WorkerExample with clang 1165*9880d681SAndroid Build Coastguard Worker------------------ 1166*9880d681SAndroid Build Coastguard Worker 1167*9880d681SAndroid Build Coastguard Worker#. First, create a simple C file, name it 'hello.c': 1168*9880d681SAndroid Build Coastguard Worker 1169*9880d681SAndroid Build Coastguard Worker .. code-block:: c 1170*9880d681SAndroid Build Coastguard Worker 1171*9880d681SAndroid Build Coastguard Worker #include <stdio.h> 1172*9880d681SAndroid Build Coastguard Worker 1173*9880d681SAndroid Build Coastguard Worker int main() { 1174*9880d681SAndroid Build Coastguard Worker printf("hello world\n"); 1175*9880d681SAndroid Build Coastguard Worker return 0; 1176*9880d681SAndroid Build Coastguard Worker } 1177*9880d681SAndroid Build Coastguard Worker 1178*9880d681SAndroid Build Coastguard Worker#. Next, compile the C file into a native executable: 1179*9880d681SAndroid Build Coastguard Worker 1180*9880d681SAndroid Build Coastguard Worker .. code-block:: console 1181*9880d681SAndroid Build Coastguard Worker 1182*9880d681SAndroid Build Coastguard Worker % clang hello.c -o hello 1183*9880d681SAndroid Build Coastguard Worker 1184*9880d681SAndroid Build Coastguard Worker .. note:: 1185*9880d681SAndroid Build Coastguard Worker 1186*9880d681SAndroid Build Coastguard Worker Clang works just like GCC by default. The standard -S and -c arguments 1187*9880d681SAndroid Build Coastguard Worker work as usual (producing a native .s or .o file, respectively). 1188*9880d681SAndroid Build Coastguard Worker 1189*9880d681SAndroid Build Coastguard Worker#. Next, compile the C file into an LLVM bitcode file: 1190*9880d681SAndroid Build Coastguard Worker 1191*9880d681SAndroid Build Coastguard Worker .. code-block:: console 1192*9880d681SAndroid Build Coastguard Worker 1193*9880d681SAndroid Build Coastguard Worker % clang -O3 -emit-llvm hello.c -c -o hello.bc 1194*9880d681SAndroid Build Coastguard Worker 1195*9880d681SAndroid Build Coastguard Worker The -emit-llvm option can be used with the -S or -c options to emit an LLVM 1196*9880d681SAndroid Build Coastguard Worker ``.ll`` or ``.bc`` file (respectively) for the code. This allows you to use 1197*9880d681SAndroid Build Coastguard Worker the `standard LLVM tools <CommandGuide/index.html>`_ on the bitcode file. 1198*9880d681SAndroid Build Coastguard Worker 1199*9880d681SAndroid Build Coastguard Worker#. Run the program in both forms. To run the program, use: 1200*9880d681SAndroid Build Coastguard Worker 1201*9880d681SAndroid Build Coastguard Worker .. code-block:: console 1202*9880d681SAndroid Build Coastguard Worker 1203*9880d681SAndroid Build Coastguard Worker % ./hello 1204*9880d681SAndroid Build Coastguard Worker 1205*9880d681SAndroid Build Coastguard Worker and 1206*9880d681SAndroid Build Coastguard Worker 1207*9880d681SAndroid Build Coastguard Worker .. code-block:: console 1208*9880d681SAndroid Build Coastguard Worker 1209*9880d681SAndroid Build Coastguard Worker % lli hello.bc 1210*9880d681SAndroid Build Coastguard Worker 1211*9880d681SAndroid Build Coastguard Worker The second examples shows how to invoke the LLVM JIT, :doc:`lli 1212*9880d681SAndroid Build Coastguard Worker <CommandGuide/lli>`. 1213*9880d681SAndroid Build Coastguard Worker 1214*9880d681SAndroid Build Coastguard Worker#. Use the ``llvm-dis`` utility to take a look at the LLVM assembly code: 1215*9880d681SAndroid Build Coastguard Worker 1216*9880d681SAndroid Build Coastguard Worker .. code-block:: console 1217*9880d681SAndroid Build Coastguard Worker 1218*9880d681SAndroid Build Coastguard Worker % llvm-dis < hello.bc | less 1219*9880d681SAndroid Build Coastguard Worker 1220*9880d681SAndroid Build Coastguard Worker#. Compile the program to native assembly using the LLC code generator: 1221*9880d681SAndroid Build Coastguard Worker 1222*9880d681SAndroid Build Coastguard Worker .. code-block:: console 1223*9880d681SAndroid Build Coastguard Worker 1224*9880d681SAndroid Build Coastguard Worker % llc hello.bc -o hello.s 1225*9880d681SAndroid Build Coastguard Worker 1226*9880d681SAndroid Build Coastguard Worker#. Assemble the native assembly language file into a program: 1227*9880d681SAndroid Build Coastguard Worker 1228*9880d681SAndroid Build Coastguard Worker .. code-block:: console 1229*9880d681SAndroid Build Coastguard Worker 1230*9880d681SAndroid Build Coastguard Worker % /opt/SUNWspro/bin/cc -xarch=v9 hello.s -o hello.native # On Solaris 1231*9880d681SAndroid Build Coastguard Worker 1232*9880d681SAndroid Build Coastguard Worker % gcc hello.s -o hello.native # On others 1233*9880d681SAndroid Build Coastguard Worker 1234*9880d681SAndroid Build Coastguard Worker#. Execute the native code program: 1235*9880d681SAndroid Build Coastguard Worker 1236*9880d681SAndroid Build Coastguard Worker .. code-block:: console 1237*9880d681SAndroid Build Coastguard Worker 1238*9880d681SAndroid Build Coastguard Worker % ./hello.native 1239*9880d681SAndroid Build Coastguard Worker 1240*9880d681SAndroid Build Coastguard Worker Note that using clang to compile directly to native code (i.e. when the 1241*9880d681SAndroid Build Coastguard Worker ``-emit-llvm`` option is not present) does steps 6/7/8 for you. 1242*9880d681SAndroid Build Coastguard Worker 1243*9880d681SAndroid Build Coastguard WorkerCommon Problems 1244*9880d681SAndroid Build Coastguard Worker=============== 1245*9880d681SAndroid Build Coastguard Worker 1246*9880d681SAndroid Build Coastguard WorkerIf you are having problems building or using LLVM, or if you have any other 1247*9880d681SAndroid Build Coastguard Workergeneral questions about LLVM, please consult the `Frequently Asked 1248*9880d681SAndroid Build Coastguard WorkerQuestions <FAQ.html>`_ page. 1249*9880d681SAndroid Build Coastguard Worker 1250*9880d681SAndroid Build Coastguard Worker.. _links: 1251*9880d681SAndroid Build Coastguard Worker 1252*9880d681SAndroid Build Coastguard WorkerLinks 1253*9880d681SAndroid Build Coastguard Worker===== 1254*9880d681SAndroid Build Coastguard Worker 1255*9880d681SAndroid Build Coastguard WorkerThis document is just an **introduction** on how to use LLVM to do some simple 1256*9880d681SAndroid Build Coastguard Workerthings... there are many more interesting and complicated things that you can do 1257*9880d681SAndroid Build Coastguard Workerthat aren't documented here (but we'll gladly accept a patch if you want to 1258*9880d681SAndroid Build Coastguard Workerwrite something up!). For more information about LLVM, check out: 1259*9880d681SAndroid Build Coastguard Worker 1260*9880d681SAndroid Build Coastguard Worker* `LLVM Homepage <http://llvm.org/>`_ 1261*9880d681SAndroid Build Coastguard Worker* `LLVM Doxygen Tree <http://llvm.org/doxygen/>`_ 1262*9880d681SAndroid Build Coastguard Worker* `Starting a Project that Uses LLVM <http://llvm.org/docs/Projects.html>`_ 1263