blob: 017a4d1a229f17b0e01a87b008357901cddff665 [file] [log] [blame]
Misha Brukman6c91a332003-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 Brukman5363e382004-06-01 18:51:03 +00006 <style type="text/css">
Misha Brukman6c91a332003-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 Criswell8af73202003-10-13 16:13:06 +000013
Misha Brukman6c91a332003-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>
Misha Brukman6c91a332003-11-06 21:55:44 +000039 <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>
Reid Spencerc7f87f22007-07-09 08:04:31 +000042 <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>
Misha Brukman6c91a332003-11-06 21:55:44 +000044 <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
47 errors.</li>
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>
Chris Lattner5abdc6f2003-12-22 04:06:12 +000050 <li>Compiling LLVM with GCC 3.3.2 fails, what should I do?</li>
John Criswellfa2f3682004-03-29 20:23:11 +000051 <li>When I use the test suite, all of the C Backend tests fail. What is
52 wrong?</li>
Reid Spencerc7f87f22007-07-09 08:04:31 +000053 <li>After Subversion update, rebuilding gives the error "No rule to make
Bill Wendling0a303eb2007-05-29 09:35:34 +000054 target".</li>
55 <li><a href="#llvmc">The <tt>llvmc</tt> program gives me errors/doesn't
Bill Wendlingbeee6222007-09-22 09:54:47 +000056 work.</a></li>
Misha Brukman6c91a332003-11-06 21:55:44 +000057 </ol></li>
John Criswell956cf452003-11-18 16:08:49 +000058
Reid Spencer9aa244e2006-04-26 14:52:19 +000059 <li><a href="#felangs">Source Languages</a>
60 <ol>
61 <li><a href="#langs">What source languages are supported?</a></li>
Gordon Henriksen6ee6b7c2008-02-22 20:58:29 +000062 <li><a href="#langirgen">I'd like to write an LLVM compiler for my language.
63 How should I interface with the LLVM middle-end optimizers and back-end
64 code generators?</a></div>
Reid Spencer9aa244e2006-04-26 14:52:19 +000065 <li><a href="#langhlsupp">What support is there for higher level source
66 language constructs for building a compiler?</a></li>
Reid Spencer4bded9c2006-08-10 20:15:58 +000067 <li><a href="GetElementPtr.html">I don't understand the GetElementPtr
68 instruction. Help!</a></li>
Reid Spencer9aa244e2006-04-26 14:52:19 +000069 </ol>
70
Chris Lattner23353312003-11-19 05:53:12 +000071 <li><a href="#cfe">Using the GCC Front End</a>
John Criswell956cf452003-11-18 16:08:49 +000072 <ol>
73 <li>
74 When I compile software that uses a configure script, the configure script
75 thinks my system has all of the header files and libraries it is testing
76 for. How do I get configure to work correctly?
77 </li>
78
79 <li>
80 When I compile code using the LLVM GCC front end, it complains that it
Chris Lattner020e1fc2004-05-23 21:07:27 +000081 cannot find libcrtend.a.
John Criswell956cf452003-11-18 16:08:49 +000082 </li>
Tanya Lattneraf0ac272005-04-25 20:36:56 +000083
84 <li>
85 How can I disable all optimizations when compiling code using the LLVM GCC front end?
86 </li>
87
Chris Lattner7b1d3c02006-07-19 18:19:59 +000088 <li><a href="#translatec++">Can I use LLVM to convert C++ code to C code?</a></li>
89
John Criswell956cf452003-11-18 16:08:49 +000090 </ol>
91 </li>
Chris Lattner23353312003-11-19 05:53:12 +000092
93 <li><a href="#cfe_code">Questions about code generated by the GCC front-end</a>
94 <ol>
Chris Lattner37d55472005-02-25 20:30:21 +000095 <li><a href="#iosinit">What is this <tt>llvm.global_ctors</tt> and
Chris Lattner87d6b402004-03-29 19:14:35 +000096 <tt>_GLOBAL__I__tmp_webcompile...</tt> stuff that happens when I
Chris Lattner37d55472005-02-25 20:30:21 +000097 #include &lt;iostream&gt;?</a></li>
98 <li><a href="#codedce">Where did all of my code go??</a></li>
99 <li><a href="#undef">What is this "<tt>undef</tt>" thing that shows up in my code?</a></li>
Chris Lattner23353312003-11-19 05:53:12 +0000100 </ol>
101 </li>
Misha Brukman6c91a332003-11-06 21:55:44 +0000102</ol>
103
Chris Lattner020e1fc2004-05-23 21:07:27 +0000104<div class="doc_author">
Reid Spencerca058542006-03-14 05:39:39 +0000105 <p>Written by <a href="http://llvm.org">The LLVM Team</a></p>
Chris Lattner020e1fc2004-05-23 21:07:27 +0000106</div>
107
108
Misha Brukman6c91a332003-11-06 21:55:44 +0000109<!-- *********************************************************************** -->
110<div class="doc_section">
111 <a name="license">License</a>
112</div>
113<!-- *********************************************************************** -->
114
115<div class="question">
116<p>Why are the LLVM source code and the front-end distributed under different
117licenses?</p>
118</div>
119
120<div class="answer">
121<p>The C/C++ front-ends are based on GCC and must be distributed under the GPL.
122Our aim is to distribute LLVM source code under a <em>much less restrictive</em>
123license, in particular one that does not compel users who distribute tools based
124on modifying the source to redistribute the modified source code as well.</p>
125</div>
126
127<div class="question">
128<p>Does the University of Illinois Open Source License really qualify as an
129"open source" license?</p>
130</div>
131
132<div class="answer">
133<p>Yes, the license is <a
134href="http://www.opensource.org/licenses/UoI-NCSA.php">certified</a> by the Open
135Source Initiative (OSI).</p>
136</div>
137
138<div class="question">
139<p>Can I modify LLVM source code and redistribute the modified source?</p>
140</div>
141
142<div class="answer">
143<p>Yes. The modified source distribution must retain the copyright notice and
144follow the three bulletted conditions listed in the <a
Reid Spencerca058542006-03-14 05:39:39 +0000145href="http://llvm.org/releases/1.3/LICENSE.TXT">LLVM license</a>.</p>
Misha Brukman6c91a332003-11-06 21:55:44 +0000146</div>
147
148<div class="question">
149<p>Can I modify LLVM source code and redistribute binaries or other tools based
150on it, without redistributing the source?</p>
151</div>
152
153<div class="answer">
154<p>Yes, this is why we distribute LLVM under a less restrictive license than
155GPL, as explained in the first question above.</p>
156</div>
157
158<!-- *********************************************************************** -->
159<div class="doc_section">
160 <a name="source">Source Code</a>
161</div>
162<!-- *********************************************************************** -->
163
164<div class="question">
165<p>In what language is LLVM written?</p>
166</div>
167
168<div class="answer">
169<p>All of the LLVM tools and libraries are written in C++ with extensive use of
170the STL.</p>
171</div>
172
173<div class="question">
174<p>How portable is the LLVM source code?</p>
175</div>
176
177<div class="answer">
178<p>The LLVM source code should be portable to most modern UNIX-like operating
179systems. Most of the code is written in standard C++ with operating system
180services abstracted to a support library. The tools required to build and test
181LLVM have been ported to a plethora of platforms.</p>
182
183<p>Some porting problems may exist in the following areas:</p>
184
185<ul>
Misha Brukman6c91a332003-11-06 21:55:44 +0000186 <li>The GCC front end code is not as portable as the LLVM suite, so it may not
Bill Wendlingbeee6222007-09-22 09:54:47 +0000187 compile as well on unsupported platforms.</li>
Misha Brukman6c91a332003-11-06 21:55:44 +0000188
Misha Brukman6c91a332003-11-06 21:55:44 +0000189 <li>The LLVM build system relies heavily on UNIX shell tools, like the Bourne
Bill Wendlingbeee6222007-09-22 09:54:47 +0000190 Shell and sed. Porting to systems without these tools (MacOS 9, Plan 9)
191 will require more effort.</li>
Misha Brukman6c91a332003-11-06 21:55:44 +0000192</ul>
193
194</div>
195
196<!-- *********************************************************************** -->
197<div class="doc_section">
198 <a name="build">Build Problems</a>
199</div>
200<!-- *********************************************************************** -->
201
202<div class="question">
203<p>When I run configure, it finds the wrong C compiler.</p>
204</div>
205
206<div class="answer">
207
208<p>The <tt>configure</tt> script attempts to locate first <tt>gcc</tt> and then
209<tt>cc</tt>, unless it finds compiler paths set in <tt>CC</tt> and <tt>CXX</tt>
210for the C and C++ compiler, respectively.</p>
211
212<p>If <tt>configure</tt> finds the wrong compiler, either adjust your
213<tt>PATH</tt> environment variable or set <tt>CC</tt> and <tt>CXX</tt>
214explicitly.</p>
215
216</div>
217
218<div class="question">
Misha Brukman6c91a332003-11-06 21:55:44 +0000219<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>
Misha Brukman6c91a332003-11-06 21:55:44 +0000229 <li><p>Adjust your <tt>PATH</tt> environment variable so that the correct
Bill Wendlingbeee6222007-09-22 09:54:47 +0000230 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
232 work.</p></li>
Misha Brukman6c91a332003-11-06 21:55:44 +0000233
234 <li><p>Run <tt>configure</tt> with an alternative <tt>PATH</tt> that is
Bill Wendlingbeee6222007-09-22 09:54:47 +0000235 correct. In a Borne compatible shell, the syntax would be:</p>
236
237<div class="doc_code">
238<pre>
239% PATH=[the path without the bad program] ./configure ...
240</pre>
241</div>
Misha Brukman6c91a332003-11-06 21:55:44 +0000242
243 <p>This is still somewhat inconvenient, but it allows <tt>configure</tt>
Bill Wendlingbeee6222007-09-22 09:54:47 +0000244 to do its work without having to adjust your <tt>PATH</tt>
245 permanently.</p></li>
Misha Brukman6c91a332003-11-06 21:55:44 +0000246</ol>
247
248</div>
249
250<div class="question">
251<p>When creating a dynamic library, I get a strange GLIBC error.</p>
252</div>
253
254<div class="answer">
255<p>Under some operating systems (i.e. Linux), libtool does not work correctly if
256GCC was compiled with the --disable-shared option. To work around this, install
257your own version of GCC that has shared libraries enabled by default.</p>
258</div>
259
260<div class="question">
Bill Wendlingbeee6222007-09-22 09:54:47 +0000261<p>I've updated my source tree from Subversion, and now my build is trying to
262use a file/directory that doesn't exist.</p>
Misha Brukman6c91a332003-11-06 21:55:44 +0000263</div>
264
265<div class="answer">
266<p>You need to re-run configure in your object directory. When new Makefiles
267are added to the source tree, they have to be copied over to the object tree in
268order to be used by the build.</p>
269</div>
270
271<div class="question">
272<p>I've modified a Makefile in my source tree, but my build tree keeps using the
273old version. What do I do?</p>
274</div>
275
276<div class="answer">
Misha Brukman6c91a332003-11-06 21:55:44 +0000277<p>If the Makefile already exists in your object tree, you
278can just run the following command in the top level directory of your object
279tree:</p>
280
Bill Wendlingbeee6222007-09-22 09:54:47 +0000281<div class="doc_code">
282<pre>% ./config.status &lt;relative path to Makefile&gt;</pre>
283</div>
Misha Brukman6c91a332003-11-06 21:55:44 +0000284
285<p>If the Makefile is new, you will have to modify the configure script to copy
286it over.</p>
287
288</div>
289
290<div class="question">
291<p>I've upgraded to a new version of LLVM, and I get strange build errors.</p>
292</div>
293
294<div class="answer">
295
296<p>Sometimes, changes to the LLVM source code alters how the build system works.
297Changes in libtool, autoconf, or header file dependencies are especially prone
298to this sort of problem.</p>
299
300<p>The best thing to try is to remove the old files and re-build. In most
301cases, this takes care of the problem. To do this, just type <tt>make
302clean</tt> and then <tt>make</tt> in the directory that fails to build.</p>
303
304</div>
305
306<div class="question">
307<p>I've built LLVM and am testing it, but the tests freeze.</p>
308</div>
309
310<div class="answer">
311
312<p>This is most likely occurring because you built a profile or release
313(optimized) build of LLVM and have not specified the same information on the
314<tt>gmake</tt> command line.</p>
315
316<p>For example, if you built LLVM with the command:</p>
317
Bill Wendling2c22fcb2007-05-29 09:24:33 +0000318<div class="doc_code">
Bill Wendlingbeee6222007-09-22 09:54:47 +0000319<pre>% gmake ENABLE_PROFILING=1</pre>
Bill Wendling2c22fcb2007-05-29 09:24:33 +0000320</div>
Misha Brukman6c91a332003-11-06 21:55:44 +0000321
322<p>...then you must run the tests with the following commands:</p>
323
Bill Wendling2c22fcb2007-05-29 09:24:33 +0000324<div class="doc_code">
325<pre>
326% cd llvm/test
327% gmake ENABLE_PROFILING=1
328</pre>
329</div>
Misha Brukman6c91a332003-11-06 21:55:44 +0000330
331</div>
332
333<div class="question">
334<p>Why do test results differ when I perform different types of builds?</p>
335</div>
336
337<div class="answer">
338
339<p>The LLVM test suite is dependent upon several features of the LLVM tools and
340libraries.</p>
341
342<p>First, the debugging assertions in code are not enabled in optimized or
343profiling builds. Hence, tests that used to fail may pass.</p>
344
345<p>Second, some tests may rely upon debugging options or behavior that is only
346available in the debug build. These tests will fail in an optimized or profile
347build.</p>
348
349</div>
350
Chris Lattner408916b2003-12-08 05:43:19 +0000351<div class="question">
Chris Lattner5abdc6f2003-12-22 04:06:12 +0000352<p>Compiling LLVM with GCC 3.3.2 fails, what should I do?</p>
Chris Lattner408916b2003-12-08 05:43:19 +0000353</div>
354
355<div class="answer">
Chris Lattner5abdc6f2003-12-22 04:06:12 +0000356<p>This is <a href="http://gcc.gnu.org/PR?13392">a bug in GCC</a>, and
Bill Wendlingbeee6222007-09-22 09:54:47 +0000357affects projects other than LLVM. Try upgrading or downgrading your GCC.</p>
Chris Lattner408916b2003-12-08 05:43:19 +0000358</div>
359
John Criswellfa2f3682004-03-29 20:23:11 +0000360<div class="question">
Bill Wendlingbeee6222007-09-22 09:54:47 +0000361<p>After Subversion update, rebuilding gives the error "No rule to make
362target".</p>
Misha Brukman46572352004-09-09 16:36:47 +0000363</div>
364
365<div class="answer">
366<p>If the error is of the form:</p>
367
368<div class="doc_code">
Bill Wendling2c22fcb2007-05-29 09:24:33 +0000369<pre>
Misha Brukman46572352004-09-09 16:36:47 +0000370gmake[2]: *** No rule to make target `/path/to/somefile', needed by
371`/path/to/another/file.d'.<br>
372Stop.
Bill Wendling2c22fcb2007-05-29 09:24:33 +0000373</pre>
Misha Brukman46572352004-09-09 16:36:47 +0000374</div>
375
Reid Spencerc7f87f22007-07-09 08:04:31 +0000376<p>This may occur anytime files are moved within the Subversion repository or
377removed entirely. In this case, the best solution is to erase all
378<tt>.d</tt> files, which list dependencies for source files, and rebuild:</p>
Misha Brukman46572352004-09-09 16:36:47 +0000379
380<div class="doc_code">
381<pre>
382% cd $LLVM_OBJ_DIR
383% rm -f `find . -name \*\.d`
384% gmake
385</pre>
386</div>
387
388<p>In other cases, it may be necessary to run <tt>make clean</tt> before
389rebuilding.</p>
390</div>
391
Bill Wendlingbeee6222007-09-22 09:54:47 +0000392<div class="question"><p><a name="llvmc">
393The <tt>llvmc</tt> program gives me errors/doesn't work.</a></p>
Bill Wendling0a303eb2007-05-29 09:35:34 +0000394</div>
395
396<div class="answer">
Bill Wendlingbeee6222007-09-22 09:54:47 +0000397<p><tt>llvmc</tt> is experimental and isn't really supported. We suggest
398using <tt>llvm-gcc</tt> instead.</p>
Bill Wendling0a303eb2007-05-29 09:35:34 +0000399</div>
400
Misha Brukman6c91a332003-11-06 21:55:44 +0000401<!-- *********************************************************************** -->
Reid Spencer4d3171f2006-04-26 15:46:53 +0000402<div class="doc_section"><a name="felangs">Source Languages</a></div>
Reid Spencer9aa244e2006-04-26 14:52:19 +0000403
Reid Spencer4d3171f2006-04-26 15:46:53 +0000404<div class="question"><p>
405 <a name="langs">What source languages are supported?</a></p>
406</div>
407<div class="answer">
Reid Spencer9aa244e2006-04-26 14:52:19 +0000408 <p>LLVM currently has full support for C and C++ source languages. These are
409 available through a special version of GCC that LLVM calls the
410 <a href="#cfe">C Front End</a></p>
411 <p>There is an incomplete version of a Java front end available in the
Reid Spencerc7f87f22007-07-09 08:04:31 +0000412 <tt>java</tt> module. There is no documentation on this yet so
Reid Spencer9aa244e2006-04-26 14:52:19 +0000413 you'll need to download the code, compile it, and try it.</p>
Reid Spencerc7f87f22007-07-09 08:04:31 +0000414 <p>In the <tt>stacker</tt> module is a compiler and runtime
Reid Spencer9aa244e2006-04-26 14:52:19 +0000415 library for the Stacker language, a "toy" language loosely based on Forth.</p>
416 <p>The PyPy developers are working on integrating LLVM into the PyPy backend
417 so that PyPy language can translate to LLVM.</p>
418</div>
Gordon Henriksen6ee6b7c2008-02-22 20:58:29 +0000419
420<div class="question"><p><a name="langirgen">
421 I'd like to write an LLVM compiler for my language. How should I interface
422 with the LLVM middle-end optimizers and back-end code generators?
423</a></p></div>
424<div class="answer">
425 <p>Your compiler front-end will communicate with LLVM by creating a module in
426 the LLVM intermediate representation (IR) format. There are 3 major ways to
427 tackle generating LLVM IR from a front-end:</p>
428 <ul>
429 <li>
430 <strong>Call into the LLVM libraries code using your language's FFI
431 (foreign function interface).</strong>
432 <ul>
433 <li><em>for:</em> best tracks changes to the LLVM IR, .ll syntax,
434 and .bc format</li>
435 <li><em>for:</em> enables running LLVM optimization passes without a
436 emit/parse overhead</li>
437 <li><em>for:</em> adapts well to a JIT context</li>
438 <li><em>against:</em> lots of ugly glue code to write</li>
439 </ul>
440 </li>
441 <li>
442 <strong>Emit LLVM assembly from your compiler's native language.</strong>
443 <ul>
444 <li><em>for:</em> very straightforward to get started</li>
445 <li><em>against:</em> the .ll parser is slower than the bitcode reader
446 when interfacing to the middle end</li>
447 <li><em>against:</em> you'll have to re-engineer the LLVM IR object
448 model and asm writer in your language</li>
449 <li><em>against:</em> it may be harder to track changes to the IR</li>
450 </ul>
451 </li>
452 <li>
453 <strong>Emit LLVM bitcode from your compiler's native language.</strong>
454 <ul>
455 <li><em>for:</em> can use the more-efficient bitcode reader when
456 interfacing to the middle end</li>
457 <li><em>against:</em> you'll have to re-engineer the LLVM IR object
458 model and bitcode writer in your language</li>
459 <li><em>against:</em> it may be harder to track changes to the IR</li>
460 </ul>
461 </li>
462 </ul>
463 <p>If you go with the first option, the C bindings in include/llvm-c should
464 help a lot, since most languages have strong support for interfacing with
465 C. The most common hurdle with calling C from managed code is interfacing
466 with the garbage collector. The C interface was designed to require very
467 little memory management, and so is straightforward in this regard.</p>
468</div>
469
Bill Wendlingbeee6222007-09-22 09:54:47 +0000470<div class="question"><p><a name="langhlsupp">
471 What support is there for a higher level source language constructs for
Reid Spencer4d3171f2006-04-26 15:46:53 +0000472 building a compiler?</a></p>
Reid Spencer9aa244e2006-04-26 14:52:19 +0000473</div>
474<div class="answer">
475 <p>Currently, there isn't much. LLVM supports an intermediate representation
476 which is useful for code representation but will not support the high level
477 (abstract syntax tree) representation needed by most compilers. There are no
Jeff Cohen027fbc22006-04-26 21:03:17 +0000478 facilities for lexical nor semantic analysis. There is, however, a <i>mostly
Reid Spencer9aa244e2006-04-26 14:52:19 +0000479 implemented</i> configuration-driven
480 <a href="CompilerDriver.html">compiler driver</a> which simplifies the task
481 of running optimizations, linking, and executable generation.</p>
Reid Spencer9aa244e2006-04-26 14:52:19 +0000482</div>
Chris Lattner667c9012006-08-15 00:43:35 +0000483
Bill Wendlingbeee6222007-09-22 09:54:47 +0000484<div class="question"><p><a name="langhlsupp">
485 I don't understand the GetElementPtr instruction. Help!</a></p>
Chris Lattner667c9012006-08-15 00:43:35 +0000486</div>
487<div class="answer">
488 <p>See <a href="GetElementPtr.html">The Often Misunderstood GEP
Bill Wendlingbeee6222007-09-22 09:54:47 +0000489 Instruction</a>.</p>
Chris Lattner667c9012006-08-15 00:43:35 +0000490</div>
491
Reid Spencer9aa244e2006-04-26 14:52:19 +0000492<!-- *********************************************************************** -->
493<div class="doc_section">
Chris Lattner23353312003-11-19 05:53:12 +0000494 <a name="cfe">Using the GCC Front End</a>
John Criswell5e0f07e2003-11-18 16:05:23 +0000495</div>
496
497<div class="question">
498<p>
499When I compile software that uses a configure script, the configure script
500thinks my system has all of the header files and libraries it is testing for.
501How do I get configure to work correctly?
502</p>
503</div>
504
505<div class="answer">
506<p>
507The configure script is getting things wrong because the LLVM linker allows
508symbols to be undefined at link time (so that they can be resolved during JIT
509or translation to the C back end). That is why configure thinks your system
510"has everything."
511</p>
512<p>
513To work around this, perform the following steps:
514</p>
John Criswell5e0f07e2003-11-18 16:05:23 +0000515<ol>
Reid Spencera7974cc2007-02-09 15:59:08 +0000516 <li>Make sure the CC and CXX environment variables contains the full path to
517 the LLVM GCC front end.</li>
John Criswell5e0f07e2003-11-18 16:05:23 +0000518
Reid Spencera7974cc2007-02-09 15:59:08 +0000519 <li>Make sure that the regular C compiler is first in your PATH. </li>
John Criswell5e0f07e2003-11-18 16:05:23 +0000520
Reid Spencera7974cc2007-02-09 15:59:08 +0000521 <li>Add the string "-Wl,-native" to your CFLAGS environment variable.</li>
John Criswell5e0f07e2003-11-18 16:05:23 +0000522</ol>
523
524<p>
Reid Spencera7974cc2007-02-09 15:59:08 +0000525This will allow the <tt>llvm-ld</tt> linker to create a native code executable
526instead of shell script that runs the JIT. Creating native code requires
527standard linkage, which in turn will allow the configure script to find out if
528code is not linking on your system because the feature isn't available on your
529system.</p>
John Criswell5e0f07e2003-11-18 16:05:23 +0000530</div>
531
Chris Lattner23353312003-11-19 05:53:12 +0000532<div class="question">
John Criswell5e0f07e2003-11-18 16:05:23 +0000533<p>
534When I compile code using the LLVM GCC front end, it complains that it cannot
John Criswelld89dbd02004-03-12 18:20:15 +0000535find libcrtend.a.
John Criswell5e0f07e2003-11-18 16:05:23 +0000536</p>
537</div>
538
Chris Lattner23353312003-11-19 05:53:12 +0000539<div class="answer">
John Criswell5e0f07e2003-11-18 16:05:23 +0000540<p>
Reid Spencer360d6b72004-12-15 00:14:01 +0000541The only way this can happen is if you haven't installed the runtime library. To
542correct this, do:</p>
Bill Wendling2c22fcb2007-05-29 09:24:33 +0000543
544<div class="doc_code">
Reid Spencer360d6b72004-12-15 00:14:01 +0000545<pre>
Bill Wendling2c22fcb2007-05-29 09:24:33 +0000546% cd llvm/runtime
547% make clean ; make install-bytecode
Reid Spencer360d6b72004-12-15 00:14:01 +0000548</pre>
John Criswell5e0f07e2003-11-18 16:05:23 +0000549</div>
Bill Wendling2c22fcb2007-05-29 09:24:33 +0000550</div>
Chris Lattner23353312003-11-19 05:53:12 +0000551
Tanya Lattneraf0ac272005-04-25 20:36:56 +0000552<div class="question">
553<p>
554How can I disable all optimizations when compiling code using the LLVM GCC front end?
555</p>
556</div>
557
558<div class="answer">
559<p>
560Passing "-Wa,-disable-opt -Wl,-disable-opt" will disable *all* cleanup and
561optimizations done at the llvm level, leaving you with the truly horrible
562code that you desire.
563</p>
564</div>
Chris Lattner23353312003-11-19 05:53:12 +0000565
Chris Lattner7b1d3c02006-07-19 18:19:59 +0000566
567<div class="question">
568<p>
569<a name="translatec++">Can I use LLVM to convert C++ code to C code?</a>
570</p>
571</div>
572
573<div class="answer">
574<p>Yes, you can use LLVM to convert code from any language LLVM supports to C.
575Note that the generated C code will be very low level (all loops are lowered
576to gotos, etc) and not very pretty (comments are stripped, original source
577formatting is totally lost, variables are renamed, expressions are regrouped),
578so this may not be what you're looking for. However, this is a good way to add
579C++ support for a processor that does not otherwise have a C++ compiler.
580</p>
581
582<p>Use commands like this:</p>
583
584<ol>
Bill Wendlingbeee6222007-09-22 09:54:47 +0000585 <li><p>Compile your program as normal with llvm-g++:</p>
Chris Lattner7b1d3c02006-07-19 18:19:59 +0000586
Bill Wendling2c22fcb2007-05-29 09:24:33 +0000587<div class="doc_code">
588<pre>
589% llvm-g++ x.cpp -o program
590</pre>
591</div>
Chris Lattner7b1d3c02006-07-19 18:19:59 +0000592
Bill Wendlingbeee6222007-09-22 09:54:47 +0000593 <p>or:</p>
Chris Lattner7b1d3c02006-07-19 18:19:59 +0000594
595<div class="doc_code">
Bill Wendling2c22fcb2007-05-29 09:24:33 +0000596<pre>
597% llvm-g++ a.cpp -c
598% llvm-g++ b.cpp -c
599% llvm-g++ a.o b.o -o program
600</pre>
Chris Lattner7b1d3c02006-07-19 18:19:59 +0000601</div>
602
Bill Wendlingbeee6222007-09-22 09:54:47 +0000603 <p>With llvm-gcc3, this will generate program and program.bc. The .bc
604 file is the LLVM version of the program all linked together.</p></li>
Chris Lattner7b1d3c02006-07-19 18:19:59 +0000605
Bill Wendlingbeee6222007-09-22 09:54:47 +0000606 <li><p>Convert the LLVM code to C code, using the LLC tool with the C
607 backend:</p>
Chris Lattner7b1d3c02006-07-19 18:19:59 +0000608
Bill Wendling2c22fcb2007-05-29 09:24:33 +0000609<div class="doc_code">
610<pre>
611% llc -march=c program.bc -o program.c
612</pre>
Bill Wendlingbeee6222007-09-22 09:54:47 +0000613</div></li>
Chris Lattner7b1d3c02006-07-19 18:19:59 +0000614
Bill Wendlingbeee6222007-09-22 09:54:47 +0000615<li><p>Finally, compile the C file:</p>
Chris Lattner7b1d3c02006-07-19 18:19:59 +0000616
Bill Wendling2c22fcb2007-05-29 09:24:33 +0000617<div class="doc_code">
618<pre>
619% cc x.c
620</pre>
Bill Wendlingbeee6222007-09-22 09:54:47 +0000621</div></li>
Chris Lattner7b1d3c02006-07-19 18:19:59 +0000622
623</ol>
624
Bill Wendlingbeee6222007-09-22 09:54:47 +0000625<p>Note that, by default, the C backend does not support exception handling. If
626you want/need it for a certain program, you can enable it by passing
627"-enable-correct-eh-support" to the llc program. The resultant code will use
628setjmp/longjmp to implement exception support that is correct but relatively
629slow.</p>
Chris Lattnerb0961902006-08-31 04:26:31 +0000630
Bill Wendlingbeee6222007-09-22 09:54:47 +0000631<p>Also note: this specific sequence of commands won't work if you use a
632function defined in the C++ runtime library (or any other C++ library). To
633access an external C++ library, you must manually compile libstdc++ to LLVM
634bitcode, statically link it into your program, then use the commands above to
635convert the whole result into C code. Alternatively, you can compile the
636libraries and your application into two different chunks of C code and link
637them.</p>
Chris Lattnerb0961902006-08-31 04:26:31 +0000638
Chris Lattner7b1d3c02006-07-19 18:19:59 +0000639</div>
640
Chris Lattner23353312003-11-19 05:53:12 +0000641<!-- *********************************************************************** -->
642<div class="doc_section">
643 <a name="cfe_code">Questions about code generated by the GCC front-end</a>
644</div>
645
Misha Brukman8d9a83a2004-12-03 23:58:18 +0000646<div class="question">
Chris Lattner37d55472005-02-25 20:30:21 +0000647<a name="iosinit"></a>
Misha Brukman8d9a83a2004-12-03 23:58:18 +0000648<p> What is this <tt>llvm.global_ctors</tt> and
649<tt>_GLOBAL__I__tmp_webcompile...</tt> stuff that happens when I #include
650&lt;iostream&gt;?</p>
651</div>
Chris Lattner87d6b402004-03-29 19:14:35 +0000652
653<div class="answer">
Misha Brukman8d9a83a2004-12-03 23:58:18 +0000654
655<p>If you #include the &lt;iostream&gt; header into a C++ translation unit, the
Chris Lattner87d6b402004-03-29 19:14:35 +0000656file will probably use the <tt>std::cin</tt>/<tt>std::cout</tt>/... global
657objects. However, C++ does not guarantee an order of initialization between
658static objects in different translation units, so if a static ctor/dtor in your
659.cpp file used <tt>std::cout</tt>, for example, the object would not necessarily
Misha Brukman8d9a83a2004-12-03 23:58:18 +0000660be automatically initialized before your use.</p>
Chris Lattner87d6b402004-03-29 19:14:35 +0000661
Misha Brukman8d9a83a2004-12-03 23:58:18 +0000662<p>To make <tt>std::cout</tt> and friends work correctly in these scenarios, the
Chris Lattner87d6b402004-03-29 19:14:35 +0000663STL that we use declares a static object that gets created in every translation
Misha Brukman8d9a83a2004-12-03 23:58:18 +0000664unit that includes <tt>&lt;iostream&gt;</tt>. This object has a static
665constructor and destructor that initializes and destroys the global iostream
666objects before they could possibly be used in the file. The code that you see
667in the .ll file corresponds to the constructor and destructor registration code.
Chris Lattner87d6b402004-03-29 19:14:35 +0000668</p>
669
Misha Brukman8d9a83a2004-12-03 23:58:18 +0000670<p>If you would like to make it easier to <b>understand</b> the LLVM code
671generated by the compiler in the demo page, consider using <tt>printf()</tt>
672instead of <tt>iostream</tt>s to print values.</p>
673
Chris Lattner87d6b402004-03-29 19:14:35 +0000674</div>
675
Chris Lattner37d55472005-02-25 20:30:21 +0000676<!--=========================================================================-->
677
678<div class="question"><p>
679<a name="codedce"></a>
680Where did all of my code go??
681</p></div>
682
683<div class="answer">
684<p>
685If you are using the LLVM demo page, you may often wonder what happened to all
686of the code that you typed in. Remember that the demo script is running the
687code through the LLVM optimizers, so if your code doesn't actually do anything
688useful, it might all be deleted.
689</p>
690
691<p>
692To prevent this, make sure that the code is actually needed. For example, if
693you are computing some expression, return the value from the function instead of
694leaving it in a local variable. If you really want to constrain the optimizer,
695you can read from and assign to <tt>volatile</tt> global variables.
696</p>
697</div>
698
699<!--=========================================================================-->
700
701<div class="question"><p>
702<a name="undef"></a>
703<p>What is this "<tt>undef</tt>" thing that shows up in my code?
704</p></div>
705
706<div class="answer">
707<p>
708<a href="LangRef.html#undef"><tt>undef</tt></a> is the LLVM way of representing
709a value that is not defined. You can get these if you do not initialize a
710variable before you use it. For example, the C function:</p>
711
712<div class="doc_code">
Bill Wendling2c22fcb2007-05-29 09:24:33 +0000713<pre>
714int X() { int i; return i; }
715</pre>
Chris Lattner37d55472005-02-25 20:30:21 +0000716</div>
717
Bill Wendling2c22fcb2007-05-29 09:24:33 +0000718<p>Is compiled to "<tt>ret i32 undef</tt>" because "<tt>i</tt>" never has
719a value specified for it.</p>
Chris Lattner37d55472005-02-25 20:30:21 +0000720</div>
721
John Criswell5e0f07e2003-11-18 16:05:23 +0000722<!-- *********************************************************************** -->
John Criswell8af73202003-10-13 16:13:06 +0000723
724<hr>
Misha Brukman5363e382004-06-01 18:51:03 +0000725<address>
726 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
727 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
728 <a href="http://validator.w3.org/check/referer"><img
729 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a>
730
Reid Spencerca058542006-03-14 05:39:39 +0000731 <a href="http://llvm.org">LLVM Compiler Infrastructure</a><br>
Misha Brukman6c91a332003-11-06 21:55:44 +0000732 Last modified: $Date$
Misha Brukman5363e382004-06-01 18:51:03 +0000733</address>
John Criswellebe140b2003-10-24 22:48:20 +0000734
John Criswell8af73202003-10-13 16:13:06 +0000735</body>
736</html>