Add some PRs which were fixed, but not previously mentioned in the rel. notes.
[oota-llvm.git] / docs / FAQ.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   <title>LLVM: Frequently Asked Questions</title>
6   <style>
7     @import url("llvm.css");
8     .question { font-weight: bold }
9     .answer   { margin-left: 2em  }
10   </style>
11 </head>
12 <body>
13
14 <div class="doc_title">
15   LLVM: Frequently Asked Questions
16 </div>
17
18 <ol>
19   <li><a href="#license">License</a>
20   <ol>
21   <li>Why are the LLVM source code and the front-end distributed under different
22   licenses?</li>
23   <li>Does the University of Illinois Open Source License really qualify as an
24   "open source" license?</li>
25   <li>Can I modify LLVM source code and redistribute the modified source?</li>
26   <li>Can I modify LLVM source code and redistribute binaries or other tools
27   based on it, without redistributing the source?</li>
28   </ol></li>
29
30   <li><a href="#source">Source code</a>
31   <ol>
32   <li>In what language is LLVM written?</li>
33   <li>How portable is the LLVM source code?</li>
34   </ol></li>
35
36   <li><a href="#build">Build Problems</a>
37   <ol>
38   <li>When I run configure, it finds the wrong C compiler.</li>
39   <li>I compile the code, and I get some error about <tt>/localhome</tt>.</li>
40   <li>The <tt>configure</tt> script finds the right C compiler, but it uses the
41   LLVM linker from a previous build.  What do I do?</li>
42   <li>When creating a dynamic library, I get a strange GLIBC error.</li>
43   <li>I've updated my source tree from CVS, and now my build is trying to use a
44   file/directory that doesn't exist.</li>
45   <li>I've modified a Makefile in my source tree, but my build tree keeps using
46   the old version.  What do I do?</li>
47   <li>I've upgraded to a new version of LLVM, and I get strange build
48   errors.</li>
49   <li>I've built LLVM and am testing it, but the tests freeze.</li>
50   <li>Why do test results differ when I perform different types of builds?</li>
51   <li>Compiling LLVM with GCC 3.3.2 fails, what should I do?</li>
52   <li>When I use the test suite, all of the C Backend tests fail.  What is
53       wrong?</li>
54   </ol></li>
55
56   <li><a href="#cfe">Using the GCC Front End</a>
57   <ol>
58     <li>
59     When I compile software that uses a configure script, the configure script
60     thinks my system has all of the header files and libraries it is testing
61     for.  How do I get configure to work correctly?
62     </li>
63
64     <li>
65     When I compile code using the LLVM GCC front end, it complains that it
66     cannot find crtend.o.
67     </li>
68   </ol>
69   </li>
70
71   <li><a href="#cfe_code">Questions about code generated by the GCC front-end</a>
72   <ol>
73      <li>What is this <tt>__main()</tt> call that gets inserted into
74          <tt>main()</tt>?</li>
75      <li>Where did all of my code go??</li>
76      <li>What is this <tt>llvm.global_ctors</tt> and
77           <tt>_GLOBAL__I__tmp_webcompile...</tt> stuff that happens when I
78           #include &lt;iostream&gt;?</li>
79   </ol>
80   </li>
81 </ol>
82
83 <!-- *********************************************************************** -->
84 <div class="doc_section">
85   <a name="license">License</a>
86 </div>
87 <!-- *********************************************************************** -->
88
89 <div class="question">
90 <p>Why are the LLVM source code and the front-end distributed under different
91 licenses?</p>
92 </div>
93         
94 <div class="answer">
95 <p>The C/C++ front-ends are based on GCC and must be distributed under the GPL.
96 Our aim is to distribute LLVM source code under a <em>much less restrictive</em>
97 license, in particular one that does not compel users who distribute tools based
98 on modifying the source to redistribute the modified source code as well.</p>
99 </div>
100
101 <div class="question">
102 <p>Does the University of Illinois Open Source License really qualify as an
103 "open source" license?</p>
104 </div>
105
106 <div class="answer">
107 <p>Yes, the license is <a
108 href="http://www.opensource.org/licenses/UoI-NCSA.php">certified</a> by the Open
109 Source Initiative (OSI).</p>
110 </div>
111
112 <div class="question">
113 <p>Can I modify LLVM source code and redistribute the modified source?</p>
114 </div>
115
116 <div class="answer">
117 <p>Yes.  The modified source distribution must retain the copyright notice and
118 follow the three bulletted conditions listed in the <a
119 href="http://llvm.cs.uiuc.edu/releases/1.2/LICENSE.TXT">LLVM license</a>.</p>
120 </div>
121
122 <div class="question">
123 <p>Can I modify LLVM source code and redistribute binaries or other tools based
124 on it, without redistributing the source?</p>
125 </div>
126
127 <div class="answer">
128 <p>Yes, this is why we distribute LLVM under a less restrictive license than
129 GPL, as explained in the first question above.</p>
130 </div>
131
132 <!-- *********************************************************************** -->
133 <div class="doc_section">
134   <a name="source">Source Code</a>
135 </div>
136 <!-- *********************************************************************** -->
137
138 <div class="question">
139 <p>In what language is LLVM written?</p>
140 </div>
141
142 <div class="answer">
143 <p>All of the LLVM tools and libraries are written in C++ with extensive use of
144 the STL.</p>
145 </div>
146
147 <div class="question">
148 <p>How portable is the LLVM source code?</p>
149 </div>
150
151 <div class="answer">
152 <p>The LLVM source code should be portable to most modern UNIX-like operating
153 systems.  Most of the code is written in standard C++ with operating system
154 services abstracted to a support library.  The tools required to build and test
155 LLVM have been ported to a plethora of platforms.</p>
156
157 <p>Some porting problems may exist in the following areas:</p>
158
159 <ul>
160
161   <li>The GCC front end code is not as portable as the LLVM suite, so it may not
162   compile as well on unsupported platforms.</li>
163
164   <li>The Python test classes are more UNIX-centric than they should be, so
165   porting to non-UNIX like platforms (i.e. Windows, MacOS 9) will require some
166   effort.</li>
167
168   <li>The LLVM build system relies heavily on UNIX shell tools, like the Bourne
169   Shell and sed.  Porting to systems without these tools (MacOS 9, Plan 9) will
170   require more effort.</li>
171
172 </ul>
173
174 </div>
175
176 <!-- *********************************************************************** -->
177 <div class="doc_section">
178   <a name="build">Build Problems</a>
179 </div>
180 <!-- *********************************************************************** -->
181
182 <div class="question">
183 <p>When I run configure, it finds the wrong C compiler.</p>
184 </div>
185
186 <div class="answer">
187
188 <p>The <tt>configure</tt> script attempts to locate first <tt>gcc</tt> and then
189 <tt>cc</tt>, unless it finds compiler paths set in <tt>CC</tt> and <tt>CXX</tt>
190 for the C and C++ compiler, respectively.</p>
191
192 <p>If <tt>configure</tt> finds the wrong compiler, either adjust your
193 <tt>PATH</tt> environment variable or set <tt>CC</tt> and <tt>CXX</tt>
194 explicitly.</p>
195
196 </div>
197
198 <div class="question">
199 <p>I compile the code, and I get some error about <tt>/localhome</tt>.</p>
200 </div>
201
202 <div class="answer">
203
204 <p>There are several possible causes for this.  The first is that you didn't set
205 a pathname properly when using <tt>configure</tt>, and it defaulted to a
206 pathname that we use on our research machines.</p>
207
208 <p>Another possibility is that we hardcoded a path in our Makefiles.  If you see
209 this, please email the LLVM bug mailing list with the name of the offending
210 Makefile and a description of what is wrong with it.</p>
211
212 </div>
213
214 <div class="question">
215 <p>The <tt>configure</tt> script finds the right C compiler, but it uses the
216 LLVM linker from a previous build.  What do I do?</p>
217 </div>
218
219 <div class="answer">
220 <p>The <tt>configure</tt> script uses the <tt>PATH</tt> to find executables, so
221 if it's grabbing the wrong linker/assembler/etc, there are two ways to fix
222 it:</p>
223
224 <ol>
225                 
226   <li><p>Adjust your <tt>PATH</tt> environment variable so that the correct
227   program appears first in the <tt>PATH</tt>.  This may work, but may not be
228   convenient when you want them <i>first</i> in your path for other
229   work.</p></li>
230
231   <li><p>Run <tt>configure</tt> with an alternative <tt>PATH</tt> that is
232   correct. In a Borne compatible shell, the syntax would be:</p>
233                 
234       <p><tt>PATH=<the path without the bad program> ./configure ...</tt></p>
235
236       <p>This is still somewhat inconvenient, but it allows <tt>configure</tt>
237       to do its work without having to adjust your <tt>PATH</tt>
238       permanently.</p></li>
239         
240 </ol>
241
242 </div>
243
244 <div class="question">
245 <p>When creating a dynamic library, I get a strange GLIBC error.</p>
246 </div>
247
248 <div class="answer">
249 <p>Under some operating systems (i.e. Linux), libtool does not work correctly if
250 GCC was compiled with the --disable-shared option.  To work around this, install
251 your own version of GCC that has shared libraries enabled by default.</p>
252 </div>
253
254 <div class="question">
255 <p>I've updated my source tree from CVS, and now my build is trying to use a
256 file/directory that doesn't exist.</p>
257 </div>
258
259 <div class="answer">
260 <p>You need to re-run configure in your object directory.  When new Makefiles
261 are added to the source tree, they have to be copied over to the object tree in
262 order to be used by the build.</p>
263 </div>
264
265 <div class="question">
266 <p>I've modified a Makefile in my source tree, but my build tree keeps using the
267 old version.  What do I do?</p>
268 </div>
269
270 <div class="answer">
271
272 <p>If the Makefile already exists in your object tree, you
273 can just run the following command in the top level directory of your object
274 tree:</p>
275
276 <p><tt>./config.status &lt;relative path to Makefile&gt;</tt><p>
277
278 <p>If the Makefile is new, you will have to modify the configure script to copy
279 it over.</p>
280
281 </div>
282
283 <div class="question">
284 <p>I've upgraded to a new version of LLVM, and I get strange build errors.</p>
285 </div>
286
287 <div class="answer">
288
289 <p>Sometimes, changes to the LLVM source code alters how the build system works.
290 Changes in libtool, autoconf, or header file dependencies are especially prone
291 to this sort of problem.</p>
292
293 <p>The best thing to try is to remove the old files and re-build.  In most
294 cases, this takes care of the problem.  To do this, just type <tt>make
295 clean</tt> and then <tt>make</tt> in the directory that fails to build.</p>
296
297 </div>
298
299 <div class="question">
300 <p>I've built LLVM and am testing it, but the tests freeze.</p>
301 </div>
302
303 <div class="answer">
304
305 <p>This is most likely occurring because you built a profile or release
306 (optimized) build of LLVM and have not specified the same information on the
307 <tt>gmake</tt> command line.</p>
308
309 <p>For example, if you built LLVM with the command:</p>
310
311 <p><tt>gmake ENABLE_PROFILING=1</tt>
312
313 <p>...then you must run the tests with the following commands:</p>
314
315 <p><tt>cd llvm/test<br>gmake  ENABLE_PROFILING=1</tt></p>
316
317 </div>
318
319 <div class="question">
320 <p>Why do test results differ when I perform different types of builds?</p>
321 </div>
322
323 <div class="answer">
324
325 <p>The LLVM test suite is dependent upon several features of the LLVM tools and
326 libraries.</p>
327
328 <p>First, the debugging assertions in code are not enabled in optimized or
329 profiling builds.  Hence, tests that used to fail may pass.</p>
330         
331 <p>Second, some tests may rely upon debugging options or behavior that is only
332 available in the debug build.  These tests will fail in an optimized or profile
333 build.</p>
334
335 </div>
336
337 <div class="question">
338 <p>Compiling LLVM with GCC 3.3.2 fails, what should I do?</p>
339 </div>
340
341 <div class="answer">
342 <p>This is <a href="http://gcc.gnu.org/PR?13392">a bug in GCC</a>, and 
343    affects projects other than LLVM.  Try upgrading or downgrading your GCC.</p>
344 </div>
345
346 <div class="question">
347 <p>
348 When I use the test suite, all of the C Backend tests fail.  What is
349 wrong?
350 </p>
351 </div>
352
353 <div class="answer">
354 <p>
355 If you build LLVM and the C Backend tests fail in <tt>llvm/test/Programs</tt>,
356 then chances are good that the directory pointed to by the LLVM_LIB_SEARCH_PATH
357 environment variable does not contain the libcrtend.a library.
358 </p>
359
360 <p>
361 To fix it, verify that LLVM_LIB_SEARCH_PATH points to the correct directory
362 and that libcrtend.a is inside.  For pre-built LLVM GCC front ends, this
363 should be the absolute path to
364 <tt>cfrontend/&lt;<i>platform</i>&gt;/llvm-gcc/bytecode-libs</tt>.  If you've
365 built your own LLVM GCC front end, then ensure that you've built and installed
366 the libraries in <tt>llvm/runtime</tt> and have LLVM_LIB_SEARCH_PATH pointing
367 to the <tt>LLVMGCCDIR/bytecode-libs</tt> subdirectory.
368 </p>
369 </div>
370
371 <!-- *********************************************************************** -->
372 <div class="doc_section">
373   <a name="cfe">Using the GCC Front End</a>
374 </div>
375
376 <div class="question">
377 <p>
378 When I compile software that uses a configure script, the configure script
379 thinks my system has all of the header files and libraries it is testing for.
380 How do I get configure to work correctly?
381 </p>
382 </div>
383
384 <div class="answer">
385 <p>
386 The configure script is getting things wrong because the LLVM linker allows
387 symbols to be undefined at link time (so that they can be resolved during JIT
388 or translation to the C back end).  That is why configure thinks your system
389 "has everything."
390 </p>
391 <p>
392 To work around this, perform the following steps:
393 </p>
394
395 <ol>
396   <li>
397   Make sure the CC and CXX environment variables contains the full path to the
398   LLVM GCC front end.
399   </li>
400
401   <li>
402   Make sure that the regular C compiler is first in your PATH.
403   </li>
404
405   <li>
406   Add the string "-Wl,-native" to your CFLAGS environment variable.
407   </li>
408 </ol>
409
410 <p>
411 This will allow the gccld linker to create a native code executable instead of
412 a shell script that runs the JIT.  Creating native code requires standard
413 linkage, which in turn will allow the configure script to find out if code is
414 not linking on your system because the feature isn't available on your system.
415 </p>
416 </div>
417
418 <div class="question">
419 <p>
420 When I compile code using the LLVM GCC front end, it complains that it cannot
421 find libcrtend.a.
422 </p>
423 </div>
424
425 <div class="answer">
426 <p>
427 In order to find libcrtend.a, you must have the directory in which it lives in
428 your LLVM_LIB_SEARCH_PATH environment variable.  For the binary distribution of
429 the LLVM GCC front end, this will be the full path of the bytecode-libs
430 directory inside of the LLVM GCC distribution.
431 </p>
432 </div>
433
434
435 <!-- *********************************************************************** -->
436 <div class="doc_section">
437   <a name="cfe_code">Questions about code generated by the GCC front-end</a>
438 </div>
439
440 <div class="question"><p>
441 What is this <tt>__main()</tt> call that gets inserted into <tt>main()</tt>?
442 </p></div>
443
444 <div class="answer">
445 <p>
446 The <tt>__main</tt> call is inserted by the C/C++ compiler in order to guarantee
447 that static constructors and destructors are called when the program starts up
448 and shuts down.  In C, you can create static constructors and destructors by
449 using GCC extensions, and in C++ you can do so by creating a global variable
450 whose class has a ctor or dtor.
451 </p>
452
453 <p>
454 The actual implementation of <tt>__main</tt> lives in the
455 <tt>llvm/runtime/GCCLibraries/crtend/</tt> directory in the source-base, and is
456 linked in automatically when you link the program.
457 </p>
458 </div>
459
460 <!--=========================================================================-->
461
462 <div class="question"><p>
463 Where did all of my code go??
464 </p></div>
465
466 <div class="answer">
467 <p>
468 If you are using the LLVM demo page, you may often wonder what happened to all
469 of the code that you typed in.  Remember that the demo script is running the
470 code through the LLVM optimizers, so if your code doesn't actually do anything
471 useful, it might all be deleted.
472 </p>
473
474 <p>
475 To prevent this, make sure that the code is actually needed.  For example, if
476 you are computing some expression, return the value from the function instead of
477 leaving it in a local variable.  If you really want to constrain the optimizer,
478 you can read from and assign to <tt>volatile</tt> global variables.
479 </p>
480 </div>
481
482 <!--=========================================================================-->
483
484 <div class="question"><p>
485 What is this <tt>llvm.global_ctors</tt> and <tt>_GLOBAL__I__tmp_webcompile...</tt> stuff that happens when I #include &lt;iostream&gt;?
486 </p></div>
487
488 <div class="answer">
489 <p>
490 If you #include the &lt;iostream&gt; header into a C++ translation unit, the
491 file will probably use the <tt>std::cin</tt>/<tt>std::cout</tt>/... global
492 objects.  However, C++ does not guarantee an order of initialization between
493 static objects in different translation units, so if a static ctor/dtor in your
494 .cpp file used <tt>std::cout</tt>, for example, the object would not necessarily
495 be automatically initialized before your use.
496 </p>
497
498 <p>
499 To make <tt>std::cout</tt> and friends work correctly in these scenarios, the
500 STL that we use declares a static object that gets created in every translation
501 unit that includes &lt;iostream&gt;.  This object has a static constructor and
502 destructor that initializes and destroys the global iostream objects before they
503 could possibly be used in the file.  The code that you see in the .ll file
504 corresponds to the constructor and destructor registration code.
505 </p>
506
507 <p>
508 If you would like to make it easier to <b>understand</b> the LLVM code generated
509 by the compiler in the demo page, consider using printf instead of iostreams to
510 print values.
511 </p>
512 </div>
513
514
515      <li>
516
517
518 <!-- *********************************************************************** -->
519 <!-- *********************************************************************** -->
520
521 <hr>
522 <div class="doc_footer">
523   <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a>
524   <br>
525   Last modified: $Date$
526 </div>
527
528 </body>
529 </html>