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