000d0507da8b0643a9ed67dbedc8ee8e33d08dab
[oota-llvm.git] / docs / CFEBuildInstrs.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <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 LLVM C/C++ Front-End</title>
7 </head>
8 <body>
9
10 <div class="doc_title">
11   Bootstrapping the LLVM C/C++ Front-End
12 </div>
13
14 <ol>
15   <li><a href="#cautionarynote">A Cautionary Note</a>
16   <li><a href="#instructions">Instructions</a>
17 </ol>
18
19 <div class="doc_text">    
20   <p><b>Written by Brian R. Gaeke</b></p>
21 </div>
22
23 <!-- *********************************************************************** -->
24 <div class="doc_section">
25   <a name="cautionarynote">A Cautionary Note</a>
26 </div>
27 <!-- *********************************************************************** -->
28
29 <div class="doc_text">
30 <p>This document is intended to explain the process of building the
31 LLVM C/C++ front-end, based on GCC 3.4, from its source code. You
32 would have to do this, for example, if you are porting LLVM to a new
33 architecture or operating system.</p>
34
35 <p><b>NOTE:</b> This is currently a somewhat fragile, error-prone
36 process, and you should <b>only</b> try to do it if:</p>
37
38 <ol>
39   <li>you really, really, really can't use the binaries we distribute</li>
40   <li>you need GCC to fix some of the header files on your system</li>
41   <li>you are an elite GCC hacker.</li>
42 </ol>
43
44 <p>We welcome patches to help make this process simpler.</p>
45 </div>
46
47 <!-- *********************************************************************** -->
48 <div class="doc_section">
49   <a name="instructions">Instructions</a>
50 </div>
51 <!-- *********************************************************************** -->
52
53 <div class="doc_text">
54 <p>
55 <ol>
56 <li><p>Configure and build the LLVM libraries and tools using:</p>
57 <pre>
58  % cd llvm
59  % ./configure [options...]
60  % gmake tools-only
61 </pre>
62     <p>The use of the non-default target "tools-only" means that the
63     LLVM tools and libraries will build, and the binaries will be
64     deposited in llvm/tools/Debug, but the runtime (bytecode)
65     libraries will not build.</p></li>
66
67 <li><p>Add the directory containing the tools to your PATH.</p>
68 <pre>
69  % set path = ( `cd llvm/tools/Debug &amp;&amp; pwd` $path )
70 </pre></li>
71
72 <li><p>Unpack the C/C++ front-end source into cfrontend/src.</p></li>
73
74 <li><p>Edit src/configure.  Change the first line (starting w/ #!) to
75        contain the correct full pathname of sh.</p></li>
76
77 <li><p>Make "build" and "install" directories as siblings of the "src"
78        tree.</p>
79 <pre>
80  % pwd
81  /usr/local/example/cfrontend/src
82  % cd ..
83  % mkdir build install
84  % set CFEINSTALL = `pwd`/install
85 </pre></li>
86
87 <li><p>Configure, build and install the C front-end:</p>
88 <pre>
89  % cd build
90  % ../src/configure --prefix=$CFEINSTALL --disable-nls --disable-shared \
91    --enable-languages=c,c++
92  % gmake all-gcc
93  % setenv LLVM_LIB_SEARCH_PATH `pwd`/gcc 
94  % gmake all; gmake install
95 </pre>
96
97  <p><b>Common Problem:</b> You may get error messages regarding the fact
98  that LLVM does not support inline assembly. Here are two common
99  fixes:</p>
100
101  <ul>
102   <li><p><b>Fix 1:</b> If you have system header files that include
103    inline assembly, you may have to modify them to remove the inline
104    assembly, and install the modified versions in
105    <code>$CFEINSTALL/<i>target-triplet</i>/sys-include</code>.</p></li>
106
107   <li><b>Fix 2:</b> If you are building the C++ front-end on a CPU we
108    haven't tried yet, you will probably have to edit the appropriate
109    version of atomicity.h under
110    <code>src/libstdc++-v3/config/cpu/<i>name-of-cpu</i>/atomicity.h</code>
111    and apply a patch so that it does not use inline assembly.</p></li>
112  </ul>
113
114  <p><b>Porting to a new architecture:</b> If you are porting the new front-end
115  to a new architecture, or compiling in a different configuration that we have
116  previously, there are probably several changes you will have to make to the GCC
117  target to get it to work correctly.  These include:<p>
118
119  <ul>
120   <li>Often targets include special or assembler linker flags which
121       <tt>gccas</tt>/<tt>gccld</tt> does not understand.  In general, these can
122       just be removed.</li>
123   <li>LLVM currently does not support any floating point values other than 
124       32-bit and 64-bit IEEE floating point.  The primary effect of this is
125       that you may have to map "long double" onto "double".</li>
126   <li>The profiling hooks in GCC do not apply at all to the LLVM front-end.
127       These may need to be disabled.</li>
128   <li>No inline assembly for position independent code.  At the LLVM level,
129       everything is position independent.</li>
130   <li>We handle <tt>.init</tt> and <tt>.fini</tt> differently.</li>
131   <li>You may have to disable multilib support in your target.  Using multilib
132       support causes the GCC compiler driver to add a lot of "<tt>-L</tt>"
133       options to the link line, which do not relate to LLVM and confuse
134       <tt>gccld</tt>.  To disable multilibs, delete any
135       <tt>MULTILIB_OPTIONS</tt> lines from your target files.</li>
136   <li>Did we mention that we don't support inline assembly?  You'll probably
137       have to add some fixinclude hacks to disable it in the system
138       headers.</li>
139  </ul>
140 </li>
141
142 <li><p>Go back into the LLVM source tree proper. Edit Makefile.config
143 to redefine <code>LLVMGCCDIR</code> to the full pathname of the
144 <code>$CFEINSTALL</code> directory, which is the directory you just
145 installed the C front-end into. (The ./configure script is likely to
146 have set this to a directory which does not exist on your system.)</p></li>
147
148 <li><p>If you edited header files during the C/C++ front-end build as
149 described in "Fix 1" above, you must now copy those header files from
150 <code>$CFEINSTALL/<i>target-triplet</i>/sys-include</code> to
151 <code>$CFEINSTALL/lib/gcc/<i>target-triplet</i>/3.4-llvm/include</code>.
152 (This should be the "include" directory in the same directory as the
153 libgcc.a library, which you can find by running
154 <code>$CFEINSTALL/bin/gcc --print-libgcc-file-name</code>.)</p></li>
155
156 <li><p>Build and install the runtime (bytecode) libraries by running:</p>
157 <pre>
158  % gmake -C runtime
159  % mkdir $CFEINSTALL/bytecode-libs
160  % gmake -C runtime install
161  % setenv LLVM_LIB_SEARCH_PATH $CFEINSTALL/bytecode-libs
162 </pre></li>
163
164 <li><p>Test the newly-installed C frontend by one or more of the
165 following means:</p>
166  <ul>
167   <li> compiling and running a "hello, LLVM" program in C and C++.</li>
168   <li> running the tests under <tt>test/Programs</tt> using <code>gmake -C
169    test/Programs</code></li>
170  </ul>
171   </p>
172 </li>
173 </ol>
174 </div>
175
176 <!-- *********************************************************************** -->
177
178 <hr>
179 <div class="doc_footer">
180   <address>Brian Gaeke</address>
181   <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a>
182   <br>
183   Last modified: $Date$
184 </div>
185
186 </body>
187 </html>