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 Subversion, and now my build is trying
43 to use a 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>Compiling LLVM with GCC succeeds, but the resulting tools do not work, what can be wrong?</li>
52 <li>When I use the test suite, all of the C Backend tests fail. What is
54 <li>After Subversion update, rebuilding gives the error "No rule to make
56 <li><a href="#llvmc">The <tt>llvmc</tt> program gives me errors/doesn't
60 <li><a href="#felangs">Source Languages</a>
62 <li><a href="#langs">What source languages are supported?</a></li>
63 <li><a href="#langirgen">I'd like to write a self-hosting LLVM compiler. How
64 should I interface with the LLVM middle-end optimizers and back-end code
66 <li><a href="#langhlsupp">What support is there for higher level source
67 language constructs for building a compiler?</a></li>
68 <li><a href="GetElementPtr.html">I don't understand the GetElementPtr
69 instruction. Help!</a></li>
72 <li><a href="#cfe">Using the GCC Front End</a>
75 When I compile software that uses a configure script, the configure script
76 thinks my system has all of the header files and libraries it is testing
77 for. How do I get configure to work correctly?
81 When I compile code using the LLVM GCC front end, it complains that it
82 cannot find libcrtend.a.
86 How can I disable all optimizations when compiling code using the LLVM GCC front end?
89 <li><a href="#translatecxx">Can I use LLVM to convert C++ code to C code?</a></li>
91 <li><a href="#platformindependent">Can I compile C or C++ code to platform-independent LLVM bitcode?</a></li>
96 <li><a href="#cfe_code">Questions about code generated by the GCC front-end</a>
98 <li><a href="#iosinit">What is this <tt>llvm.global_ctors</tt> and
99 <tt>_GLOBAL__I__tmp_webcompile...</tt> stuff that happens when I
100 #include <iostream>?</a></li>
101 <li><a href="#codedce">Where did all of my code go??</a></li>
102 <li><a href="#undef">What is this "<tt>undef</tt>" thing that shows up in my code?</a></li>
107 <div class="doc_author">
108 <p>Written by <a href="http://llvm.org">The LLVM Team</a></p>
112 <!-- *********************************************************************** -->
113 <div class="doc_section">
114 <a name="license">License</a>
116 <!-- *********************************************************************** -->
118 <div class="question">
119 <p>Why are the LLVM source code and the front-end distributed under different
124 <p>The C/C++ front-ends are based on GCC and must be distributed under the GPL.
125 Our aim is to distribute LLVM source code under a <em>much less restrictive</em>
126 license, in particular one that does not compel users who distribute tools based
127 on modifying the source to redistribute the modified source code as well.</p>
130 <div class="question">
131 <p>Does the University of Illinois Open Source License really qualify as an
132 "open source" license?</p>
136 <p>Yes, the license is <a
137 href="http://www.opensource.org/licenses/UoI-NCSA.php">certified</a> by the Open
138 Source Initiative (OSI).</p>
141 <div class="question">
142 <p>Can I modify LLVM source code and redistribute the modified source?</p>
146 <p>Yes. The modified source distribution must retain the copyright notice and
147 follow the three bulletted conditions listed in the <a
148 href="http://llvm.org/svn/llvm-project/llvm/trunk/LICENSE.TXT">LLVM license</a>.</p>
151 <div class="question">
152 <p>Can I modify LLVM source code and redistribute binaries or other tools based
153 on it, without redistributing the source?</p>
157 <p>Yes, this is why we distribute LLVM under a less restrictive license than
158 GPL, as explained in the first question above.</p>
161 <!-- *********************************************************************** -->
162 <div class="doc_section">
163 <a name="source">Source Code</a>
165 <!-- *********************************************************************** -->
167 <div class="question">
168 <p>In what language is LLVM written?</p>
172 <p>All of the LLVM tools and libraries are written in C++ with extensive use of
176 <div class="question">
177 <p>How portable is the LLVM source code?</p>
181 <p>The LLVM source code should be portable to most modern UNIX-like operating
182 systems. Most of the code is written in standard C++ with operating system
183 services abstracted to a support library. The tools required to build and test
184 LLVM have been ported to a plethora of platforms.</p>
186 <p>Some porting problems may exist in the following areas:</p>
189 <li>The GCC front end code is not as portable as the LLVM suite, so it may not
190 compile as well on unsupported platforms.</li>
192 <li>The LLVM build system relies heavily on UNIX shell tools, like the Bourne
193 Shell and sed. Porting to systems without these tools (MacOS 9, Plan 9)
194 will require more effort.</li>
199 <!-- *********************************************************************** -->
200 <div class="doc_section">
201 <a name="build">Build Problems</a>
203 <!-- *********************************************************************** -->
205 <div class="question">
206 <p>When I run configure, it finds the wrong C compiler.</p>
211 <p>The <tt>configure</tt> script attempts to locate first <tt>gcc</tt> and then
212 <tt>cc</tt>, unless it finds compiler paths set in <tt>CC</tt> and <tt>CXX</tt>
213 for the C and C++ compiler, respectively.</p>
215 <p>If <tt>configure</tt> finds the wrong compiler, either adjust your
216 <tt>PATH</tt> environment variable or set <tt>CC</tt> and <tt>CXX</tt>
221 <div class="question">
222 <p>The <tt>configure</tt> script finds the right C compiler, but it uses the
223 LLVM linker from a previous build. What do I do?</p>
227 <p>The <tt>configure</tt> script uses the <tt>PATH</tt> to find executables, so
228 if it's grabbing the wrong linker/assembler/etc, there are two ways to fix
232 <li><p>Adjust your <tt>PATH</tt> environment variable so that the correct
233 program appears first in the <tt>PATH</tt>. This may work, but may not be
234 convenient when you want them <i>first</i> in your path for other
237 <li><p>Run <tt>configure</tt> with an alternative <tt>PATH</tt> that is
238 correct. In a Borne compatible shell, the syntax would be:</p>
240 <pre class="doc_code">
241 % PATH=[the path without the bad program] ./configure ...
244 <p>This is still somewhat inconvenient, but it allows <tt>configure</tt>
245 to do its work without having to adjust your <tt>PATH</tt>
246 permanently.</p></li>
251 <div class="question">
252 <p>When creating a dynamic library, I get a strange GLIBC error.</p>
256 <p>Under some operating systems (i.e. Linux), libtool does not work correctly if
257 GCC was compiled with the --disable-shared option. To work around this, install
258 your own version of GCC that has shared libraries enabled by default.</p>
261 <div class="question">
262 <p>I've updated my source tree from Subversion, and now my build is trying to
263 use a file/directory that doesn't exist.</p>
267 <p>You need to re-run configure in your object directory. When new Makefiles
268 are added to the source tree, they have to be copied over to the object tree in
269 order to be used by the build.</p>
272 <div class="question">
273 <p>I've modified a Makefile in my source tree, but my build tree keeps using the
274 old version. What do I do?</p>
278 <p>If the Makefile already exists in your object tree, you
279 can just run the following command in the top level directory of your object
282 <pre class="doc_code">
283 % ./config.status <relative path to Makefile>
286 <p>If the Makefile is new, you will have to modify the configure script to copy
291 <div class="question">
292 <p>I've upgraded to a new version of LLVM, and I get strange build errors.</p>
297 <p>Sometimes, changes to the LLVM source code alters how the build system works.
298 Changes in libtool, autoconf, or header file dependencies are especially prone
299 to this sort of problem.</p>
301 <p>The best thing to try is to remove the old files and re-build. In most
302 cases, this takes care of the problem. To do this, just type <tt>make
303 clean</tt> and then <tt>make</tt> in the directory that fails to build.</p>
307 <div class="question">
308 <p>I've built LLVM and am testing it, but the tests freeze.</p>
313 <p>This is most likely occurring because you built a profile or release
314 (optimized) build of LLVM and have not specified the same information on the
315 <tt>gmake</tt> command line.</p>
317 <p>For example, if you built LLVM with the command:</p>
319 <pre class="doc_code">
320 % gmake ENABLE_PROFILING=1
323 <p>...then you must run the tests with the following commands:</p>
325 <pre class="doc_code">
327 % gmake ENABLE_PROFILING=1
332 <div class="question">
333 <p>Why do test results differ when I perform different types of builds?</p>
338 <p>The LLVM test suite is dependent upon several features of the LLVM tools and
341 <p>First, the debugging assertions in code are not enabled in optimized or
342 profiling builds. Hence, tests that used to fail may pass.</p>
344 <p>Second, some tests may rely upon debugging options or behavior that is only
345 available in the debug build. These tests will fail in an optimized or profile
350 <div class="question">
351 <p>Compiling LLVM with GCC 3.3.2 fails, what should I do?</p>
355 <p>This is <a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13392">a bug in GCC</a>, and
356 affects projects other than LLVM. Try upgrading or downgrading your GCC.</p>
359 <div class="question">
360 <p>Compiling LLVM with GCC succeeds, but the resulting tools do not work, what can be wrong?</p>
364 <p>Several versions of GCC have shown a weakness in miscompiling the LLVM codebase. Please
365 consult your compiler version (<tt>gcc --version</tt>) to find out whether it is
366 <a href="GettingStarted.html#brokengcc">broken</a>. If so, your only option is to upgrade
367 GCC to a known good version.</p>
370 <div class="question">
371 <p>After Subversion update, rebuilding gives the error "No rule to make
376 <p>If the error is of the form:</p>
378 <pre class="doc_code">
379 gmake[2]: *** No rule to make target `/path/to/somefile', needed by
380 `/path/to/another/file.d'.<br>
384 <p>This may occur anytime files are moved within the Subversion repository or
385 removed entirely. In this case, the best solution is to erase all
386 <tt>.d</tt> files, which list dependencies for source files, and rebuild:</p>
388 <pre class="doc_code">
390 % rm -f `find . -name \*\.d`
394 <p>In other cases, it may be necessary to run <tt>make clean</tt> before
398 <div class="question"><p><a name="llvmc">
399 The <tt>llvmc</tt> program gives me errors/doesn't work.</a></p>
403 <p><tt>llvmc</tt> is experimental and isn't really supported. We suggest
404 using <tt>llvm-gcc</tt> instead.</p>
407 <!-- *********************************************************************** -->
408 <div class="doc_section"><a name="felangs">Source Languages</a></div>
410 <div class="question"><p>
411 <a name="langs">What source languages are supported?</a></p>
414 <p>LLVM currently has full support for C and C++ source languages. These are
415 available through a special version of GCC that LLVM calls the
416 <a href="#cfe">C Front End</a></p>
417 <p>There is an incomplete version of a Java front end available in the
418 <tt>java</tt> module. There is no documentation on this yet so
419 you'll need to download the code, compile it, and try it.</p>
420 <p>The PyPy developers are working on integrating LLVM into the PyPy backend
421 so that PyPy language can translate to LLVM.</p>
424 <div class="question"><p><a name="langirgen">
425 I'd like to write a self-hosting LLVM compiler. How should I interface with
426 the LLVM middle-end optimizers and back-end code generators?
429 <p>Your compiler front-end will communicate with LLVM by creating a module in
430 the LLVM intermediate representation (IR) format. Assuming you want to
431 write your language's compiler in the language itself (rather than C++),
432 there are 3 major ways to tackle generating LLVM IR from a front-end:</p>
435 <strong>Call into the LLVM libraries code using your language's FFI
436 (foreign function interface).</strong>
438 <li><em>for:</em> best tracks changes to the LLVM IR, .ll syntax,
440 <li><em>for:</em> enables running LLVM optimization passes without a
441 emit/parse overhead</li>
442 <li><em>for:</em> adapts well to a JIT context</li>
443 <li><em>against:</em> lots of ugly glue code to write</li>
447 <strong>Emit LLVM assembly from your compiler's native language.</strong>
449 <li><em>for:</em> very straightforward to get started</li>
450 <li><em>against:</em> the .ll parser is slower than the bitcode reader
451 when interfacing to the middle end</li>
452 <li><em>against:</em> you'll have to re-engineer the LLVM IR object
453 model and asm writer in your language</li>
454 <li><em>against:</em> it may be harder to track changes to the IR</li>
458 <strong>Emit LLVM bitcode from your compiler's native language.</strong>
460 <li><em>for:</em> can use the more-efficient bitcode reader when
461 interfacing to the middle end</li>
462 <li><em>against:</em> you'll have to re-engineer the LLVM IR object
463 model and bitcode writer in your language</li>
464 <li><em>against:</em> it may be harder to track changes to the IR</li>
468 <p>If you go with the first option, the C bindings in include/llvm-c should
469 help a lot, since most languages have strong support for interfacing with
470 C. The most common hurdle with calling C from managed code is interfacing
471 with the garbage collector. The C interface was designed to require very
472 little memory management, and so is straightforward in this regard.</p>
475 <div class="question"><p><a name="langhlsupp">
476 What support is there for a higher level source language constructs for
477 building a compiler?</a></p>
480 <p>Currently, there isn't much. LLVM supports an intermediate representation
481 which is useful for code representation but will not support the high level
482 (abstract syntax tree) representation needed by most compilers. There are no
483 facilities for lexical nor semantic analysis. There is, however, a <i>mostly
484 implemented</i> configuration-driven
485 <a href="CompilerDriver.html">compiler driver</a> which simplifies the task
486 of running optimizations, linking, and executable generation.</p>
489 <div class="question"><p><a name="getelementptr">
490 I don't understand the GetElementPtr instruction. Help!</a></p>
493 <p>See <a href="GetElementPtr.html">The Often Misunderstood GEP
497 <!-- *********************************************************************** -->
498 <div class="doc_section">
499 <a name="cfe">Using the GCC Front End</a>
502 <div class="question">
504 When I compile software that uses a configure script, the configure script
505 thinks my system has all of the header files and libraries it is testing for.
506 How do I get configure to work correctly?
512 The configure script is getting things wrong because the LLVM linker allows
513 symbols to be undefined at link time (so that they can be resolved during JIT
514 or translation to the C back end). That is why configure thinks your system
518 To work around this, perform the following steps:
521 <li>Make sure the CC and CXX environment variables contains the full path to
522 the LLVM GCC front end.</li>
524 <li>Make sure that the regular C compiler is first in your PATH. </li>
526 <li>Add the string "-Wl,-native" to your CFLAGS environment variable.</li>
530 This will allow the <tt>llvm-ld</tt> linker to create a native code executable
531 instead of shell script that runs the JIT. Creating native code requires
532 standard linkage, which in turn will allow the configure script to find out if
533 code is not linking on your system because the feature isn't available on your
537 <div class="question">
539 When I compile code using the LLVM GCC front end, it complains that it cannot
546 The only way this can happen is if you haven't installed the runtime library. To
547 correct this, do:</p>
549 <pre class="doc_code">
551 % make clean ; make install-bytecode
555 <div class="question">
557 How can I disable all optimizations when compiling code using the LLVM GCC front end?
563 Passing "-Wa,-disable-opt -Wl,-disable-opt" will disable *all* cleanup and
564 optimizations done at the llvm level, leaving you with the truly horrible
565 code that you desire.
570 <div class="question">
572 <a name="translatecxx">Can I use LLVM to convert C++ code to C code?</a>
577 <p>Yes, you can use LLVM to convert code from any language LLVM supports to C.
578 Note that the generated C code will be very low level (all loops are lowered
579 to gotos, etc) and not very pretty (comments are stripped, original source
580 formatting is totally lost, variables are renamed, expressions are regrouped),
581 so this may not be what you're looking for. Also, there are several
582 limitations noted below.<p>
584 <p>Use commands like this:</p>
587 <li><p>Compile your program as normal with llvm-g++:</p>
589 <pre class="doc_code">
590 % llvm-g++ x.cpp -o program
595 <pre class="doc_code">
598 % llvm-g++ a.o b.o -o program
601 <p>With llvm-gcc3, this will generate program and program.bc. The .bc
602 file is the LLVM version of the program all linked together.</p></li>
604 <li><p>Convert the LLVM code to C code, using the LLC tool with the C
607 <pre class="doc_code">
608 % llc -march=c program.bc -o program.c
611 <li><p>Finally, compile the C file:</p>
613 <pre class="doc_code">
619 <p>Using LLVM does not eliminate the need for C++ library support.
620 If you use the llvm-g++ front-end, the generated code will depend on
621 g++'s C++ support libraries in the same way that code generated from
622 g++ would. If you use another C++ front-end, the generated code will
623 depend on whatever library that front-end would normally require.</p>
625 <p>If you are working on a platform that does not provide any C++
626 libraries, you may be able to manually compile libstdc++ to LLVM
627 bitcode, statically link it into your program, then use the commands above to
628 convert the whole result into C code. Alternatively, you might compile the
629 libraries and your application into two different chunks of C code and link
632 <p>Note that, by default, the C back end does not support exception handling. If
633 you want/need it for a certain program, you can enable it by passing
634 "-enable-correct-eh-support" to the llc program. The resultant code will use
635 setjmp/longjmp to implement exception support that is relatively slow, and
636 not C++-ABI-conforming on most platforms, but otherwise correct.</p>
638 <p>Also, there are a number of other limitations of the C backend that
639 cause it to produce code that does not fully conform to the C++ ABI on
640 most platforms. Some of the C++ programs in LLVM's test suite are known
641 to fail when compiled with the C back end because of ABI incompatiblities
642 with standard C++ libraries.</p>
646 <div class="question">
648 <a name="platformindependent">Can I compile C or C++ code to platform-independent LLVM bitcode?</a>
654 <p>No. C and C++ are inherently platform-dependent languages. The most
655 obvious example of this is the preprocessor. A very common way that C code
656 is made portable is by using the preprocessor to include platform-specific
657 code. In practice, information about other platforms is lost after
658 preprocessing, so the result is inherently dependent on the platform that
659 the preprocessing was targetting.</p>
661 <p>Another example is <tt>sizeof</tt>. It's common for <tt>sizeof(long)</tt>
662 to vary between platforms. In most C front-ends, <tt>sizeof</tt> is expanded
663 to a constant immediately, thus hardwaring a platform-specific detail.</p>
665 <p>Also, since many platforms define their ABIs in terms of C, and since
666 LLVM is lower-level than C, front-ends currently must emit platform-specific
667 IR in order to have the result conform to the platform ABI.</p>
671 <!-- *********************************************************************** -->
672 <div class="doc_section">
673 <a name="cfe_code">Questions about code generated by the GCC front-end</a>
676 <div class="question">
677 <a name="iosinit"></a>
678 <p> What is this <tt>llvm.global_ctors</tt> and
679 <tt>_GLOBAL__I__tmp_webcompile...</tt> stuff that happens when I #include
680 <iostream>?</p>
685 <p>If you #include the <iostream> header into a C++ translation unit, the
686 file will probably use the <tt>std::cin</tt>/<tt>std::cout</tt>/... global
687 objects. However, C++ does not guarantee an order of initialization between
688 static objects in different translation units, so if a static ctor/dtor in your
689 .cpp file used <tt>std::cout</tt>, for example, the object would not necessarily
690 be automatically initialized before your use.</p>
692 <p>To make <tt>std::cout</tt> and friends work correctly in these scenarios, the
693 STL that we use declares a static object that gets created in every translation
694 unit that includes <tt><iostream></tt>. This object has a static
695 constructor and destructor that initializes and destroys the global iostream
696 objects before they could possibly be used in the file. The code that you see
697 in the .ll file corresponds to the constructor and destructor registration code.
700 <p>If you would like to make it easier to <b>understand</b> the LLVM code
701 generated by the compiler in the demo page, consider using <tt>printf()</tt>
702 instead of <tt>iostream</tt>s to print values.</p>
706 <!--=========================================================================-->
708 <div class="question"><p>
709 <a name="codedce"></a>
710 Where did all of my code go??
715 If you are using the LLVM demo page, you may often wonder what happened to all
716 of the code that you typed in. Remember that the demo script is running the
717 code through the LLVM optimizers, so if your code doesn't actually do anything
718 useful, it might all be deleted.
722 To prevent this, make sure that the code is actually needed. For example, if
723 you are computing some expression, return the value from the function instead of
724 leaving it in a local variable. If you really want to constrain the optimizer,
725 you can read from and assign to <tt>volatile</tt> global variables.
729 <!--=========================================================================-->
731 <div class="question"><p>
733 <p>What is this "<tt>undef</tt>" thing that shows up in my code?
738 <a href="LangRef.html#undef"><tt>undef</tt></a> is the LLVM way of representing
739 a value that is not defined. You can get these if you do not initialize a
740 variable before you use it. For example, the C function:</p>
742 <pre class="doc_code">
743 int X() { int i; return i; }
746 <p>Is compiled to "<tt>ret i32 undef</tt>" because "<tt>i</tt>" never has
747 a value specified for it.</p>
750 <!-- *********************************************************************** -->
754 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
755 src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a>
756 <a href="http://validator.w3.org/check/referer"><img
757 src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a>
759 <a href="http://llvm.org">LLVM Compiler Infrastructure</a><br>
760 Last modified: $Date$