blob: 0f2abd63801ed7455c4bfdcf3b94253e30da755b [file] [log] [blame]
Misha Brukmana6538852003-11-06 21:55:44 +00001<!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>
Misha Brukman7ce62cc2004-06-01 18:51:03 +00006 <style type="text/css">
Misha Brukmana6538852003-11-06 21:55:44 +00007 @import url("llvm.css");
8 .question { font-weight: bold }
9 .answer { margin-left: 2em }
10 </style>
11</head>
12<body>
John Criswellc310f622003-10-13 16:13:06 +000013
Misha Brukmana6538852003-11-06 21:55:44 +000014<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>
Chris Lattner306acee2003-12-22 04:06:12 +000051 <li>Compiling LLVM with GCC 3.3.2 fails, what should I do?</li>
John Criswelld1799612004-03-29 20:23:11 +000052 <li>When I use the test suite, all of the C Backend tests fail. What is
53 wrong?</li>
Misha Brukman1739aec2004-09-09 16:36:47 +000054 <li>After CVS update, rebuilding gives the error "No rule to make
55 target".</li>
Misha Brukmana6538852003-11-06 21:55:44 +000056 </ol></li>
John Criswell76c1e382003-11-18 16:08:49 +000057
Chris Lattnercc33d702003-11-19 05:53:12 +000058 <li><a href="#cfe">Using the GCC Front End</a>
John Criswell76c1e382003-11-18 16:08:49 +000059 <ol>
60 <li>
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?
64 </li>
65
66 <li>
67 When I compile code using the LLVM GCC front end, it complains that it
Chris Lattner7911ce22004-05-23 21:07:27 +000068 cannot find libcrtend.a.
John Criswell76c1e382003-11-18 16:08:49 +000069 </li>
70 </ol>
71 </li>
Chris Lattnercc33d702003-11-19 05:53:12 +000072
73 <li><a href="#cfe_code">Questions about code generated by the GCC front-end</a>
74 <ol>
Chris Lattner5a53c5d2005-02-25 20:30:21 +000075 <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
Chris Lattnerc50bbc92004-03-29 19:14:35 +000078 <tt>_GLOBAL__I__tmp_webcompile...</tt> stuff that happens when I
Chris Lattner5a53c5d2005-02-25 20:30:21 +000079 #include &lt;iostream&gt;?</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>
Chris Lattnercc33d702003-11-19 05:53:12 +000082 </ol>
83 </li>
Misha Brukmana6538852003-11-06 21:55:44 +000084</ol>
85
Chris Lattner7911ce22004-05-23 21:07:27 +000086<div class="doc_author">
87 <p>Written by <a href="http://llvm.cs.uiuc.edu">The LLVM Team</a></p>
88</div>
89
90
Misha Brukmana6538852003-11-06 21:55:44 +000091<!-- *********************************************************************** -->
92<div class="doc_section">
93 <a name="license">License</a>
94</div>
95<!-- *********************************************************************** -->
96
97<div class="question">
98<p>Why are the LLVM source code and the front-end distributed under different
99licenses?</p>
100</div>
101
102<div class="answer">
103<p>The C/C++ front-ends are based on GCC and must be distributed under the GPL.
104Our aim is to distribute LLVM source code under a <em>much less restrictive</em>
105license, in particular one that does not compel users who distribute tools based
106on modifying the source to redistribute the modified source code as well.</p>
107</div>
108
109<div class="question">
110<p>Does the University of Illinois Open Source License really qualify as an
111"open source" license?</p>
112</div>
113
114<div class="answer">
115<p>Yes, the license is <a
116href="http://www.opensource.org/licenses/UoI-NCSA.php">certified</a> by the Open
117Source Initiative (OSI).</p>
118</div>
119
120<div class="question">
121<p>Can I modify LLVM source code and redistribute the modified source?</p>
122</div>
123
124<div class="answer">
125<p>Yes. The modified source distribution must retain the copyright notice and
126follow the three bulletted conditions listed in the <a
Misha Brukman237dc2a2004-12-03 23:58:18 +0000127href="http://llvm.cs.uiuc.edu/releases/1.3/LICENSE.TXT">LLVM license</a>.</p>
Misha Brukmana6538852003-11-06 21:55:44 +0000128</div>
129
130<div class="question">
131<p>Can I modify LLVM source code and redistribute binaries or other tools based
132on it, without redistributing the source?</p>
133</div>
134
135<div class="answer">
136<p>Yes, this is why we distribute LLVM under a less restrictive license than
137GPL, as explained in the first question above.</p>
138</div>
139
140<!-- *********************************************************************** -->
141<div class="doc_section">
142 <a name="source">Source Code</a>
143</div>
144<!-- *********************************************************************** -->
145
146<div class="question">
147<p>In what language is LLVM written?</p>
148</div>
149
150<div class="answer">
151<p>All of the LLVM tools and libraries are written in C++ with extensive use of
152the STL.</p>
153</div>
154
155<div class="question">
156<p>How portable is the LLVM source code?</p>
157</div>
158
159<div class="answer">
160<p>The LLVM source code should be portable to most modern UNIX-like operating
161systems. Most of the code is written in standard C++ with operating system
162services abstracted to a support library. The tools required to build and test
163LLVM have been ported to a plethora of platforms.</p>
164
165<p>Some porting problems may exist in the following areas:</p>
166
167<ul>
168
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>
171
Misha Brukmana6538852003-11-06 21:55:44 +0000172 <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>
175
176</ul>
177
178</div>
179
180<!-- *********************************************************************** -->
181<div class="doc_section">
182 <a name="build">Build Problems</a>
183</div>
184<!-- *********************************************************************** -->
185
186<div class="question">
187<p>When I run configure, it finds the wrong C compiler.</p>
188</div>
189
190<div class="answer">
191
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>
194for the C and C++ compiler, respectively.</p>
195
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>
198explicitly.</p>
199
200</div>
201
202<div class="question">
203<p>I compile the code, and I get some error about <tt>/localhome</tt>.</p>
204</div>
205
206<div class="answer">
207
208<p>There are several possible causes for this. The first is that you didn't set
209a pathname properly when using <tt>configure</tt>, and it defaulted to a
210pathname that we use on our research machines.</p>
211
212<p>Another possibility is that we hardcoded a path in our Makefiles. If you see
213this, please email the LLVM bug mailing list with the name of the offending
214Makefile and a description of what is wrong with it.</p>
215
216</div>
217
218<div class="question">
219<p>The <tt>configure</tt> script finds the right C compiler, but it uses the
220LLVM linker from a previous build. What do I do?</p>
221</div>
222
223<div class="answer">
224<p>The <tt>configure</tt> script uses the <tt>PATH</tt> to find executables, so
225if it's grabbing the wrong linker/assembler/etc, there are two ways to fix
226it:</p>
227
228<ol>
229
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
233 work.</p></li>
234
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>
237
Misha Brukman7ce62cc2004-06-01 18:51:03 +0000238 <p><tt>PATH=[the path without the bad program] ./configure ...</tt></p>
Misha Brukmana6538852003-11-06 21:55:44 +0000239
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>
243
244</ol>
245
246</div>
247
248<div class="question">
249<p>When creating a dynamic library, I get a strange GLIBC error.</p>
250</div>
251
252<div class="answer">
253<p>Under some operating systems (i.e. Linux), libtool does not work correctly if
254GCC was compiled with the --disable-shared option. To work around this, install
255your own version of GCC that has shared libraries enabled by default.</p>
256</div>
257
258<div class="question">
259<p>I've updated my source tree from CVS, and now my build is trying to use a
260file/directory that doesn't exist.</p>
261</div>
262
263<div class="answer">
264<p>You need to re-run configure in your object directory. When new Makefiles
265are added to the source tree, they have to be copied over to the object tree in
266order to be used by the build.</p>
267</div>
268
269<div class="question">
270<p>I've modified a Makefile in my source tree, but my build tree keeps using the
271old version. What do I do?</p>
272</div>
273
274<div class="answer">
275
276<p>If the Makefile already exists in your object tree, you
277can just run the following command in the top level directory of your object
278tree:</p>
279
280<p><tt>./config.status &lt;relative path to Makefile&gt;</tt><p>
281
282<p>If the Makefile is new, you will have to modify the configure script to copy
283it over.</p>
284
285</div>
286
287<div class="question">
288<p>I've upgraded to a new version of LLVM, and I get strange build errors.</p>
289</div>
290
291<div class="answer">
292
293<p>Sometimes, changes to the LLVM source code alters how the build system works.
294Changes in libtool, autoconf, or header file dependencies are especially prone
295to this sort of problem.</p>
296
297<p>The best thing to try is to remove the old files and re-build. In most
298cases, this takes care of the problem. To do this, just type <tt>make
299clean</tt> and then <tt>make</tt> in the directory that fails to build.</p>
300
301</div>
302
303<div class="question">
304<p>I've built LLVM and am testing it, but the tests freeze.</p>
305</div>
306
307<div class="answer">
308
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>
312
313<p>For example, if you built LLVM with the command:</p>
314
315<p><tt>gmake ENABLE_PROFILING=1</tt>
316
317<p>...then you must run the tests with the following commands:</p>
318
319<p><tt>cd llvm/test<br>gmake ENABLE_PROFILING=1</tt></p>
320
321</div>
322
323<div class="question">
324<p>Why do test results differ when I perform different types of builds?</p>
325</div>
326
327<div class="answer">
328
329<p>The LLVM test suite is dependent upon several features of the LLVM tools and
330libraries.</p>
331
332<p>First, the debugging assertions in code are not enabled in optimized or
333profiling builds. Hence, tests that used to fail may pass.</p>
334
335<p>Second, some tests may rely upon debugging options or behavior that is only
336available in the debug build. These tests will fail in an optimized or profile
337build.</p>
338
339</div>
340
Chris Lattner8a0b9242003-12-08 05:43:19 +0000341<div class="question">
Chris Lattner306acee2003-12-22 04:06:12 +0000342<p>Compiling LLVM with GCC 3.3.2 fails, what should I do?</p>
Chris Lattner8a0b9242003-12-08 05:43:19 +0000343</div>
344
345<div class="answer">
Chris Lattner306acee2003-12-22 04:06:12 +0000346<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>
Chris Lattner8a0b9242003-12-08 05:43:19 +0000348</div>
349
John Criswelld1799612004-03-29 20:23:11 +0000350<div class="question">
Misha Brukman1739aec2004-09-09 16:36:47 +0000351<p>After CVS update, rebuilding gives the error "No rule to make target".</p>
352</div>
353
354<div class="answer">
355<p>If the error is of the form:</p>
356
357<div class="doc_code">
358<tt>
359gmake[2]: *** No rule to make target `/path/to/somefile', needed by
360`/path/to/another/file.d'.<br>
361Stop.
362</tt>
363</div>
364
365<p>This may occur anytime files are moved within the CVS repository or removed
366entirely. In this case, the best solution is to erase all <tt>.d</tt> files,
367which list dependencies for source files, and rebuild:</p>
368
369<div class="doc_code">
370<pre>
371% cd $LLVM_OBJ_DIR
372% rm -f `find . -name \*\.d`
373% gmake
374</pre>
375</div>
376
377<p>In other cases, it may be necessary to run <tt>make clean</tt> before
378rebuilding.</p>
379</div>
380
Misha Brukmana6538852003-11-06 21:55:44 +0000381<!-- *********************************************************************** -->
John Criswell6ea30b02003-11-18 16:05:23 +0000382<div class="doc_section">
Chris Lattnercc33d702003-11-19 05:53:12 +0000383 <a name="cfe">Using the GCC Front End</a>
John Criswell6ea30b02003-11-18 16:05:23 +0000384</div>
385
386<div class="question">
387<p>
388When I compile software that uses a configure script, the configure script
389thinks my system has all of the header files and libraries it is testing for.
390How do I get configure to work correctly?
391</p>
392</div>
393
394<div class="answer">
395<p>
396The configure script is getting things wrong because the LLVM linker allows
397symbols to be undefined at link time (so that they can be resolved during JIT
398or translation to the C back end). That is why configure thinks your system
399"has everything."
400</p>
401<p>
402To work around this, perform the following steps:
403</p>
404
405<ol>
406 <li>
407 Make sure the CC and CXX environment variables contains the full path to the
408 LLVM GCC front end.
409 </li>
410
411 <li>
412 Make sure that the regular C compiler is first in your PATH.
413 </li>
414
415 <li>
416 Add the string "-Wl,-native" to your CFLAGS environment variable.
417 </li>
418</ol>
419
420<p>
421This will allow the gccld linker to create a native code executable instead of
422a shell script that runs the JIT. Creating native code requires standard
423linkage, which in turn will allow the configure script to find out if code is
424not linking on your system because the feature isn't available on your system.
425</p>
426</div>
427
Chris Lattnercc33d702003-11-19 05:53:12 +0000428<div class="question">
John Criswell6ea30b02003-11-18 16:05:23 +0000429<p>
430When I compile code using the LLVM GCC front end, it complains that it cannot
John Criswellcd161192004-03-12 18:20:15 +0000431find libcrtend.a.
John Criswell6ea30b02003-11-18 16:05:23 +0000432</p>
433</div>
434
Chris Lattnercc33d702003-11-19 05:53:12 +0000435<div class="answer">
John Criswell6ea30b02003-11-18 16:05:23 +0000436<p>
Reid Spencerf96eb572004-12-15 00:14:01 +0000437The only way this can happen is if you haven't installed the runtime library. To
438correct this, do:</p>
439<pre>
440 % cd llvm/runtime
441 % make clean ; make install-bytecode
442</pre>
John Criswell6ea30b02003-11-18 16:05:23 +0000443</div>
Chris Lattnercc33d702003-11-19 05:53:12 +0000444
445
446<!-- *********************************************************************** -->
447<div class="doc_section">
448 <a name="cfe_code">Questions about code generated by the GCC front-end</a>
449</div>
450
Chris Lattnera28e3ce2003-12-16 22:33:55 +0000451<div class="question"><p>
Chris Lattner5a53c5d2005-02-25 20:30:21 +0000452<a name="__main"></a>
Chris Lattnercc33d702003-11-19 05:53:12 +0000453What is this <tt>__main()</tt> call that gets inserted into <tt>main()</tt>?
Chris Lattnera28e3ce2003-12-16 22:33:55 +0000454</p></div>
Chris Lattnercc33d702003-11-19 05:53:12 +0000455
456<div class="answer">
457<p>
458The <tt>__main</tt> call is inserted by the C/C++ compiler in order to guarantee
459that static constructors and destructors are called when the program starts up
460and shuts down. In C, you can create static constructors and destructors by
461using GCC extensions, and in C++ you can do so by creating a global variable
462whose class has a ctor or dtor.
463</p>
464
465<p>
466The actual implementation of <tt>__main</tt> lives in the
467<tt>llvm/runtime/GCCLibraries/crtend/</tt> directory in the source-base, and is
468linked in automatically when you link the program.
469</p>
Chris Lattnercc33d702003-11-19 05:53:12 +0000470</div>
471
Chris Lattnera28e3ce2003-12-16 22:33:55 +0000472<!--=========================================================================-->
Chris Lattnercc33d702003-11-19 05:53:12 +0000473
Misha Brukman237dc2a2004-12-03 23:58:18 +0000474<div class="question">
Chris Lattner5a53c5d2005-02-25 20:30:21 +0000475<a name="iosinit"></a>
Misha Brukman237dc2a2004-12-03 23:58:18 +0000476<p> What is this <tt>llvm.global_ctors</tt> and
477<tt>_GLOBAL__I__tmp_webcompile...</tt> stuff that happens when I #include
478&lt;iostream&gt;?</p>
479</div>
Chris Lattnerc50bbc92004-03-29 19:14:35 +0000480
481<div class="answer">
Misha Brukman237dc2a2004-12-03 23:58:18 +0000482
483<p>If you #include the &lt;iostream&gt; header into a C++ translation unit, the
Chris Lattnerc50bbc92004-03-29 19:14:35 +0000484file will probably use the <tt>std::cin</tt>/<tt>std::cout</tt>/... global
485objects. However, C++ does not guarantee an order of initialization between
486static 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
Misha Brukman237dc2a2004-12-03 23:58:18 +0000488be automatically initialized before your use.</p>
Chris Lattnerc50bbc92004-03-29 19:14:35 +0000489
Misha Brukman237dc2a2004-12-03 23:58:18 +0000490<p>To make <tt>std::cout</tt> and friends work correctly in these scenarios, the
Chris Lattnerc50bbc92004-03-29 19:14:35 +0000491STL that we use declares a static object that gets created in every translation
Misha Brukman237dc2a2004-12-03 23:58:18 +0000492unit that includes <tt>&lt;iostream&gt;</tt>. This object has a static
493constructor and destructor that initializes and destroys the global iostream
494objects before they could possibly be used in the file. The code that you see
495in the .ll file corresponds to the constructor and destructor registration code.
Chris Lattnerc50bbc92004-03-29 19:14:35 +0000496</p>
497
Misha Brukman237dc2a2004-12-03 23:58:18 +0000498<p>If you would like to make it easier to <b>understand</b> the LLVM code
499generated by the compiler in the demo page, consider using <tt>printf()</tt>
500instead of <tt>iostream</tt>s to print values.</p>
501
Chris Lattnerc50bbc92004-03-29 19:14:35 +0000502</div>
503
Chris Lattner5a53c5d2005-02-25 20:30:21 +0000504<!--=========================================================================-->
505
506<div class="question"><p>
507<a name="codedce"></a>
508Where did all of my code go??
509</p></div>
510
511<div class="answer">
512<p>
513If you are using the LLVM demo page, you may often wonder what happened to all
514of the code that you typed in. Remember that the demo script is running the
515code through the LLVM optimizers, so if your code doesn't actually do anything
516useful, it might all be deleted.
517</p>
518
519<p>
520To prevent this, make sure that the code is actually needed. For example, if
521you are computing some expression, return the value from the function instead of
522leaving it in a local variable. If you really want to constrain the optimizer,
523you can read from and assign to <tt>volatile</tt> global variables.
524</p>
525</div>
526
527<!--=========================================================================-->
528
529<div class="question"><p>
530<a name="undef"></a>
531<p>What is this "<tt>undef</tt>" thing that shows up in my code?
532</p></div>
533
534<div class="answer">
535<p>
536<a href="LangRef.html#undef"><tt>undef</tt></a> is the LLVM way of representing
537a value that is not defined. You can get these if you do not initialize a
538variable before you use it. For example, the C function:</p>
539
540<div class="doc_code">
541 <tt>int X() { int i; return i; }</tt>
542</div>
543
544<p>Is compiled to "<tt>ret int undef</tt>" because "i" never has a value
545specified for it.
546</p>
547</div>
548
John Criswell6ea30b02003-11-18 16:05:23 +0000549<!-- *********************************************************************** -->
John Criswellc310f622003-10-13 16:13:06 +0000550
551<hr>
Misha Brukman7ce62cc2004-06-01 18:51:03 +0000552<address>
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>
557
558 <a href="http://llvm.cs.uiuc.edu">LLVM Compiler Infrastructure</a><br>
Misha Brukmana6538852003-11-06 21:55:44 +0000559 Last modified: $Date$
Misha Brukman7ce62cc2004-06-01 18:51:03 +0000560</address>
John Criswellf08c5d82003-10-24 22:48:20 +0000561
John Criswellc310f622003-10-13 16:13:06 +0000562</body>
563</html>