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>The <tt>configure</tt> script finds the right C compiler, but it uses the
40 LLVM linker from a previous build. What do I do?</li>
41 <li>When creating a dynamic library, I get a strange GLIBC error.</li>
42 <li>I've updated my source tree from CVS, and now my build is trying to use a
43 file/directory that doesn't exist.</li>
44 <li>I've modified a Makefile in my source tree, but my build tree keeps using
45 the old version. What do I do?</li>
46 <li>I've upgraded to a new version of LLVM, and I get strange build
48 <li>I've built LLVM and am testing it, but the tests freeze.</li>
49 <li>Why do test results differ when I perform different types of builds?</li>
50 <li>Compiling LLVM with GCC 3.3.2 fails, what should I do?</li>
51 <li>When I use the test suite, all of the C Backend tests fail. What is
53 <li>After CVS update, rebuilding gives the error "No rule to make
57 <li><a href="#felangs">Source Languages</a>
59 <li><a href="#langs">What source languages are supported?</a></li>
60 <li><a href="#langhlsupp">What support is there for higher level source
61 language constructs for building a compiler?</a></li>
62 <li><a href="GetElementPtr.html">I don't understand the GetElementPtr
63 instruction. Help!</a></li>
66 <li><a href="#cfe">Using the GCC Front End</a>
69 When I compile software that uses a configure script, the configure script
70 thinks my system has all of the header files and libraries it is testing
71 for. How do I get configure to work correctly?
75 When I compile code using the LLVM GCC front end, it complains that it
76 cannot find libcrtend.a.
80 How can I disable all optimizations when compiling code using the LLVM GCC front end?
83 <li><a href="#translatec++">Can I use LLVM to convert C++ code to C code?</a></li>
88 <li><a href="#cfe_code">Questions about code generated by the GCC front-end</a>
90 <li><a href="#__main">What is this <tt>__main()</tt> call that gets inserted into
91 <tt>main()</tt>?</a></li>
92 <li><a href="#iosinit">What is this <tt>llvm.global_ctors</tt> and
93 <tt>_GLOBAL__I__tmp_webcompile...</tt> stuff that happens when I
94 #include <iostream>?</a></li>
95 <li><a href="#codedce">Where did all of my code go??</a></li>
96 <li><a href="#undef">What is this "<tt>undef</tt>" thing that shows up in my code?</a></li>
101 <div class="doc_author">
102 <p>Written by <a href="http://llvm.org">The LLVM Team</a></p>
106 <!-- *********************************************************************** -->
107 <div class="doc_section">
108 <a name="license">License</a>
110 <!-- *********************************************************************** -->
112 <div class="question">
113 <p>Why are the LLVM source code and the front-end distributed under different
118 <p>The C/C++ front-ends are based on GCC and must be distributed under the GPL.
119 Our aim is to distribute LLVM source code under a <em>much less restrictive</em>
120 license, in particular one that does not compel users who distribute tools based
121 on modifying the source to redistribute the modified source code as well.</p>
124 <div class="question">
125 <p>Does the University of Illinois Open Source License really qualify as an
126 "open source" license?</p>
130 <p>Yes, the license is <a
131 href="http://www.opensource.org/licenses/UoI-NCSA.php">certified</a> by the Open
132 Source Initiative (OSI).</p>
135 <div class="question">
136 <p>Can I modify LLVM source code and redistribute the modified source?</p>
140 <p>Yes. The modified source distribution must retain the copyright notice and
141 follow the three bulletted conditions listed in the <a
142 href="http://llvm.org/releases/1.3/LICENSE.TXT">LLVM license</a>.</p>
145 <div class="question">
146 <p>Can I modify LLVM source code and redistribute binaries or other tools based
147 on it, without redistributing the source?</p>
151 <p>Yes, this is why we distribute LLVM under a less restrictive license than
152 GPL, as explained in the first question above.</p>
155 <!-- *********************************************************************** -->
156 <div class="doc_section">
157 <a name="source">Source Code</a>
159 <!-- *********************************************************************** -->
161 <div class="question">
162 <p>In what language is LLVM written?</p>
166 <p>All of the LLVM tools and libraries are written in C++ with extensive use of
170 <div class="question">
171 <p>How portable is the LLVM source code?</p>
175 <p>The LLVM source code should be portable to most modern UNIX-like operating
176 systems. Most of the code is written in standard C++ with operating system
177 services abstracted to a support library. The tools required to build and test
178 LLVM have been ported to a plethora of platforms.</p>
180 <p>Some porting problems may exist in the following areas:</p>
184 <li>The GCC front end code is not as portable as the LLVM suite, so it may not
185 compile as well on unsupported platforms.</li>
187 <li>The LLVM build system relies heavily on UNIX shell tools, like the Bourne
188 Shell and sed. Porting to systems without these tools (MacOS 9, Plan 9) will
189 require more effort.</li>
195 <!-- *********************************************************************** -->
196 <div class="doc_section">
197 <a name="build">Build Problems</a>
199 <!-- *********************************************************************** -->
201 <div class="question">
202 <p>When I run configure, it finds the wrong C compiler.</p>
207 <p>The <tt>configure</tt> script attempts to locate first <tt>gcc</tt> and then
208 <tt>cc</tt>, unless it finds compiler paths set in <tt>CC</tt> and <tt>CXX</tt>
209 for the C and C++ compiler, respectively.</p>
211 <p>If <tt>configure</tt> finds the wrong compiler, either adjust your
212 <tt>PATH</tt> environment variable or set <tt>CC</tt> and <tt>CXX</tt>
217 <div class="question">
218 <p>The <tt>configure</tt> script finds the right C compiler, but it uses the
219 LLVM linker from a previous build. What do I do?</p>
223 <p>The <tt>configure</tt> script uses the <tt>PATH</tt> to find executables, so
224 if it's grabbing the wrong linker/assembler/etc, there are two ways to fix
229 <li><p>Adjust your <tt>PATH</tt> environment variable so that the correct
230 program appears first in the <tt>PATH</tt>. This may work, but may not be
231 convenient when you want them <i>first</i> in your path for other
234 <li><p>Run <tt>configure</tt> with an alternative <tt>PATH</tt> that is
235 correct. In a Borne compatible shell, the syntax would be:</p>
237 <p><tt>PATH=[the path without the bad program] ./configure ...</tt></p>
239 <p>This is still somewhat inconvenient, but it allows <tt>configure</tt>
240 to do its work without having to adjust your <tt>PATH</tt>
241 permanently.</p></li>
247 <div class="question">
248 <p>When creating a dynamic library, I get a strange GLIBC error.</p>
252 <p>Under some operating systems (i.e. Linux), libtool does not work correctly if
253 GCC was compiled with the --disable-shared option. To work around this, install
254 your own version of GCC that has shared libraries enabled by default.</p>
257 <div class="question">
258 <p>I've updated my source tree from CVS, and now my build is trying to use a
259 file/directory that doesn't exist.</p>
263 <p>You need to re-run configure in your object directory. When new Makefiles
264 are added to the source tree, they have to be copied over to the object tree in
265 order to be used by the build.</p>
268 <div class="question">
269 <p>I've modified a Makefile in my source tree, but my build tree keeps using the
270 old version. What do I do?</p>
275 <p>If the Makefile already exists in your object tree, you
276 can just run the following command in the top level directory of your object
279 <p><tt>./config.status <relative path to Makefile></tt><p>
281 <p>If the Makefile is new, you will have to modify the configure script to copy
286 <div class="question">
287 <p>I've upgraded to a new version of LLVM, and I get strange build errors.</p>
292 <p>Sometimes, changes to the LLVM source code alters how the build system works.
293 Changes in libtool, autoconf, or header file dependencies are especially prone
294 to this sort of problem.</p>
296 <p>The best thing to try is to remove the old files and re-build. In most
297 cases, this takes care of the problem. To do this, just type <tt>make
298 clean</tt> and then <tt>make</tt> in the directory that fails to build.</p>
302 <div class="question">
303 <p>I've built LLVM and am testing it, but the tests freeze.</p>
308 <p>This is most likely occurring because you built a profile or release
309 (optimized) build of LLVM and have not specified the same information on the
310 <tt>gmake</tt> command line.</p>
312 <p>For example, if you built LLVM with the command:</p>
314 <div class="doc_code">
316 % gmake ENABLE_PROFILING=1
320 <p>...then you must run the tests with the following commands:</p>
322 <div class="doc_code">
325 % gmake ENABLE_PROFILING=1
331 <div class="question">
332 <p>Why do test results differ when I perform different types of builds?</p>
337 <p>The LLVM test suite is dependent upon several features of the LLVM tools and
340 <p>First, the debugging assertions in code are not enabled in optimized or
341 profiling builds. Hence, tests that used to fail may pass.</p>
343 <p>Second, some tests may rely upon debugging options or behavior that is only
344 available in the debug build. These tests will fail in an optimized or profile
349 <div class="question">
350 <p>Compiling LLVM with GCC 3.3.2 fails, what should I do?</p>
354 <p>This is <a href="http://gcc.gnu.org/PR?13392">a bug in GCC</a>, and
355 affects projects other than LLVM. Try upgrading or downgrading your GCC.</p>
358 <div class="question">
359 <p>After CVS update, rebuilding gives the error "No rule to make target".</p>
363 <p>If the error is of the form:</p>
365 <div class="doc_code">
367 gmake[2]: *** No rule to make target `/path/to/somefile', needed by
368 `/path/to/another/file.d'.<br>
373 <p>This may occur anytime files are moved within the CVS repository or removed
374 entirely. In this case, the best solution is to erase all <tt>.d</tt> files,
375 which list dependencies for source files, and rebuild:</p>
377 <div class="doc_code">
380 % rm -f `find . -name \*\.d`
385 <p>In other cases, it may be necessary to run <tt>make clean</tt> before
389 <!-- *********************************************************************** -->
390 <div class="doc_section"><a name="felangs">Source Languages</a></div>
392 <div class="question"><p>
393 <a name="langs">What source languages are supported?</a></p>
396 <p>LLVM currently has full support for C and C++ source languages. These are
397 available through a special version of GCC that LLVM calls the
398 <a href="#cfe">C Front End</a></p>
399 <p>There is an incomplete version of a Java front end available in the
400 <tt>llvm-java</tt> CVS repository. There is no documentation on this yet so
401 you'll need to download the code, compile it, and try it.</p>
402 <p>In the <tt>examples/BFtoLLVM</tt> directory is a translator for the
403 BrainF*** language (2002 Language Specification).</p>
404 <p>In the <tt>projects/Stacker</tt> directory is a compiler and runtime
405 library for the Stacker language, a "toy" language loosely based on Forth.</p>
406 <p>The PyPy developers are working on integrating LLVM into the PyPy backend
407 so that PyPy language can translate to LLVM.</p>
409 <div class="question"><a name="langhlsupp">
410 <p>What support is there for a higher level source language constructs for
411 building a compiler?</a></p>
414 <p>Currently, there isn't much. LLVM supports an intermediate representation
415 which is useful for code representation but will not support the high level
416 (abstract syntax tree) representation needed by most compilers. There are no
417 facilities for lexical nor semantic analysis. There is, however, a <i>mostly
418 implemented</i> configuration-driven
419 <a href="CompilerDriver.html">compiler driver</a> which simplifies the task
420 of running optimizations, linking, and executable generation.</p>
423 <div class="question"><a name="langhlsupp">
424 <p>I don't understand the GetElementPtr
425 instruction. Help!</a></p>
428 <p>See <a href="GetElementPtr.html">The Often Misunderstood GEP
429 Instruction</a>.</li>
432 <!-- *********************************************************************** -->
433 <div class="doc_section">
434 <a name="cfe">Using the GCC Front End</a>
437 <div class="question">
439 When I compile software that uses a configure script, the configure script
440 thinks my system has all of the header files and libraries it is testing for.
441 How do I get configure to work correctly?
447 The configure script is getting things wrong because the LLVM linker allows
448 symbols to be undefined at link time (so that they can be resolved during JIT
449 or translation to the C back end). That is why configure thinks your system
453 To work around this, perform the following steps:
456 <li>Make sure the CC and CXX environment variables contains the full path to
457 the LLVM GCC front end.</li>
459 <li>Make sure that the regular C compiler is first in your PATH. </li>
461 <li>Add the string "-Wl,-native" to your CFLAGS environment variable.</li>
465 This will allow the <tt>llvm-ld</tt> linker to create a native code executable
466 instead of shell script that runs the JIT. Creating native code requires
467 standard linkage, which in turn will allow the configure script to find out if
468 code is not linking on your system because the feature isn't available on your
472 <div class="question">
474 When I compile code using the LLVM GCC front end, it complains that it cannot
481 The only way this can happen is if you haven't installed the runtime library. To
482 correct this, do:</p>
484 <div class="doc_code">
487 % make clean ; make install-bytecode
492 <div class="question">
494 How can I disable all optimizations when compiling code using the LLVM GCC front end?
500 Passing "-Wa,-disable-opt -Wl,-disable-opt" will disable *all* cleanup and
501 optimizations done at the llvm level, leaving you with the truly horrible
502 code that you desire.
507 <div class="question">
509 <a name="translatec++">Can I use LLVM to convert C++ code to C code?</a>
514 <p>Yes, you can use LLVM to convert code from any language LLVM supports to C.
515 Note that the generated C code will be very low level (all loops are lowered
516 to gotos, etc) and not very pretty (comments are stripped, original source
517 formatting is totally lost, variables are renamed, expressions are regrouped),
518 so this may not be what you're looking for. However, this is a good way to add
519 C++ support for a processor that does not otherwise have a C++ compiler.
522 <p>Use commands like this:</p>
525 <li><p>Compile your program as normal with llvm-g++:</p></li>
527 <div class="doc_code">
529 % llvm-g++ x.cpp -o program
535 <div class="doc_code">
539 % llvm-g++ a.o b.o -o program
543 <p>With llvm-gcc3, this will generate program and program.bc. The .bc file is
544 the LLVM version of the program all linked together.</p>
546 <li><p>Convert the LLVM code to C code, using the LLC tool with the C
549 <div class="doc_code">
551 % llc -march=c program.bc -o program.c
555 <li><p>Finally, compile the c file:</p></li>
557 <div class="doc_code">
565 <p>Note that, by default, the C backend does not support exception handling.
566 If you want/need it for a certain program, you can enable it by passing
567 "-enable-correct-eh-support" to the llc program. The resultant code will
568 use setjmp/longjmp to implement exception support that is correct but
572 <p>Also note: this specific sequence of commands won't work if you use a
573 function defined in the C++ runtime library (or any other C++ library). To
574 access an external C++ library, you must manually
575 compile libstdc++ to LLVM bytecode, statically link it into your program, then
576 use the commands above to convert the whole result into C code. Alternatively,
577 you can compile the libraries and your application into two different chunks
578 of C code and link them.</p>
584 <!-- *********************************************************************** -->
585 <div class="doc_section">
586 <a name="cfe_code">Questions about code generated by the GCC front-end</a>
589 <div class="question"><p>
590 <a name="__main"></a>
591 What is this <tt>__main()</tt> call that gets inserted into <tt>main()</tt>?
596 The <tt>__main</tt> call is inserted by the C/C++ compiler in order to guarantee
597 that static constructors and destructors are called when the program starts up
598 and shuts down. In C, you can create static constructors and destructors by
599 using GCC extensions, and in C++ you can do so by creating a global variable
600 whose class has a ctor or dtor.
604 The actual implementation of <tt>__main</tt> lives in the
605 <tt>llvm/runtime/GCCLibraries/crtend/</tt> directory in the source-base, and is
606 linked in automatically when you link the program.
610 <!--=========================================================================-->
612 <div class="question">
613 <a name="iosinit"></a>
614 <p> What is this <tt>llvm.global_ctors</tt> and
615 <tt>_GLOBAL__I__tmp_webcompile...</tt> stuff that happens when I #include
616 <iostream>?</p>
621 <p>If you #include the <iostream> header into a C++ translation unit, the
622 file will probably use the <tt>std::cin</tt>/<tt>std::cout</tt>/... global
623 objects. However, C++ does not guarantee an order of initialization between
624 static objects in different translation units, so if a static ctor/dtor in your
625 .cpp file used <tt>std::cout</tt>, for example, the object would not necessarily
626 be automatically initialized before your use.</p>
628 <p>To make <tt>std::cout</tt> and friends work correctly in these scenarios, the
629 STL that we use declares a static object that gets created in every translation
630 unit that includes <tt><iostream></tt>. This object has a static
631 constructor and destructor that initializes and destroys the global iostream
632 objects before they could possibly be used in the file. The code that you see
633 in the .ll file corresponds to the constructor and destructor registration code.
636 <p>If you would like to make it easier to <b>understand</b> the LLVM code
637 generated by the compiler in the demo page, consider using <tt>printf()</tt>
638 instead of <tt>iostream</tt>s to print values.</p>
642 <!--=========================================================================-->
644 <div class="question"><p>
645 <a name="codedce"></a>
646 Where did all of my code go??
651 If you are using the LLVM demo page, you may often wonder what happened to all
652 of the code that you typed in. Remember that the demo script is running the
653 code through the LLVM optimizers, so if your code doesn't actually do anything
654 useful, it might all be deleted.
658 To prevent this, make sure that the code is actually needed. For example, if
659 you are computing some expression, return the value from the function instead of
660 leaving it in a local variable. If you really want to constrain the optimizer,
661 you can read from and assign to <tt>volatile</tt> global variables.
665 <!--=========================================================================-->
667 <div class="question"><p>
669 <p>What is this "<tt>undef</tt>" thing that shows up in my code?
674 <a href="LangRef.html#undef"><tt>undef</tt></a> is the LLVM way of representing
675 a value that is not defined. You can get these if you do not initialize a
676 variable before you use it. For example, the C function:</p>
678 <div class="doc_code">
680 int X() { int i; return i; }
684 <p>Is compiled to "<tt>ret i32 undef</tt>" because "<tt>i</tt>" never has
685 a value specified for it.</p>
688 <!-- *********************************************************************** -->
692 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
693 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
694 <a href="http://validator.w3.org/check/referer"><img
695 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a>
697 <a href="http://llvm.org">LLVM Compiler Infrastructure</a><br>
698 Last modified: $Date$