1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
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 }
14 <div class="doc_title">
15 LLVM: Frequently Asked Questions
19 <li><a href="#license">License</a>
21 <li>Why are the LLVM source code and the front-end distributed under different
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>
30 <li><a href="#source">Source code</a>
32 <li>In what language is LLVM written?</li>
33 <li>How portable is the LLVM source code?</li>
36 <li><a href="#build">Build Problems</a>
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
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
54 <li>After CVS update, rebuilding gives the error "No rule to make
58 <li><a href="#cfe">Using the GCC Front End</a>
61 When I compile software that uses a configure script, the configure script
62 thinks my system has all of the header files and libraries it is testing
63 for. How do I get configure to work correctly?
67 When I compile code using the LLVM GCC front end, it complains that it
68 cannot find libcrtend.a.
73 <li><a href="#cfe_code">Questions about code generated by the GCC front-end</a>
75 <li><a href="#__main">What is this <tt>__main()</tt> call that gets inserted into
76 <tt>main()</tt>?</a></li>
77 <li><a href="#iosinit">What is this <tt>llvm.global_ctors</tt> and
78 <tt>_GLOBAL__I__tmp_webcompile...</tt> stuff that happens when I
79 #include <iostream>?</a></li>
80 <li><a href="#codedce">Where did all of my code go??</a></li>
81 <li><a href="#undef">What is this "<tt>undef</tt>" thing that shows up in my code?</a></li>
86 <div class="doc_author">
87 <p>Written by <a href="http://llvm.cs.uiuc.edu">The LLVM Team</a></p>
91 <!-- *********************************************************************** -->
92 <div class="doc_section">
93 <a name="license">License</a>
95 <!-- *********************************************************************** -->
97 <div class="question">
98 <p>Why are the LLVM source code and the front-end distributed under different
103 <p>The C/C++ front-ends are based on GCC and must be distributed under the GPL.
104 Our aim is to distribute LLVM source code under a <em>much less restrictive</em>
105 license, in particular one that does not compel users who distribute tools based
106 on modifying the source to redistribute the modified source code as well.</p>
109 <div class="question">
110 <p>Does the University of Illinois Open Source License really qualify as an
111 "open source" license?</p>
115 <p>Yes, the license is <a
116 href="http://www.opensource.org/licenses/UoI-NCSA.php">certified</a> by the Open
117 Source Initiative (OSI).</p>
120 <div class="question">
121 <p>Can I modify LLVM source code and redistribute the modified source?</p>
125 <p>Yes. The modified source distribution must retain the copyright notice and
126 follow the three bulletted conditions listed in the <a
127 href="http://llvm.cs.uiuc.edu/releases/1.3/LICENSE.TXT">LLVM license</a>.</p>
130 <div class="question">
131 <p>Can I modify LLVM source code and redistribute binaries or other tools based
132 on it, without redistributing the source?</p>
136 <p>Yes, this is why we distribute LLVM under a less restrictive license than
137 GPL, as explained in the first question above.</p>
140 <!-- *********************************************************************** -->
141 <div class="doc_section">
142 <a name="source">Source Code</a>
144 <!-- *********************************************************************** -->
146 <div class="question">
147 <p>In what language is LLVM written?</p>
151 <p>All of the LLVM tools and libraries are written in C++ with extensive use of
155 <div class="question">
156 <p>How portable is the LLVM source code?</p>
160 <p>The LLVM source code should be portable to most modern UNIX-like operating
161 systems. Most of the code is written in standard C++ with operating system
162 services abstracted to a support library. The tools required to build and test
163 LLVM have been ported to a plethora of platforms.</p>
165 <p>Some porting problems may exist in the following areas:</p>
169 <li>The GCC front end code is not as portable as the LLVM suite, so it may not
170 compile as well on unsupported platforms.</li>
172 <li>The LLVM build system relies heavily on UNIX shell tools, like the Bourne
173 Shell and sed. Porting to systems without these tools (MacOS 9, Plan 9) will
174 require more effort.</li>
180 <!-- *********************************************************************** -->
181 <div class="doc_section">
182 <a name="build">Build Problems</a>
184 <!-- *********************************************************************** -->
186 <div class="question">
187 <p>When I run configure, it finds the wrong C compiler.</p>
192 <p>The <tt>configure</tt> script attempts to locate first <tt>gcc</tt> and then
193 <tt>cc</tt>, unless it finds compiler paths set in <tt>CC</tt> and <tt>CXX</tt>
194 for the C and C++ compiler, respectively.</p>
196 <p>If <tt>configure</tt> finds the wrong compiler, either adjust your
197 <tt>PATH</tt> environment variable or set <tt>CC</tt> and <tt>CXX</tt>
202 <div class="question">
203 <p>I compile the code, and I get some error about <tt>/localhome</tt>.</p>
208 <p>There are several possible causes for this. The first is that you didn't set
209 a pathname properly when using <tt>configure</tt>, and it defaulted to a
210 pathname that we use on our research machines.</p>
212 <p>Another possibility is that we hardcoded a path in our Makefiles. If you see
213 this, please email the LLVM bug mailing list with the name of the offending
214 Makefile and a description of what is wrong with it.</p>
218 <div class="question">
219 <p>The <tt>configure</tt> script finds the right C compiler, but it uses the
220 LLVM linker from a previous build. What do I do?</p>
224 <p>The <tt>configure</tt> script uses the <tt>PATH</tt> to find executables, so
225 if it's grabbing the wrong linker/assembler/etc, there are two ways to fix
230 <li><p>Adjust your <tt>PATH</tt> environment variable so that the correct
231 program appears first in the <tt>PATH</tt>. This may work, but may not be
232 convenient when you want them <i>first</i> in your path for other
235 <li><p>Run <tt>configure</tt> with an alternative <tt>PATH</tt> that is
236 correct. In a Borne compatible shell, the syntax would be:</p>
238 <p><tt>PATH=[the path without the bad program] ./configure ...</tt></p>
240 <p>This is still somewhat inconvenient, but it allows <tt>configure</tt>
241 to do its work without having to adjust your <tt>PATH</tt>
242 permanently.</p></li>
248 <div class="question">
249 <p>When creating a dynamic library, I get a strange GLIBC error.</p>
253 <p>Under some operating systems (i.e. Linux), libtool does not work correctly if
254 GCC was compiled with the --disable-shared option. To work around this, install
255 your own version of GCC that has shared libraries enabled by default.</p>
258 <div class="question">
259 <p>I've updated my source tree from CVS, and now my build is trying to use a
260 file/directory that doesn't exist.</p>
264 <p>You need to re-run configure in your object directory. When new Makefiles
265 are added to the source tree, they have to be copied over to the object tree in
266 order to be used by the build.</p>
269 <div class="question">
270 <p>I've modified a Makefile in my source tree, but my build tree keeps using the
271 old version. What do I do?</p>
276 <p>If the Makefile already exists in your object tree, you
277 can just run the following command in the top level directory of your object
280 <p><tt>./config.status <relative path to Makefile></tt><p>
282 <p>If the Makefile is new, you will have to modify the configure script to copy
287 <div class="question">
288 <p>I've upgraded to a new version of LLVM, and I get strange build errors.</p>
293 <p>Sometimes, changes to the LLVM source code alters how the build system works.
294 Changes in libtool, autoconf, or header file dependencies are especially prone
295 to this sort of problem.</p>
297 <p>The best thing to try is to remove the old files and re-build. In most
298 cases, this takes care of the problem. To do this, just type <tt>make
299 clean</tt> and then <tt>make</tt> in the directory that fails to build.</p>
303 <div class="question">
304 <p>I've built LLVM and am testing it, but the tests freeze.</p>
309 <p>This is most likely occurring because you built a profile or release
310 (optimized) build of LLVM and have not specified the same information on the
311 <tt>gmake</tt> command line.</p>
313 <p>For example, if you built LLVM with the command:</p>
315 <p><tt>gmake ENABLE_PROFILING=1</tt>
317 <p>...then you must run the tests with the following commands:</p>
319 <p><tt>cd llvm/test<br>gmake ENABLE_PROFILING=1</tt></p>
323 <div class="question">
324 <p>Why do test results differ when I perform different types of builds?</p>
329 <p>The LLVM test suite is dependent upon several features of the LLVM tools and
332 <p>First, the debugging assertions in code are not enabled in optimized or
333 profiling builds. Hence, tests that used to fail may pass.</p>
335 <p>Second, some tests may rely upon debugging options or behavior that is only
336 available in the debug build. These tests will fail in an optimized or profile
341 <div class="question">
342 <p>Compiling LLVM with GCC 3.3.2 fails, what should I do?</p>
346 <p>This is <a href="http://gcc.gnu.org/PR?13392">a bug in GCC</a>, and
347 affects projects other than LLVM. Try upgrading or downgrading your GCC.</p>
350 <div class="question">
351 <p>After CVS update, rebuilding gives the error "No rule to make target".</p>
355 <p>If the error is of the form:</p>
357 <div class="doc_code">
359 gmake[2]: *** No rule to make target `/path/to/somefile', needed by
360 `/path/to/another/file.d'.<br>
365 <p>This may occur anytime files are moved within the CVS repository or removed
366 entirely. In this case, the best solution is to erase all <tt>.d</tt> files,
367 which list dependencies for source files, and rebuild:</p>
369 <div class="doc_code">
372 % rm -f `find . -name \*\.d`
377 <p>In other cases, it may be necessary to run <tt>make clean</tt> before
381 <!-- *********************************************************************** -->
382 <div class="doc_section">
383 <a name="cfe">Using the GCC Front End</a>
386 <div class="question">
388 When I compile software that uses a configure script, the configure script
389 thinks my system has all of the header files and libraries it is testing for.
390 How do I get configure to work correctly?
396 The configure script is getting things wrong because the LLVM linker allows
397 symbols to be undefined at link time (so that they can be resolved during JIT
398 or translation to the C back end). That is why configure thinks your system
402 To work around this, perform the following steps:
407 Make sure the CC and CXX environment variables contains the full path to the
412 Make sure that the regular C compiler is first in your PATH.
416 Add the string "-Wl,-native" to your CFLAGS environment variable.
421 This will allow the gccld linker to create a native code executable instead of
422 a shell script that runs the JIT. Creating native code requires standard
423 linkage, which in turn will allow the configure script to find out if code is
424 not linking on your system because the feature isn't available on your system.
428 <div class="question">
430 When I compile code using the LLVM GCC front end, it complains that it cannot
437 The only way this can happen is if you haven't installed the runtime library. To
438 correct this, do:</p>
441 % make clean ; make install-bytecode
446 <!-- *********************************************************************** -->
447 <div class="doc_section">
448 <a name="cfe_code">Questions about code generated by the GCC front-end</a>
451 <div class="question"><p>
452 <a name="__main"></a>
453 What is this <tt>__main()</tt> call that gets inserted into <tt>main()</tt>?
458 The <tt>__main</tt> call is inserted by the C/C++ compiler in order to guarantee
459 that static constructors and destructors are called when the program starts up
460 and shuts down. In C, you can create static constructors and destructors by
461 using GCC extensions, and in C++ you can do so by creating a global variable
462 whose class has a ctor or dtor.
466 The actual implementation of <tt>__main</tt> lives in the
467 <tt>llvm/runtime/GCCLibraries/crtend/</tt> directory in the source-base, and is
468 linked in automatically when you link the program.
472 <!--=========================================================================-->
474 <div class="question">
475 <a name="iosinit"></a>
476 <p> What is this <tt>llvm.global_ctors</tt> and
477 <tt>_GLOBAL__I__tmp_webcompile...</tt> stuff that happens when I #include
478 <iostream>?</p>
483 <p>If you #include the <iostream> header into a C++ translation unit, the
484 file will probably use the <tt>std::cin</tt>/<tt>std::cout</tt>/... global
485 objects. However, C++ does not guarantee an order of initialization between
486 static objects in different translation units, so if a static ctor/dtor in your
487 .cpp file used <tt>std::cout</tt>, for example, the object would not necessarily
488 be automatically initialized before your use.</p>
490 <p>To make <tt>std::cout</tt> and friends work correctly in these scenarios, the
491 STL that we use declares a static object that gets created in every translation
492 unit that includes <tt><iostream></tt>. This object has a static
493 constructor and destructor that initializes and destroys the global iostream
494 objects before they could possibly be used in the file. The code that you see
495 in the .ll file corresponds to the constructor and destructor registration code.
498 <p>If you would like to make it easier to <b>understand</b> the LLVM code
499 generated by the compiler in the demo page, consider using <tt>printf()</tt>
500 instead of <tt>iostream</tt>s to print values.</p>
504 <!--=========================================================================-->
506 <div class="question"><p>
507 <a name="codedce"></a>
508 Where did all of my code go??
513 If you are using the LLVM demo page, you may often wonder what happened to all
514 of the code that you typed in. Remember that the demo script is running the
515 code through the LLVM optimizers, so if your code doesn't actually do anything
516 useful, it might all be deleted.
520 To prevent this, make sure that the code is actually needed. For example, if
521 you are computing some expression, return the value from the function instead of
522 leaving it in a local variable. If you really want to constrain the optimizer,
523 you can read from and assign to <tt>volatile</tt> global variables.
527 <!--=========================================================================-->
529 <div class="question"><p>
531 <p>What is this "<tt>undef</tt>" thing that shows up in my code?
536 <a href="LangRef.html#undef"><tt>undef</tt></a> is the LLVM way of representing
537 a value that is not defined. You can get these if you do not initialize a
538 variable before you use it. For example, the C function:</p>
540 <div class="doc_code">
541 <tt>int X() { int i; return i; }</tt>
544 <p>Is compiled to "<tt>ret int undef</tt>" because "i" never has a value
549 <!-- *********************************************************************** -->
553 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
554 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
555 <a href="http://validator.w3.org/check/referer"><img
556 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a>
558 <a href="http://llvm.cs.uiuc.edu">LLVM Compiler Infrastructure</a><br>
559 Last modified: $Date$