For PR780:
[oota-llvm.git] / docs / CFEBuildInstrs.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2                       "http://www.w3.org/TR/html4/strict.dtd">
3 <html>
4 <head>
5   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
6   <link rel="stylesheet" href="llvm.css" type="text/css" media="screen">
7   <title>Bootstrapping the LLVM C/C++ Front-End</title>
8 </head>
9 <body>
10
11 <div class="doc_title">
12   Bootstrapping the LLVM C/C++ Front-End
13 </div>
14
15 <ol>
16   <li><a href="#cautionarynote">A Cautionary Note</a>
17     <ul>
18       <li><a href="#cygwin">Building under Cygwin</a></li>
19       <li><a href="#aix">Building under AIX</a></li>
20     </ul>
21   </li>
22   <li><a href="#instructions">llvm-gcc4 Instructions</a></li>
23   <li><a href="#llvm-gcc3-instructions">llvm-gcc3 Instructions</a></li>
24   <li><a href="#license">License Information</a></li>
25 </ol>
26
27 <div class="doc_author">    
28   <p>Written by Brian R. Gaeke and 
29      <a href="http://nondot.org/sabre">Chris Lattner</a></p>
30 </div>
31
32 <!-- *********************************************************************** -->
33 <div class="doc_section">
34   <a name="cautionarynote">A Cautionary Note</a>
35 </div>
36 <!-- *********************************************************************** -->
37
38 <div class="doc_text">
39 <p>This document is intended to explain the process of building the
40 LLVM C/C++ front-end from its source code. You have to do this, for example, if
41 you are porting LLVM to a new architecture or operating system, if you are
42 working from Top-Of-Tree CVS/SVN, or if there is no precompiled snapshot
43 available.</p>
44
45 <p><b>NOTE:</b> This is currently a somewhat fragile, error-prone
46 process, and you should <b>only</b> try to do it if:</p>
47
48 <ol>
49   <li>you really, really, really can't use the binaries we distribute</li>
50   <li>you are an elite GCC hacker.</li>
51   <li>you want to use the latest bits from CVS.</li>
52 </ol>
53
54 <p>We welcome patches to help make this process simpler.</p>
55 </div>
56
57 <!--=========================================================================-->
58 <div class="doc_subsection">
59   <a name="cygwin">Building under Cygwin</a>
60 </div>
61 <!--=========================================================================-->
62
63 <div class="doc_text">
64 <p>If you are building LLVM and the GCC front-end under Cygwin, please note that
65 the LLVM and GCC makefiles do not correctly handle spaces in paths.  To deal
66 with this issue, make sure that your LLVM and GCC source and build trees are 
67 located in a top-level directory (like <tt>/cygdrive/c/llvm</tt> and 
68 <tt>/cygdrive/c/llvm-cfrontend</tt>), not in a directory that contains a space
69 (which includes your "home directory", because it lives under the "Documents 
70 and Settings" directory).  We welcome patches to fix this issue.
71 </p>
72 <p>It has been found that the GCC 3.3.3 compiler provided with recent Cygwin
73 versions is incapable of compiling the LLVM GCC front-end correctly. If your
74 Cygwin
75 installation includes GCC 3.3.3, we <i>strongly</i> recommend that you download
76 GCC 3.4.3, build it separately, and use it for compiling the LLVM GCC front-end.
77  This has been
78 shown to work correctly.</p>
79 <p>Some versions of Cygwin utilize an experimental version of GNU binutils that
80 will cause the GNU <tt>ld</tt> linker to fail an assertion when linking
81 components of the libstdc++. It is recommended that you replace the entire
82 binutils package with version 2.15 such that "<tt>ld --version</tt>" responds
83 with</p>
84 <pre>GNU ld version 2.15</pre>
85 not with:<br/>
86 <pre>GNU ld version 2.15.91 20040725</pre>
87 </div>
88
89 <!--=========================================================================-->
90 <div class="doc_subsection"><a name="aix">Building under AIX</a></div>
91 <div class="doc_text">
92 <p>If you are building LLVM and the GCC front-end under AIX, do NOT use GNU
93 Binutils.  They are not stable under AIX and may produce incorrect and/or
94 invalid code.  Instead, use the system assembler and linker.
95 </p>
96 </div>
97
98 <!-- *********************************************************************** -->
99 <div class="doc_section">
100   <a name="instructions">llvm-gcc4 Instructions</a>
101 </div>
102 <!-- *********************************************************************** -->
103
104 <div class="doc_text">
105
106 <p>This section describes how to aquire and build llvm-gcc4, which is based on
107 the GCC 4.0.1 front-end.  This front-end supports C, C++, Objective-C, and 
108 Objective-C++.  Note that the instructions for building this front-end are
109 completely different than those for building llvm-gcc3.
110 </p>
111
112 <ol>
113 <li>
114 <p>Retrieve the appropriate llvm-gcc4-x.y.source.tar.gz archive from the llvm
115 web site.</p>
116 <p>It is also possible to download the sources of the llvm-gcc4 front end from
117 a read-only mirror using subversion.  To check out the code the first time use:
118 </p>
119
120 <tt>svn co svn://anonsvn.opensource.apple.com/svn/llvm <i>dst-directory</i></tt>
121
122 <p>After that, the code can be be updated in the destination directory using;
123 </p>
124
125 <tt>svn update</tt>
126
127 <p>The mirror is brought up to date every evening.</p>
128 </li>
129
130 <li>Follow the directions in the top-level README.LLVM file for up-to-date
131     instructions on how to build llvm-gcc4.</li>
132 </ol>
133 </div>
134
135 <!-- *********************************************************************** -->
136 <div class="doc_section">
137   <a name="llvm-gcc3-instructions">llvm-gcc3 Instructions</a>
138 </div>
139 <!-- *********************************************************************** -->
140
141 <div class="doc_text">
142 <ol>
143 <li>Aquire llvm-gcc3 from <a href="GettingStarted.html#checkout">LLVM CVS</a> or
144 from a <a href="http://llvm.org/releases/">release tarball</a>.</li>
145
146 <li><p>Configure and build the LLVM libraries and tools. There are two ways to
147 do this: either with <i>objdir</i> == <i>srcdir</i> or
148 <i>objdir</i> != <i>srcdir</i>. It is recommended 
149 that <i>srcdir</i> be the same as <i>objdir</i> for your LLVM tree (but note
150 that you should always use <i>srcdir</i> != <i>objdir</i> for llvm-gcc):</p>
151 <ul>
152   <li>With <i>objdir</i> != <i>srcdir</i>:<pre>
153  % cd <i>objdir</i>
154  % <i>srcdir</i>/configure --prefix=/some/path/you/can/install/to [options...]
155  % gmake tools-only
156   </pre></li>
157   <li>With <i>objdir</i> == <i>srcdir</i>:<pre>
158  % cd llvm
159  % ./configure --prefix=/some/path/you/can/install/to [options...]
160  % gmake tools-only
161   </pre></li>
162 </ul>
163 <p>This will build all of the LLVM tools and libraries. The <tt>--prefix</tt> 
164 option defaults to /usr/local (per configure standards) but unless you are a 
165 system administrator, you probably won't be able to install LLVM there because
166 of permissions. Specify a path into which LLVM can be installed (e.g.
167 <tt>--prefix=/home/user/llvm</tt>).</p>
168 </li>
169
170 <li><p>Add the directory containing the tools to your PATH.</p>
171 <pre>
172  % set path = ( `cd llvm/Debug/bin &amp;&amp; pwd` $path )
173 </pre></li>
174
175 <li><p>Unpack the C/C++ front-end source into cfrontend/src, either by
176        untar'ing a cfrontend.source.tar.gz file or checking out CVS into this
177        directory.</p></li>
178
179 <li><p>Make "build" and "install" directories as siblings of the "src" tree:</p>
180 <pre>
181  % pwd
182  /usr/local/example/cfrontend/src
183  % cd ..
184  % mkdir build install
185  % set CFEINSTALL = `pwd`/install
186 </pre></li>
187
188
189 <li><p>Configure, build, and install the GCC front-end:</p>
190
191 <p>
192 <b>Linux/x86:</b><br>
193 <b>Linux/IA-64:</b><br>
194 <b>MacOS X/PowerPC</b> (requires dlcompat library):<br>
195 <b>AIX/PowerPC:</b>
196 </p>
197
198 <pre>
199  % cd build
200  % ../src/configure --prefix=$CFEINSTALL --disable-threads --disable-nls \
201    --disable-shared --enable-languages=c,c++ --program-prefix=llvm-
202  % gmake all; gmake install
203 </pre>
204
205 <p><b>Cygwin/x86:</b></p>
206
207 <pre>
208  % cd build
209  % ../src/configure --prefix=$CFEINSTALL --disable-threads --disable-nls \
210    --disable-shared --enable-languages=c,c++ --disable-c-mbchar \
211    --program-prefix=llvm-
212  % gmake all; gmake install
213 </pre>
214
215 <p><b>Solaris/SPARC:</b></p>
216
217 <p>
218 The GCC front-end can be configured for either SPARC V8 (32 bit) or SPARC V9 (64
219 bit).  This changes, among other things, the sizes of integer types and the
220 macros defined for conditional compilation.
221 </p>
222
223 <p>
224 The SPARC V8 ABI support is more robust than the V9 ABI support and can generate
225 SPARC V9 code.  It is highly recommended that you use the V8 ABI with LLVM, as
226 shown below.  Also,
227 note that Solaris has trouble with various wide (multibyte) character
228 functions from C as referenced from C++, so we typically configure with
229 --disable-c-mbchar (cf. <a href="http://llvm.org/PR206">Bug 206</a>).
230 </p>
231
232 <pre>
233  % cd build
234  % ../src/configure --prefix=$CFEINSTALL --disable-threads --disable-nls \
235    --disable-shared --enable-languages=c,c++ --host=sparc-sun-solaris2.8 \
236    --disable-c-mbchar --program-prefix=llvm-
237  % gmake all; gmake install
238 </pre>
239
240  <p><b>Common Problem:</b> You may get error messages regarding the fact
241  that LLVM does not support inline assembly. Here are two common
242  fixes:</p>
243
244  <ul>
245   <li><p><b>Fix 1:</b> If you have system header files that include
246    inline assembly, you may have to modify them to remove the inline
247    assembly and install the modified versions in
248    <code>$CFEINSTALL/lib/gcc/<i>target-triplet</i>/3.4-llvm/include</code>.</li>
249
250   <li><b>Fix 2:</b> If you are building the C++ front-end on a CPU we
251    haven't tried yet, you will probably have to edit the appropriate
252    version of atomicity.h under
253    <code>src/libstdc++-v3/config/cpu/<i>name-of-cpu</i>/atomicity.h</code>
254    and apply a patch so that it does not use inline assembly.</li>
255  </ul>
256
257  <p><b>Porting to a new architecture:</b> If you are porting the front-end
258  to a new architecture or compiling in a configuration that we have
259  not tried previously, there are probably several changes you will have to make
260  to the GCC target to get it to work correctly.  These include:<p>
261
262  <ul>
263   <li>Often targets include special assembler or linker flags which
264       <tt>gccas</tt>/<tt>gccld</tt> does not understand.  In general, these can
265       just be removed.</li>
266   <li>LLVM currently does not support any floating point values other than 
267       32-bit and 64-bit IEEE floating point.  The primary effect of this is
268       that you may have to map "long double" onto "double".</li>
269   <li>The profiling hooks in GCC do not apply at all to the LLVM front-end.
270       These may need to be disabled.</li>
271   <li>No inline assembly for position independent code.  At the LLVM level,
272       everything is position independent.</li>
273   <li>We handle <tt>.init</tt> and <tt>.fini</tt> differently.</li>
274   <li>You may have to disable multilib support in your target.  Using multilib
275       support causes the GCC compiler driver to add a lot of "<tt>-L</tt>"
276       options to the link line, which do not relate to LLVM and confuse
277       <tt>gccld</tt>.  To disable multilibs, delete any
278       <tt>MULTILIB_OPTIONS</tt> lines from your target files.</li>
279   <li>Did we mention that we don't support inline assembly?  You'll probably
280       have to add some fixinclude hacks to disable it in the system
281       headers.</li>
282  </ul>
283 </li>
284
285 <li><p>Put <tt>$CFEINSTALL/bin</tt> into your <tt>PATH</tt> environment
286 variable.</p>
287   <ul>
288     <li>sh: <tt>export PATH=$CFEINSTALL/bin:$PATH</tt></li>
289     <li>csh: <tt>setenv PATH $CFEINSTALL/bin:$PATH</tt></li>
290   </ul>
291 </li>
292
293 <li><p>Go back into the LLVM source tree proper.  Rerun configure, using
294 the same options as the last time. This will cause the configuration to now find
295 the newly built llvm-gcc and llvm-g++ executables. </p></li>
296
297 <li><p>Rebuild your CVS tree.  This shouldn't cause the whole thing to be
298   rebuilt, but it should build the runtime libraries.  After the tree is
299   built, install the runtime libraries into your GCC front-end build tree.
300   These are the commands you need:</p>
301 <pre>
302  % gmake
303  % gmake -C runtime install-bytecode
304 </pre></li>
305
306 <li><p>Optionally, build a symbol table for the newly installed runtime 
307 libraries. Although this step is optional, you are strongly encouraged to 
308 do this as the symbol tables will make a significant difference in your 
309 link times. Use the <tt>llvm-ranlib</tt> tool to do this, as follows:</p>
310 <pre>
311  % cd $CFEINSTALL/lib
312  % llvm-ranlib libiberty.a
313  % llvm-ranlib libstdc++.a
314  % llvm-ranlib libsupc++.a
315  % cd $CFEINSTALL/lib/gcc/<i>target-triplet</i>/3.4-llvm
316  % llvm-ranlib libgcc.a
317  % llvm-ranlib libgcov.a
318 </pre>
319
320 <li><p>Test the newly-installed C frontend by one or more of the
321 following means:</p>
322  <ul>
323   <li> running the feature &amp; regression tests via <tt>make check</tt></li>
324   <li> compiling and running a "hello, LLVM" program in C and C++.</li>
325   <li> running the tests found in the <tt>llvm-test</tt> CVS module</li>
326  </ul></li>
327 </ol>
328 </div>
329
330 <!-- *********************************************************************** -->
331 <div class="doc_section">
332   <a name="license">License Information</a>
333 </div>
334
335 <div class="doc_text">
336 <p>
337 The LLVM GCC frontend is licensed to you under the GNU General Public License
338 and the GNU Lesser General Public License.  Please see the files COPYING and
339 COPYING.LIB for more details.
340 </p>
341
342 <p>
343 More information is <a href="FAQ.html#license">available in the FAQ</a>.
344 </p>
345 </pre>
346 </div>
347
348 <!-- *********************************************************************** -->
349
350 <hr>
351 <address>
352   <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
353   src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
354   <a href="http://validator.w3.org/check/referer"><img
355   src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a>
356
357   Brian Gaeke<br>
358   <a href="http://llvm.org">LLVM Compiler Infrastructure</a><br>
359   Last modified: $Date$
360 </address>
361
362 </body>
363 </html>