blob: 62a5046c107245c4d5a22a3977a1a16e75ba3693 [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>
Misha Brukmana6538852003-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>
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
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 Lattner306acee2003-12-22 04:06:12 +000050 <li>Compiling LLVM with GCC 3.3.2 fails, what should I do?</li>
John Criswelld1799612004-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>
Misha Brukman1739aec2004-09-09 16:36:47 +000053 <li>After CVS update, rebuilding gives the error "No rule to make
54 target".</li>
Misha Brukmana6538852003-11-06 21:55:44 +000055 </ol></li>
John Criswell76c1e382003-11-18 16:08:49 +000056
Reid Spencer501bfee2006-04-26 14:52:19 +000057 <li><a href="#felangs">Source Languages</a>
58 <ol>
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>
Reid Spencere00906f2006-08-10 20:15:58 +000062 <li><a href="GetElementPtr.html">I don't understand the GetElementPtr
63 instruction. Help!</a></li>
Reid Spencer501bfee2006-04-26 14:52:19 +000064 </ol>
65
Chris Lattnercc33d702003-11-19 05:53:12 +000066 <li><a href="#cfe">Using the GCC Front End</a>
John Criswell76c1e382003-11-18 16:08:49 +000067 <ol>
68 <li>
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?
72 </li>
73
74 <li>
75 When I compile code using the LLVM GCC front end, it complains that it
Chris Lattner7911ce22004-05-23 21:07:27 +000076 cannot find libcrtend.a.
John Criswell76c1e382003-11-18 16:08:49 +000077 </li>
Tanya Lattner14fc5c12005-04-25 20:36:56 +000078
79 <li>
80 How can I disable all optimizations when compiling code using the LLVM GCC front end?
81 </li>
82
Chris Lattneraf7fd202006-07-19 18:19:59 +000083 <li><a href="#translatec++">Can I use LLVM to convert C++ code to C code?</a></li>
84
John Criswell76c1e382003-11-18 16:08:49 +000085 </ol>
86 </li>
Chris Lattnercc33d702003-11-19 05:53:12 +000087
88 <li><a href="#cfe_code">Questions about code generated by the GCC front-end</a>
89 <ol>
Chris Lattner5a53c5d2005-02-25 20:30:21 +000090 <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
Chris Lattnerc50bbc92004-03-29 19:14:35 +000093 <tt>_GLOBAL__I__tmp_webcompile...</tt> stuff that happens when I
Chris Lattner5a53c5d2005-02-25 20:30:21 +000094 #include &lt;iostream&gt;?</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>
Chris Lattnercc33d702003-11-19 05:53:12 +000097 </ol>
98 </li>
Misha Brukmana6538852003-11-06 21:55:44 +000099</ol>
100
Chris Lattner7911ce22004-05-23 21:07:27 +0000101<div class="doc_author">
Reid Spencer05fe4b02006-03-14 05:39:39 +0000102 <p>Written by <a href="http://llvm.org">The LLVM Team</a></p>
Chris Lattner7911ce22004-05-23 21:07:27 +0000103</div>
104
105
Misha Brukmana6538852003-11-06 21:55:44 +0000106<!-- *********************************************************************** -->
107<div class="doc_section">
108 <a name="license">License</a>
109</div>
110<!-- *********************************************************************** -->
111
112<div class="question">
113<p>Why are the LLVM source code and the front-end distributed under different
114licenses?</p>
115</div>
116
117<div class="answer">
118<p>The C/C++ front-ends are based on GCC and must be distributed under the GPL.
119Our aim is to distribute LLVM source code under a <em>much less restrictive</em>
120license, in particular one that does not compel users who distribute tools based
121on modifying the source to redistribute the modified source code as well.</p>
122</div>
123
124<div class="question">
125<p>Does the University of Illinois Open Source License really qualify as an
126"open source" license?</p>
127</div>
128
129<div class="answer">
130<p>Yes, the license is <a
131href="http://www.opensource.org/licenses/UoI-NCSA.php">certified</a> by the Open
132Source Initiative (OSI).</p>
133</div>
134
135<div class="question">
136<p>Can I modify LLVM source code and redistribute the modified source?</p>
137</div>
138
139<div class="answer">
140<p>Yes. The modified source distribution must retain the copyright notice and
141follow the three bulletted conditions listed in the <a
Reid Spencer05fe4b02006-03-14 05:39:39 +0000142href="http://llvm.org/releases/1.3/LICENSE.TXT">LLVM license</a>.</p>
Misha Brukmana6538852003-11-06 21:55:44 +0000143</div>
144
145<div class="question">
146<p>Can I modify LLVM source code and redistribute binaries or other tools based
147on it, without redistributing the source?</p>
148</div>
149
150<div class="answer">
151<p>Yes, this is why we distribute LLVM under a less restrictive license than
152GPL, as explained in the first question above.</p>
153</div>
154
155<!-- *********************************************************************** -->
156<div class="doc_section">
157 <a name="source">Source Code</a>
158</div>
159<!-- *********************************************************************** -->
160
161<div class="question">
162<p>In what language is LLVM written?</p>
163</div>
164
165<div class="answer">
166<p>All of the LLVM tools and libraries are written in C++ with extensive use of
167the STL.</p>
168</div>
169
170<div class="question">
171<p>How portable is the LLVM source code?</p>
172</div>
173
174<div class="answer">
175<p>The LLVM source code should be portable to most modern UNIX-like operating
176systems. Most of the code is written in standard C++ with operating system
177services abstracted to a support library. The tools required to build and test
178LLVM have been ported to a plethora of platforms.</p>
179
180<p>Some porting problems may exist in the following areas:</p>
181
182<ul>
183
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>
186
Misha Brukmana6538852003-11-06 21:55:44 +0000187 <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>
190
191</ul>
192
193</div>
194
195<!-- *********************************************************************** -->
196<div class="doc_section">
197 <a name="build">Build Problems</a>
198</div>
199<!-- *********************************************************************** -->
200
201<div class="question">
202<p>When I run configure, it finds the wrong C compiler.</p>
203</div>
204
205<div class="answer">
206
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>
209for the C and C++ compiler, respectively.</p>
210
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>
213explicitly.</p>
214
215</div>
216
217<div class="question">
Misha Brukmana6538852003-11-06 21:55:44 +0000218<p>The <tt>configure</tt> script finds the right C compiler, but it uses the
219LLVM linker from a previous build. What do I do?</p>
220</div>
221
222<div class="answer">
223<p>The <tt>configure</tt> script uses the <tt>PATH</tt> to find executables, so
224if it's grabbing the wrong linker/assembler/etc, there are two ways to fix
225it:</p>
226
227<ol>
228
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
232 work.</p></li>
233
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>
236
Misha Brukman7ce62cc2004-06-01 18:51:03 +0000237 <p><tt>PATH=[the path without the bad program] ./configure ...</tt></p>
Misha Brukmana6538852003-11-06 21:55:44 +0000238
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>
242
243</ol>
244
245</div>
246
247<div class="question">
248<p>When creating a dynamic library, I get a strange GLIBC error.</p>
249</div>
250
251<div class="answer">
252<p>Under some operating systems (i.e. Linux), libtool does not work correctly if
253GCC was compiled with the --disable-shared option. To work around this, install
254your own version of GCC that has shared libraries enabled by default.</p>
255</div>
256
257<div class="question">
258<p>I've updated my source tree from CVS, and now my build is trying to use a
259file/directory that doesn't exist.</p>
260</div>
261
262<div class="answer">
263<p>You need to re-run configure in your object directory. When new Makefiles
264are added to the source tree, they have to be copied over to the object tree in
265order to be used by the build.</p>
266</div>
267
268<div class="question">
269<p>I've modified a Makefile in my source tree, but my build tree keeps using the
270old version. What do I do?</p>
271</div>
272
273<div class="answer">
274
275<p>If the Makefile already exists in your object tree, you
276can just run the following command in the top level directory of your object
277tree:</p>
278
279<p><tt>./config.status &lt;relative path to Makefile&gt;</tt><p>
280
281<p>If the Makefile is new, you will have to modify the configure script to copy
282it over.</p>
283
284</div>
285
286<div class="question">
287<p>I've upgraded to a new version of LLVM, and I get strange build errors.</p>
288</div>
289
290<div class="answer">
291
292<p>Sometimes, changes to the LLVM source code alters how the build system works.
293Changes in libtool, autoconf, or header file dependencies are especially prone
294to this sort of problem.</p>
295
296<p>The best thing to try is to remove the old files and re-build. In most
297cases, this takes care of the problem. To do this, just type <tt>make
298clean</tt> and then <tt>make</tt> in the directory that fails to build.</p>
299
300</div>
301
302<div class="question">
303<p>I've built LLVM and am testing it, but the tests freeze.</p>
304</div>
305
306<div class="answer">
307
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>
311
312<p>For example, if you built LLVM with the command:</p>
313
Bill Wendlingd6a68eb2007-05-29 09:24:33 +0000314<div class="doc_code">
315<pre>
316% gmake ENABLE_PROFILING=1
317</pre>
318</div>
Misha Brukmana6538852003-11-06 21:55:44 +0000319
320<p>...then you must run the tests with the following commands:</p>
321
Bill Wendlingd6a68eb2007-05-29 09:24:33 +0000322<div class="doc_code">
323<pre>
324% cd llvm/test
325% gmake ENABLE_PROFILING=1
326</pre>
327</div>
Misha Brukmana6538852003-11-06 21:55:44 +0000328
329</div>
330
331<div class="question">
332<p>Why do test results differ when I perform different types of builds?</p>
333</div>
334
335<div class="answer">
336
337<p>The LLVM test suite is dependent upon several features of the LLVM tools and
338libraries.</p>
339
340<p>First, the debugging assertions in code are not enabled in optimized or
341profiling builds. Hence, tests that used to fail may pass.</p>
342
343<p>Second, some tests may rely upon debugging options or behavior that is only
344available in the debug build. These tests will fail in an optimized or profile
345build.</p>
346
347</div>
348
Chris Lattner8a0b9242003-12-08 05:43:19 +0000349<div class="question">
Chris Lattner306acee2003-12-22 04:06:12 +0000350<p>Compiling LLVM with GCC 3.3.2 fails, what should I do?</p>
Chris Lattner8a0b9242003-12-08 05:43:19 +0000351</div>
352
353<div class="answer">
Chris Lattner306acee2003-12-22 04:06:12 +0000354<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>
Chris Lattner8a0b9242003-12-08 05:43:19 +0000356</div>
357
John Criswelld1799612004-03-29 20:23:11 +0000358<div class="question">
Misha Brukman1739aec2004-09-09 16:36:47 +0000359<p>After CVS update, rebuilding gives the error "No rule to make target".</p>
360</div>
361
362<div class="answer">
363<p>If the error is of the form:</p>
364
365<div class="doc_code">
Bill Wendlingd6a68eb2007-05-29 09:24:33 +0000366<pre>
Misha Brukman1739aec2004-09-09 16:36:47 +0000367gmake[2]: *** No rule to make target `/path/to/somefile', needed by
368`/path/to/another/file.d'.<br>
369Stop.
Bill Wendlingd6a68eb2007-05-29 09:24:33 +0000370</pre>
Misha Brukman1739aec2004-09-09 16:36:47 +0000371</div>
372
373<p>This may occur anytime files are moved within the CVS repository or removed
374entirely. In this case, the best solution is to erase all <tt>.d</tt> files,
375which list dependencies for source files, and rebuild:</p>
376
377<div class="doc_code">
378<pre>
379% cd $LLVM_OBJ_DIR
380% rm -f `find . -name \*\.d`
381% gmake
382</pre>
383</div>
384
385<p>In other cases, it may be necessary to run <tt>make clean</tt> before
386rebuilding.</p>
387</div>
388
Misha Brukmana6538852003-11-06 21:55:44 +0000389<!-- *********************************************************************** -->
Reid Spencerc87f4972006-04-26 15:46:53 +0000390<div class="doc_section"><a name="felangs">Source Languages</a></div>
Reid Spencer501bfee2006-04-26 14:52:19 +0000391
Reid Spencerc87f4972006-04-26 15:46:53 +0000392<div class="question"><p>
393 <a name="langs">What source languages are supported?</a></p>
394</div>
395<div class="answer">
Reid Spencer501bfee2006-04-26 14:52:19 +0000396 <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>
408</div>
Reid Spencerc87f4972006-04-26 15:46:53 +0000409<div class="question"><a name="langhlsupp">
Reid Spencer501bfee2006-04-26 14:52:19 +0000410 <p>What support is there for a higher level source language constructs for
Reid Spencerc87f4972006-04-26 15:46:53 +0000411 building a compiler?</a></p>
Reid Spencer501bfee2006-04-26 14:52:19 +0000412</div>
413<div class="answer">
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
Jeff Cohen7b8229a2006-04-26 21:03:17 +0000417 facilities for lexical nor semantic analysis. There is, however, a <i>mostly
Reid Spencer501bfee2006-04-26 14:52:19 +0000418 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>
Reid Spencer501bfee2006-04-26 14:52:19 +0000421</div>
Chris Lattner33bef482006-08-15 00:43:35 +0000422
423<div class="question"><a name="langhlsupp">
424 <p>I don't understand the GetElementPtr
425 instruction. Help!</a></p>
426</div>
427<div class="answer">
428 <p>See <a href="GetElementPtr.html">The Often Misunderstood GEP
429 Instruction</a>.</li>
430</div>
431
Reid Spencer501bfee2006-04-26 14:52:19 +0000432<!-- *********************************************************************** -->
433<div class="doc_section">
Chris Lattnercc33d702003-11-19 05:53:12 +0000434 <a name="cfe">Using the GCC Front End</a>
John Criswell6ea30b02003-11-18 16:05:23 +0000435</div>
436
437<div class="question">
438<p>
439When I compile software that uses a configure script, the configure script
440thinks my system has all of the header files and libraries it is testing for.
441How do I get configure to work correctly?
442</p>
443</div>
444
445<div class="answer">
446<p>
447The configure script is getting things wrong because the LLVM linker allows
448symbols to be undefined at link time (so that they can be resolved during JIT
449or translation to the C back end). That is why configure thinks your system
450"has everything."
451</p>
452<p>
453To work around this, perform the following steps:
454</p>
John Criswell6ea30b02003-11-18 16:05:23 +0000455<ol>
Reid Spencer434262a2007-02-09 15:59:08 +0000456 <li>Make sure the CC and CXX environment variables contains the full path to
457 the LLVM GCC front end.</li>
John Criswell6ea30b02003-11-18 16:05:23 +0000458
Reid Spencer434262a2007-02-09 15:59:08 +0000459 <li>Make sure that the regular C compiler is first in your PATH. </li>
John Criswell6ea30b02003-11-18 16:05:23 +0000460
Reid Spencer434262a2007-02-09 15:59:08 +0000461 <li>Add the string "-Wl,-native" to your CFLAGS environment variable.</li>
John Criswell6ea30b02003-11-18 16:05:23 +0000462</ol>
463
464<p>
Reid Spencer434262a2007-02-09 15:59:08 +0000465This will allow the <tt>llvm-ld</tt> linker to create a native code executable
466instead of shell script that runs the JIT. Creating native code requires
467standard linkage, which in turn will allow the configure script to find out if
468code is not linking on your system because the feature isn't available on your
469system.</p>
John Criswell6ea30b02003-11-18 16:05:23 +0000470</div>
471
Chris Lattnercc33d702003-11-19 05:53:12 +0000472<div class="question">
John Criswell6ea30b02003-11-18 16:05:23 +0000473<p>
474When I compile code using the LLVM GCC front end, it complains that it cannot
John Criswellcd161192004-03-12 18:20:15 +0000475find libcrtend.a.
John Criswell6ea30b02003-11-18 16:05:23 +0000476</p>
477</div>
478
Chris Lattnercc33d702003-11-19 05:53:12 +0000479<div class="answer">
John Criswell6ea30b02003-11-18 16:05:23 +0000480<p>
Reid Spencerf96eb572004-12-15 00:14:01 +0000481The only way this can happen is if you haven't installed the runtime library. To
482correct this, do:</p>
Bill Wendlingd6a68eb2007-05-29 09:24:33 +0000483
484<div class="doc_code">
Reid Spencerf96eb572004-12-15 00:14:01 +0000485<pre>
Bill Wendlingd6a68eb2007-05-29 09:24:33 +0000486% cd llvm/runtime
487% make clean ; make install-bytecode
Reid Spencerf96eb572004-12-15 00:14:01 +0000488</pre>
John Criswell6ea30b02003-11-18 16:05:23 +0000489</div>
Bill Wendlingd6a68eb2007-05-29 09:24:33 +0000490</div>
Chris Lattnercc33d702003-11-19 05:53:12 +0000491
Tanya Lattner14fc5c12005-04-25 20:36:56 +0000492<div class="question">
493<p>
494How can I disable all optimizations when compiling code using the LLVM GCC front end?
495</p>
496</div>
497
498<div class="answer">
499<p>
500Passing "-Wa,-disable-opt -Wl,-disable-opt" will disable *all* cleanup and
501optimizations done at the llvm level, leaving you with the truly horrible
502code that you desire.
503</p>
504</div>
Chris Lattnercc33d702003-11-19 05:53:12 +0000505
Chris Lattneraf7fd202006-07-19 18:19:59 +0000506
507<div class="question">
508<p>
509<a name="translatec++">Can I use LLVM to convert C++ code to C code?</a>
510</p>
511</div>
512
513<div class="answer">
514<p>Yes, you can use LLVM to convert code from any language LLVM supports to C.
515Note that the generated C code will be very low level (all loops are lowered
516to gotos, etc) and not very pretty (comments are stripped, original source
517formatting is totally lost, variables are renamed, expressions are regrouped),
518so this may not be what you're looking for. However, this is a good way to add
519C++ support for a processor that does not otherwise have a C++ compiler.
520</p>
521
522<p>Use commands like this:</p>
523
524<ol>
525<li><p>Compile your program as normal with llvm-g++:</p></li>
526
Bill Wendlingd6a68eb2007-05-29 09:24:33 +0000527<div class="doc_code">
528<pre>
529% llvm-g++ x.cpp -o program
530</pre>
531</div>
Chris Lattneraf7fd202006-07-19 18:19:59 +0000532
533<p>or:</p>
534
535<div class="doc_code">
Bill Wendlingd6a68eb2007-05-29 09:24:33 +0000536<pre>
537% llvm-g++ a.cpp -c
538% llvm-g++ b.cpp -c
539% llvm-g++ a.o b.o -o program
540</pre>
Chris Lattneraf7fd202006-07-19 18:19:59 +0000541</div>
542
543<p>With llvm-gcc3, this will generate program and program.bc. The .bc file is
544the LLVM version of the program all linked together.</p>
545
546<li><p>Convert the LLVM code to C code, using the LLC tool with the C
547backend:</p></li>
548
Bill Wendlingd6a68eb2007-05-29 09:24:33 +0000549<div class="doc_code">
550<pre>
551% llc -march=c program.bc -o program.c
552</pre>
553</div>
Chris Lattneraf7fd202006-07-19 18:19:59 +0000554
555<li><p>Finally, compile the c file:</p></li>
556
Bill Wendlingd6a68eb2007-05-29 09:24:33 +0000557<div class="doc_code">
558<pre>
559% cc x.c
560</pre>
561</div>
Chris Lattneraf7fd202006-07-19 18:19:59 +0000562
563</ol>
564
565<p>Note that, by default, the C backend does not support exception handling.
566If 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
568use setjmp/longjmp to implement exception support that is correct but
569relatively slow.
570</p>
Chris Lattnerb495fb02006-08-31 04:26:31 +0000571
572<p>Also note: this specific sequence of commands won't work if you use a
573function defined in the C++ runtime library (or any other C++ library). To
574access an external C++ library, you must manually
575compile libstdc++ to LLVM bytecode, statically link it into your program, then
576use the commands above to convert the whole result into C code. Alternatively,
577you can compile the libraries and your application into two different chunks
578of C code and link them.</p>
579
Chris Lattneraf7fd202006-07-19 18:19:59 +0000580</div>
581
582
583
Chris Lattnercc33d702003-11-19 05:53:12 +0000584<!-- *********************************************************************** -->
585<div class="doc_section">
586 <a name="cfe_code">Questions about code generated by the GCC front-end</a>
587</div>
588
Chris Lattnera28e3ce2003-12-16 22:33:55 +0000589<div class="question"><p>
Chris Lattner5a53c5d2005-02-25 20:30:21 +0000590<a name="__main"></a>
Chris Lattnercc33d702003-11-19 05:53:12 +0000591What is this <tt>__main()</tt> call that gets inserted into <tt>main()</tt>?
Chris Lattnera28e3ce2003-12-16 22:33:55 +0000592</p></div>
Chris Lattnercc33d702003-11-19 05:53:12 +0000593
594<div class="answer">
595<p>
596The <tt>__main</tt> call is inserted by the C/C++ compiler in order to guarantee
597that static constructors and destructors are called when the program starts up
598and shuts down. In C, you can create static constructors and destructors by
599using GCC extensions, and in C++ you can do so by creating a global variable
600whose class has a ctor or dtor.
601</p>
602
603<p>
604The actual implementation of <tt>__main</tt> lives in the
605<tt>llvm/runtime/GCCLibraries/crtend/</tt> directory in the source-base, and is
606linked in automatically when you link the program.
607</p>
Chris Lattnercc33d702003-11-19 05:53:12 +0000608</div>
609
Chris Lattnera28e3ce2003-12-16 22:33:55 +0000610<!--=========================================================================-->
Chris Lattnercc33d702003-11-19 05:53:12 +0000611
Misha Brukman237dc2a2004-12-03 23:58:18 +0000612<div class="question">
Chris Lattner5a53c5d2005-02-25 20:30:21 +0000613<a name="iosinit"></a>
Misha Brukman237dc2a2004-12-03 23:58:18 +0000614<p> What is this <tt>llvm.global_ctors</tt> and
615<tt>_GLOBAL__I__tmp_webcompile...</tt> stuff that happens when I #include
616&lt;iostream&gt;?</p>
617</div>
Chris Lattnerc50bbc92004-03-29 19:14:35 +0000618
619<div class="answer">
Misha Brukman237dc2a2004-12-03 23:58:18 +0000620
621<p>If you #include the &lt;iostream&gt; header into a C++ translation unit, the
Chris Lattnerc50bbc92004-03-29 19:14:35 +0000622file will probably use the <tt>std::cin</tt>/<tt>std::cout</tt>/... global
623objects. However, C++ does not guarantee an order of initialization between
624static 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
Misha Brukman237dc2a2004-12-03 23:58:18 +0000626be automatically initialized before your use.</p>
Chris Lattnerc50bbc92004-03-29 19:14:35 +0000627
Misha Brukman237dc2a2004-12-03 23:58:18 +0000628<p>To make <tt>std::cout</tt> and friends work correctly in these scenarios, the
Chris Lattnerc50bbc92004-03-29 19:14:35 +0000629STL that we use declares a static object that gets created in every translation
Misha Brukman237dc2a2004-12-03 23:58:18 +0000630unit that includes <tt>&lt;iostream&gt;</tt>. This object has a static
631constructor and destructor that initializes and destroys the global iostream
632objects before they could possibly be used in the file. The code that you see
633in the .ll file corresponds to the constructor and destructor registration code.
Chris Lattnerc50bbc92004-03-29 19:14:35 +0000634</p>
635
Misha Brukman237dc2a2004-12-03 23:58:18 +0000636<p>If you would like to make it easier to <b>understand</b> the LLVM code
637generated by the compiler in the demo page, consider using <tt>printf()</tt>
638instead of <tt>iostream</tt>s to print values.</p>
639
Chris Lattnerc50bbc92004-03-29 19:14:35 +0000640</div>
641
Chris Lattner5a53c5d2005-02-25 20:30:21 +0000642<!--=========================================================================-->
643
644<div class="question"><p>
645<a name="codedce"></a>
646Where did all of my code go??
647</p></div>
648
649<div class="answer">
650<p>
651If you are using the LLVM demo page, you may often wonder what happened to all
652of the code that you typed in. Remember that the demo script is running the
653code through the LLVM optimizers, so if your code doesn't actually do anything
654useful, it might all be deleted.
655</p>
656
657<p>
658To prevent this, make sure that the code is actually needed. For example, if
659you are computing some expression, return the value from the function instead of
660leaving it in a local variable. If you really want to constrain the optimizer,
661you can read from and assign to <tt>volatile</tt> global variables.
662</p>
663</div>
664
665<!--=========================================================================-->
666
667<div class="question"><p>
668<a name="undef"></a>
669<p>What is this "<tt>undef</tt>" thing that shows up in my code?
670</p></div>
671
672<div class="answer">
673<p>
674<a href="LangRef.html#undef"><tt>undef</tt></a> is the LLVM way of representing
675a value that is not defined. You can get these if you do not initialize a
676variable before you use it. For example, the C function:</p>
677
678<div class="doc_code">
Bill Wendlingd6a68eb2007-05-29 09:24:33 +0000679<pre>
680int X() { int i; return i; }
681</pre>
Chris Lattner5a53c5d2005-02-25 20:30:21 +0000682</div>
683
Bill Wendlingd6a68eb2007-05-29 09:24:33 +0000684<p>Is compiled to "<tt>ret i32 undef</tt>" because "<tt>i</tt>" never has
685a value specified for it.</p>
Chris Lattner5a53c5d2005-02-25 20:30:21 +0000686</div>
687
John Criswell6ea30b02003-11-18 16:05:23 +0000688<!-- *********************************************************************** -->
John Criswellc310f622003-10-13 16:13:06 +0000689
690<hr>
Misha Brukman7ce62cc2004-06-01 18:51:03 +0000691<address>
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>
696
Reid Spencer05fe4b02006-03-14 05:39:39 +0000697 <a href="http://llvm.org">LLVM Compiler Infrastructure</a><br>
Misha Brukmana6538852003-11-06 21:55:44 +0000698 Last modified: $Date$
Misha Brukman7ce62cc2004-06-01 18:51:03 +0000699</address>
John Criswellf08c5d82003-10-24 22:48:20 +0000700
John Criswellc310f622003-10-13 16:13:06 +0000701</body>
702</html>