blob: 5e753ab99252f194f5544961c3483e8d81c2f720 [file] [log] [blame]
Brian Gaeke46079d22003-10-21 21:58:38 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
Misha Brukman83bd33a2003-10-23 01:48:33 +00002<html>
3<head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
5 <link rel="stylesheet" href="llvm.css" type="text/css" media="screen" />
6 <title>Bootstrapping the C/C++ Front-End</title>
7</head>
8<body>
Brian Gaeke46079d22003-10-21 21:58:38 +00009
Misha Brukman83bd33a2003-10-23 01:48:33 +000010<div class="doc_title">
11 Bootstrapping the C/C++ Front-End
12</div>
Brian Gaeke46079d22003-10-21 21:58:38 +000013
14<p>This document is intended to explain the process of building the LLVM
15C/C++ front-end, based on GCC 3.4, from source.</p>
16
17<p><b>NOTE:</b> This is currently a somewhat fragile, error-prone
John Criswell0f6d7c02003-10-27 18:18:16 +000018process, and you should only try to do it if
19<ul>
20 <li>(A) you really, really, really can't use the binaries we distribute
21 <li>(B) you need GCC to fix some of the header files on your system
22 <li>(C) you are an elite GCC hacker.</p>
23</ul>
Brian Gaeke46079d22003-10-21 21:58:38 +000024
25<p>We welcome patches to help make this process simpler.</p>
26
Misha Brukman83bd33a2003-10-23 01:48:33 +000027<!-- *********************************************************************** -->
28<div class="doc_section">
29 <a name="instructions">Instructions</a>
30</div>
31<!-- *********************************************************************** -->
32
33<div class="doc_text">
34<p>
Brian Gaeke46079d22003-10-21 21:58:38 +000035<ol>
36<li><p>Configure and build the LLVM libraries and tools using:</p>
37<pre>
38 % cd llvm
39 % ./configure [options...]
40 % gmake tools-only
41</pre>
42 <p>The use of the non-default target "tools-only" means that the
43 LLVM tools and libraries will build, and the binaries will be
44 deposited in llvm/tools/Debug, but the runtime (bytecode)
Misha Brukman83bd33a2003-10-23 01:48:33 +000045 libraries will not build.</p></li>
Brian Gaeke46079d22003-10-21 21:58:38 +000046
47<li><p>Add the directory containing the tools to your PATH.</p>
48<pre>
Misha Brukman83bd33a2003-10-23 01:48:33 +000049 % set path = ( `cd llvm/tools/Debug &amp;&amp; pwd` $path )
50</pre></li>
Brian Gaeke46079d22003-10-21 21:58:38 +000051
Misha Brukman83bd33a2003-10-23 01:48:33 +000052<li><p>Unpack the C/C++ front-end source into cfrontend/src.</p></li>
Brian Gaeke46079d22003-10-21 21:58:38 +000053
54<li><p>Edit src/configure. Change the first line (starting w/ #!) to
Misha Brukman83bd33a2003-10-23 01:48:33 +000055 contain the correct full pathname of sh.</p></li>
Brian Gaeke46079d22003-10-21 21:58:38 +000056
57<li><p>Make "build" and "install" directories as siblings of the "src"
58 tree.</p>
59<pre>
60 % pwd
61 /usr/local/example/cfrontend/src
62 % cd ..
63 % mkdir build install
64 % set CFEINSTALL = `pwd`/install
Misha Brukman83bd33a2003-10-23 01:48:33 +000065</pre></li>
Brian Gaeke46079d22003-10-21 21:58:38 +000066
67<li><p>Configure, build and install the C front-end:</p>
68<pre>
69 % cd build
70 % ../src/configure --prefix=$CFEINSTALL --disable-nls --disable-shared \
71 --enable-languages=c,c++
72 % gmake all-gcc
73 % setenv LLVM_LIB_SEARCH_PATH `pwd`/gcc
74 % gmake all; gmake install
75</pre>
76
Chris Lattnere38c6282003-10-23 03:55:23 +000077 <p><b>Common Problem:</b> You may get error messages regarding the fact
Brian Gaeke46079d22003-10-21 21:58:38 +000078 that LLVM does not support inline assembly. Here are two common
79 fixes:</p>
80
81 <ul>
82 <li><p><b>Fix 1:</b> If you have system header files that include
83 inline assembly, you may have to modify them to remove the inline
84 assembly, and install the modified versions in
Misha Brukman83bd33a2003-10-23 01:48:33 +000085 <code>$CFEINSTALL/<i>target-triplet</i>/sys-include</code>.</p></li>
Brian Gaeke46079d22003-10-21 21:58:38 +000086
87 <li><b>Fix 2:</b> If you are building the C++ front-end on a CPU we
88 haven't tried yet, you will probably have to edit the appropriate
89 version of atomicity.h under
90 <code>src/libstdc++-v3/config/cpu/<i>name-of-cpu</i>/atomicity.h</code>
Misha Brukman83bd33a2003-10-23 01:48:33 +000091 and apply a patch so that it does not use inline assembly.</p></li>
Brian Gaeke46079d22003-10-21 21:58:38 +000092 </ul>
93
Chris Lattnere38c6282003-10-23 03:55:23 +000094 <p><b>Porting to a new architecture:</b> If you are porting the new front-end
95 to a new architecture, or compiling in a different configuration that we have
96 previously, there are probably several changes you will have to make to the GCC
97 target to get it to work correctly. These include:<p>
Brian Gaeke46079d22003-10-21 21:58:38 +000098
99 <ul>
Chris Lattnere38c6282003-10-23 03:55:23 +0000100 <li>Often targets include special or assembler linker flags which
101 <tt>gccas</tt>/<tt>gccld</tt> does not understand. In general, these can
102 just be removed.</li>
103 <li>LLVM currently does not support any floating point values other than
104 32-bit and 64-bit IEEE floating point. The primary effect of this is
105 that you may have to map "long double" onto "double".</li>
106 <li>The profiling hooks in GCC do not apply at all to the LLVM front-end.
107 These may need to be disabled.</li>
108 <li>No inline assembly for position independent code. At the LLVM level,
109 everything is position independent.</li>
110 <li>We handle <tt>.init</tt> and <tt>.fini</tt> differently.</li>
Chris Lattner13964e02003-10-24 16:02:34 +0000111 <li>You may have to disable multilib support in your target. Using multilib
112 support causes the GCC compiler driver to add a lot of "<tt>-L</tt>"
113 options to the link line, which do not relate to LLVM and confuse
114 <tt>gccld</tt>. To disable multilibs, delete any
115 <tt>MULTILIB_OPTIONS</tt> lines from your target files.</li>
Chris Lattnere38c6282003-10-23 03:55:23 +0000116 <li>Did we mention that we don't support inline assembly? You'll probably
117 have to add some fixinclude hacks to disable it in the system
118 headers.</li>
Brian Gaeke46079d22003-10-21 21:58:38 +0000119 </ul>
Misha Brukman83bd33a2003-10-23 01:48:33 +0000120</li>
Brian Gaeke46079d22003-10-21 21:58:38 +0000121
122<li><p>Go back into the LLVM source tree proper. Edit Makefile.config
123to redefine <code>LLVMGCCDIR</code> to the full pathname of the
124<code>$CFEINSTALL</code> directory, which is the directory you just
125installed the C front-end into. (The ./configure script is likely to
Misha Brukman83bd33a2003-10-23 01:48:33 +0000126have set this to a directory which does not exist on your system.)</p></li>
Brian Gaeke46079d22003-10-21 21:58:38 +0000127
128<li><p>If you edited header files during the C/C++ front-end build as
129described in "Fix 1" above, you must now copy those header files from
130<code>$CFEINSTALL/<i>target-triplet</i>/sys-include</code> to
131<code>$CFEINSTALL/lib/gcc/<i>target-triplet</i>/3.4-llvm/include</code>.
132(This should be the "include" directory in the same directory as the
133libgcc.a library, which you can find by running
Misha Brukman83bd33a2003-10-23 01:48:33 +0000134<code>$CFEINSTALL/bin/gcc --print-libgcc-file-name</code>.)</p></li>
Brian Gaeke46079d22003-10-21 21:58:38 +0000135
136<li><p>Build and install the runtime (bytecode) libraries by running:</p>
137<pre>
138 % gmake -C runtime
139 % mkdir $CFEINSTALL/bytecode-libs
140 % gmake -C runtime install
141 % setenv LLVM_LIB_SEARCH_PATH $CFEINSTALL/bytecode-libs
Misha Brukman83bd33a2003-10-23 01:48:33 +0000142</pre></li>
Brian Gaeke46079d22003-10-21 21:58:38 +0000143
144<li><p>Test the newly-installed C frontend by one or more of the
145following means:</p>
146 <ul>
Chris Lattnere38c6282003-10-23 03:55:23 +0000147 <li> compiling and running a "hello, LLVM" program in C and C++.</li>
148 <li> running the tests under <tt>test/Programs</tt> using <code>gmake -C
Misha Brukman83bd33a2003-10-23 01:48:33 +0000149 test/Programs</code></li>
Brian Gaeke46079d22003-10-21 21:58:38 +0000150 </ul>
Misha Brukman83bd33a2003-10-23 01:48:33 +0000151 </p>
152</li>
Brian Gaeke46079d22003-10-21 21:58:38 +0000153</ol>
Misha Brukman83bd33a2003-10-23 01:48:33 +0000154</div>
Brian Gaeke46079d22003-10-21 21:58:38 +0000155
156<!-- *********************************************************************** -->
Brian Gaeke46079d22003-10-21 21:58:38 +0000157
Misha Brukman83bd33a2003-10-23 01:48:33 +0000158<hr><font size="-1">
Brian Gaeke46079d22003-10-21 21:58:38 +0000159<address><a href="mailto:gaeke -at- uiuc.edu">Brian Gaeke</a></address>
John Criswell0f6d7c02003-10-27 18:18:16 +0000160<a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a>
161<br>
Brian Gaeke46079d22003-10-21 21:58:38 +0000162Last modified: $Date$
Misha Brukman83bd33a2003-10-23 01:48:33 +0000163</font>
Brian Gaeke46079d22003-10-21 21:58:38 +0000164
Misha Brukman83bd33a2003-10-23 01:48:33 +0000165</body>
166</html>