| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 1 | <!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 Brukman | 7ce62cc | 2004-06-01 18:51:03 +0000 | [diff] [blame] | 6 |   <style type="text/css"> | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 7 |     @import url("llvm.css"); | 
 | 8 |     .question { font-weight: bold } | 
 | 9 |     .answer   { margin-left: 2em  } | 
 | 10 |   </style> | 
 | 11 | </head> | 
 | 12 | <body> | 
| John Criswell | c310f62 | 2003-10-13 16:13:06 +0000 | [diff] [blame] | 13 |  | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 14 | <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 Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 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> | 
| Reid Spencer | 669ed45 | 2007-07-09 08:04:31 +0000 | [diff] [blame] | 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> | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 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 Lattner | 306acee | 2003-12-22 04:06:12 +0000 | [diff] [blame] | 50 |   <li>Compiling LLVM with GCC 3.3.2 fails, what should I do?</li> | 
| John Criswell | d179961 | 2004-03-29 20:23:11 +0000 | [diff] [blame] | 51 |   <li>When I use the test suite, all of the C Backend tests fail.  What is | 
 | 52 |       wrong?</li> | 
| Reid Spencer | 669ed45 | 2007-07-09 08:04:31 +0000 | [diff] [blame] | 53 |   <li>After Subversion update, rebuilding gives the error "No rule to make | 
| Bill Wendling | 174d578 | 2007-05-29 09:35:34 +0000 | [diff] [blame] | 54 |       target".</li> | 
 | 55 |   <li><a href="#llvmc">The <tt>llvmc</tt> program gives me errors/doesn't | 
| Bill Wendling | e9a6c35 | 2007-09-22 09:54:47 +0000 | [diff] [blame] | 56 |       work.</a></li> | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 57 |   </ol></li> | 
| John Criswell | 76c1e38 | 2003-11-18 16:08:49 +0000 | [diff] [blame] | 58 |  | 
| Reid Spencer | 501bfee | 2006-04-26 14:52:19 +0000 | [diff] [blame] | 59 |   <li><a href="#felangs">Source Languages</a> | 
 | 60 |   <ol> | 
 | 61 |     <li><a href="#langs">What source languages are supported?</a></li> | 
| Gordon Henriksen | e507905 | 2008-02-22 21:55:51 +0000 | [diff] [blame] | 62 |     <li><a href="#langirgen">I'd like to write a self-hosting LLVM compiler. How | 
 | 63 |       should I interface with the LLVM middle-end optimizers and back-end code  | 
| Dan Gohman | f003276 | 2008-11-24 17:18:39 +0000 | [diff] [blame] | 64 |       generators?</a></li> | 
| Reid Spencer | 501bfee | 2006-04-26 14:52:19 +0000 | [diff] [blame] | 65 |     <li><a href="#langhlsupp">What support is there for higher level source | 
 | 66 |       language constructs for building a compiler?</a></li> | 
| Reid Spencer | e00906f | 2006-08-10 20:15:58 +0000 | [diff] [blame] | 67 |     <li><a href="GetElementPtr.html">I don't understand the GetElementPtr | 
 | 68 |       instruction. Help!</a></li> | 
| Reid Spencer | 501bfee | 2006-04-26 14:52:19 +0000 | [diff] [blame] | 69 |   </ol> | 
 | 70 |  | 
| Chris Lattner | cc33d70 | 2003-11-19 05:53:12 +0000 | [diff] [blame] | 71 |   <li><a href="#cfe">Using the GCC Front End</a> | 
| John Criswell | 76c1e38 | 2003-11-18 16:08:49 +0000 | [diff] [blame] | 72 |   <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 Lattner | 7911ce2 | 2004-05-23 21:07:27 +0000 | [diff] [blame] | 81 |     cannot find libcrtend.a. | 
| John Criswell | 76c1e38 | 2003-11-18 16:08:49 +0000 | [diff] [blame] | 82 |     </li> | 
| Tanya Lattner | 14fc5c1 | 2005-04-25 20:36:56 +0000 | [diff] [blame] | 83 |  | 
 | 84 |     <li> | 
 | 85 |     How can I disable all optimizations when compiling code using the LLVM GCC front end? | 
 | 86 |     </li> | 
 | 87 |  | 
| Dan Gohman | f003276 | 2008-11-24 17:18:39 +0000 | [diff] [blame] | 88 |     <li><a href="#translatecxx">Can I use LLVM to convert C++ code to C code?</a></li> | 
| Chris Lattner | af7fd20 | 2006-07-19 18:19:59 +0000 | [diff] [blame] | 89 |  | 
| John Criswell | 76c1e38 | 2003-11-18 16:08:49 +0000 | [diff] [blame] | 90 |   </ol> | 
 | 91 |   </li> | 
| Chris Lattner | cc33d70 | 2003-11-19 05:53:12 +0000 | [diff] [blame] | 92 |  | 
 | 93 |   <li><a href="#cfe_code">Questions about code generated by the GCC front-end</a> | 
 | 94 |   <ol> | 
| Chris Lattner | 5a53c5d | 2005-02-25 20:30:21 +0000 | [diff] [blame] | 95 |      <li><a href="#iosinit">What is this <tt>llvm.global_ctors</tt> and | 
| Chris Lattner | c50bbc9 | 2004-03-29 19:14:35 +0000 | [diff] [blame] | 96 |           <tt>_GLOBAL__I__tmp_webcompile...</tt> stuff that happens when I | 
| Chris Lattner | 5a53c5d | 2005-02-25 20:30:21 +0000 | [diff] [blame] | 97 |           #include <iostream>?</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 Lattner | cc33d70 | 2003-11-19 05:53:12 +0000 | [diff] [blame] | 100 |   </ol> | 
 | 101 |   </li> | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 102 | </ol> | 
 | 103 |  | 
| Chris Lattner | 7911ce2 | 2004-05-23 21:07:27 +0000 | [diff] [blame] | 104 | <div class="doc_author"> | 
| Reid Spencer | 05fe4b0 | 2006-03-14 05:39:39 +0000 | [diff] [blame] | 105 |   <p>Written by <a href="http://llvm.org">The LLVM Team</a></p> | 
| Chris Lattner | 7911ce2 | 2004-05-23 21:07:27 +0000 | [diff] [blame] | 106 | </div> | 
 | 107 |  | 
 | 108 |  | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 109 | <!-- *********************************************************************** --> | 
 | 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 | 
 | 117 | licenses?</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. | 
 | 122 | Our aim is to distribute LLVM source code under a <em>much less restrictive</em> | 
 | 123 | license, in particular one that does not compel users who distribute tools based | 
 | 124 | on 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 | 
 | 134 | href="http://www.opensource.org/licenses/UoI-NCSA.php">certified</a> by the Open | 
 | 135 | Source 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 | 
 | 144 | follow the three bulletted conditions listed in the <a | 
| Misha Brukman | b610655 | 2008-12-17 18:06:53 +0000 | [diff] [blame] | 145 | href="http://llvm.org/svn/llvm-project/llvm/trunk/LICENSE.TXT">LLVM license</a>.</p> | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 146 | </div> | 
 | 147 |  | 
 | 148 | <div class="question"> | 
 | 149 | <p>Can I modify LLVM source code and redistribute binaries or other tools based | 
 | 150 | on 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 | 
 | 155 | GPL, 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 | 
 | 170 | the 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 | 
 | 179 | systems.  Most of the code is written in standard C++ with operating system | 
 | 180 | services abstracted to a support library.  The tools required to build and test | 
 | 181 | LLVM 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 Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 186 |   <li>The GCC front end code is not as portable as the LLVM suite, so it may not | 
| Bill Wendling | e9a6c35 | 2007-09-22 09:54:47 +0000 | [diff] [blame] | 187 |       compile as well on unsupported platforms.</li> | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 188 |  | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 189 |   <li>The LLVM build system relies heavily on UNIX shell tools, like the Bourne | 
| Bill Wendling | e9a6c35 | 2007-09-22 09:54:47 +0000 | [diff] [blame] | 190 |       Shell and sed.  Porting to systems without these tools (MacOS 9, Plan 9) | 
 | 191 |       will require more effort.</li> | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 192 | </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> | 
 | 210 | for 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> | 
 | 214 | explicitly.</p> | 
 | 215 |  | 
 | 216 | </div> | 
 | 217 |  | 
 | 218 | <div class="question"> | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 219 | <p>The <tt>configure</tt> script finds the right C compiler, but it uses the | 
 | 220 | LLVM 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 | 
 | 225 | if it's grabbing the wrong linker/assembler/etc, there are two ways to fix | 
 | 226 | it:</p> | 
 | 227 |  | 
 | 228 | <ol> | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 229 |   <li><p>Adjust your <tt>PATH</tt> environment variable so that the correct | 
| Bill Wendling | e9a6c35 | 2007-09-22 09:54:47 +0000 | [diff] [blame] | 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> | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 233 |  | 
 | 234 |   <li><p>Run <tt>configure</tt> with an alternative <tt>PATH</tt> that is | 
| Bill Wendling | e9a6c35 | 2007-09-22 09:54:47 +0000 | [diff] [blame] | 235 |       correct. In a Borne compatible shell, the syntax would be:</p> | 
 | 236 |  | 
| Misha Brukman | a54d4b2 | 2008-12-17 18:11:40 +0000 | [diff] [blame^] | 237 | <pre class="doc_code"> | 
| Bill Wendling | e9a6c35 | 2007-09-22 09:54:47 +0000 | [diff] [blame] | 238 | % PATH=[the path without the bad program] ./configure ... | 
 | 239 | </pre> | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 240 |  | 
 | 241 |       <p>This is still somewhat inconvenient, but it allows <tt>configure</tt> | 
| Bill Wendling | e9a6c35 | 2007-09-22 09:54:47 +0000 | [diff] [blame] | 242 |          to do its work without having to adjust your <tt>PATH</tt> | 
 | 243 |          permanently.</p></li> | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 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 | 
 | 254 | GCC was compiled with the --disable-shared option.  To work around this, install | 
 | 255 | your own version of GCC that has shared libraries enabled by default.</p> | 
 | 256 | </div> | 
 | 257 |  | 
 | 258 | <div class="question"> | 
| Bill Wendling | e9a6c35 | 2007-09-22 09:54:47 +0000 | [diff] [blame] | 259 | <p>I've updated my source tree from Subversion, and now my build is trying to  | 
 | 260 | use a file/directory that doesn't exist.</p> | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 261 | </div> | 
 | 262 |  | 
 | 263 | <div class="answer"> | 
 | 264 | <p>You need to re-run configure in your object directory.  When new Makefiles | 
 | 265 | are added to the source tree, they have to be copied over to the object tree in | 
 | 266 | order 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 | 
 | 271 | old version.  What do I do?</p> | 
 | 272 | </div> | 
 | 273 |  | 
 | 274 | <div class="answer"> | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 275 | <p>If the Makefile already exists in your object tree, you | 
 | 276 | can just run the following command in the top level directory of your object | 
 | 277 | tree:</p> | 
 | 278 |  | 
| Misha Brukman | a54d4b2 | 2008-12-17 18:11:40 +0000 | [diff] [blame^] | 279 | <pre class="doc_code"> | 
 | 280 | % ./config.status <relative path to Makefile> | 
 | 281 | </pre> | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 282 |  | 
 | 283 | <p>If the Makefile is new, you will have to modify the configure script to copy | 
 | 284 | it over.</p> | 
 | 285 |  | 
 | 286 | </div> | 
 | 287 |  | 
 | 288 | <div class="question"> | 
 | 289 | <p>I've upgraded to a new version of LLVM, and I get strange build errors.</p> | 
 | 290 | </div> | 
 | 291 |  | 
 | 292 | <div class="answer"> | 
 | 293 |  | 
 | 294 | <p>Sometimes, changes to the LLVM source code alters how the build system works. | 
 | 295 | Changes in libtool, autoconf, or header file dependencies are especially prone | 
 | 296 | to this sort of problem.</p> | 
 | 297 |  | 
 | 298 | <p>The best thing to try is to remove the old files and re-build.  In most | 
 | 299 | cases, this takes care of the problem.  To do this, just type <tt>make | 
 | 300 | clean</tt> and then <tt>make</tt> in the directory that fails to build.</p> | 
 | 301 |  | 
 | 302 | </div> | 
 | 303 |  | 
 | 304 | <div class="question"> | 
 | 305 | <p>I've built LLVM and am testing it, but the tests freeze.</p> | 
 | 306 | </div> | 
 | 307 |  | 
 | 308 | <div class="answer"> | 
 | 309 |  | 
 | 310 | <p>This is most likely occurring because you built a profile or release | 
 | 311 | (optimized) build of LLVM and have not specified the same information on the | 
 | 312 | <tt>gmake</tt> command line.</p> | 
 | 313 |  | 
 | 314 | <p>For example, if you built LLVM with the command:</p> | 
 | 315 |  | 
| Misha Brukman | a54d4b2 | 2008-12-17 18:11:40 +0000 | [diff] [blame^] | 316 | <pre class="doc_code"> | 
 | 317 | % gmake ENABLE_PROFILING=1 | 
 | 318 | </pre> | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 319 |  | 
 | 320 | <p>...then you must run the tests with the following commands:</p> | 
 | 321 |  | 
| Misha Brukman | a54d4b2 | 2008-12-17 18:11:40 +0000 | [diff] [blame^] | 322 | <pre class="doc_code"> | 
| Bill Wendling | d6a68eb | 2007-05-29 09:24:33 +0000 | [diff] [blame] | 323 | % cd llvm/test | 
 | 324 | % gmake ENABLE_PROFILING=1 | 
 | 325 | </pre> | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 326 |  | 
 | 327 | </div> | 
 | 328 |  | 
 | 329 | <div class="question"> | 
 | 330 | <p>Why do test results differ when I perform different types of builds?</p> | 
 | 331 | </div> | 
 | 332 |  | 
 | 333 | <div class="answer"> | 
 | 334 |  | 
 | 335 | <p>The LLVM test suite is dependent upon several features of the LLVM tools and | 
 | 336 | libraries.</p> | 
 | 337 |  | 
 | 338 | <p>First, the debugging assertions in code are not enabled in optimized or | 
 | 339 | profiling builds.  Hence, tests that used to fail may pass.</p> | 
 | 340 | 	 | 
 | 341 | <p>Second, some tests may rely upon debugging options or behavior that is only | 
 | 342 | available in the debug build.  These tests will fail in an optimized or profile | 
 | 343 | build.</p> | 
 | 344 |  | 
 | 345 | </div> | 
 | 346 |  | 
| Chris Lattner | 8a0b924 | 2003-12-08 05:43:19 +0000 | [diff] [blame] | 347 | <div class="question"> | 
| Chris Lattner | 306acee | 2003-12-22 04:06:12 +0000 | [diff] [blame] | 348 | <p>Compiling LLVM with GCC 3.3.2 fails, what should I do?</p> | 
| Chris Lattner | 8a0b924 | 2003-12-08 05:43:19 +0000 | [diff] [blame] | 349 | </div> | 
 | 350 |  | 
 | 351 | <div class="answer"> | 
| Chris Lattner | 306acee | 2003-12-22 04:06:12 +0000 | [diff] [blame] | 352 | <p>This is <a href="http://gcc.gnu.org/PR?13392">a bug in GCC</a>, and  | 
| Bill Wendling | e9a6c35 | 2007-09-22 09:54:47 +0000 | [diff] [blame] | 353 | affects projects other than LLVM.  Try upgrading or downgrading your GCC.</p> | 
| Chris Lattner | 8a0b924 | 2003-12-08 05:43:19 +0000 | [diff] [blame] | 354 | </div> | 
 | 355 |  | 
| John Criswell | d179961 | 2004-03-29 20:23:11 +0000 | [diff] [blame] | 356 | <div class="question"> | 
| Bill Wendling | e9a6c35 | 2007-09-22 09:54:47 +0000 | [diff] [blame] | 357 | <p>After Subversion update, rebuilding gives the error "No rule to make | 
 | 358 | target".</p> | 
| Misha Brukman | 1739aec | 2004-09-09 16:36:47 +0000 | [diff] [blame] | 359 | </div> | 
 | 360 |  | 
 | 361 | <div class="answer"> | 
 | 362 | <p>If the error is of the form:</p> | 
 | 363 |  | 
| Misha Brukman | a54d4b2 | 2008-12-17 18:11:40 +0000 | [diff] [blame^] | 364 | <pre class="doc_code"> | 
| Misha Brukman | 1739aec | 2004-09-09 16:36:47 +0000 | [diff] [blame] | 365 | gmake[2]: *** No rule to make target `/path/to/somefile', needed by | 
 | 366 | `/path/to/another/file.d'.<br> | 
 | 367 | Stop. | 
| Bill Wendling | d6a68eb | 2007-05-29 09:24:33 +0000 | [diff] [blame] | 368 | </pre> | 
| Misha Brukman | 1739aec | 2004-09-09 16:36:47 +0000 | [diff] [blame] | 369 |  | 
| Reid Spencer | 669ed45 | 2007-07-09 08:04:31 +0000 | [diff] [blame] | 370 | <p>This may occur anytime files are moved within the Subversion repository or  | 
 | 371 | removed entirely.  In this case, the best solution is to erase all  | 
 | 372 | <tt>.d</tt> files, which list dependencies for source files, and rebuild:</p> | 
| Misha Brukman | 1739aec | 2004-09-09 16:36:47 +0000 | [diff] [blame] | 373 |  | 
| Misha Brukman | a54d4b2 | 2008-12-17 18:11:40 +0000 | [diff] [blame^] | 374 | <pre class="doc_code"> | 
| Misha Brukman | 1739aec | 2004-09-09 16:36:47 +0000 | [diff] [blame] | 375 | % cd $LLVM_OBJ_DIR | 
 | 376 | % rm -f `find . -name \*\.d`  | 
 | 377 | % gmake  | 
 | 378 | </pre> | 
| Misha Brukman | 1739aec | 2004-09-09 16:36:47 +0000 | [diff] [blame] | 379 |  | 
 | 380 | <p>In other cases, it may be necessary to run <tt>make clean</tt> before | 
 | 381 | rebuilding.</p> | 
 | 382 | </div> | 
 | 383 |  | 
| Bill Wendling | e9a6c35 | 2007-09-22 09:54:47 +0000 | [diff] [blame] | 384 | <div class="question"><p><a name="llvmc"> | 
 | 385 | The <tt>llvmc</tt> program gives me errors/doesn't work.</a></p> | 
| Bill Wendling | 174d578 | 2007-05-29 09:35:34 +0000 | [diff] [blame] | 386 | </div> | 
 | 387 |  | 
 | 388 | <div class="answer"> | 
| Bill Wendling | e9a6c35 | 2007-09-22 09:54:47 +0000 | [diff] [blame] | 389 | <p><tt>llvmc</tt> is experimental and isn't really supported. We suggest | 
 | 390 | using <tt>llvm-gcc</tt> instead.</p> | 
| Bill Wendling | 174d578 | 2007-05-29 09:35:34 +0000 | [diff] [blame] | 391 | </div> | 
 | 392 |  | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 393 | <!-- *********************************************************************** --> | 
| Reid Spencer | c87f497 | 2006-04-26 15:46:53 +0000 | [diff] [blame] | 394 | <div class="doc_section"><a name="felangs">Source Languages</a></div> | 
| Reid Spencer | 501bfee | 2006-04-26 14:52:19 +0000 | [diff] [blame] | 395 |  | 
| Reid Spencer | c87f497 | 2006-04-26 15:46:53 +0000 | [diff] [blame] | 396 | <div class="question"><p> | 
 | 397 |   <a name="langs">What source languages are supported?</a></p> | 
 | 398 | </div> | 
 | 399 | <div class="answer"> | 
| Reid Spencer | 501bfee | 2006-04-26 14:52:19 +0000 | [diff] [blame] | 400 |   <p>LLVM currently has full support for C and C++ source languages. These are | 
 | 401 |   available through a special version of GCC that LLVM calls the  | 
 | 402 |   <a href="#cfe">C Front End</a></p> | 
 | 403 |   <p>There is an incomplete version of a Java front end available in the | 
| Reid Spencer | 669ed45 | 2007-07-09 08:04:31 +0000 | [diff] [blame] | 404 |   <tt>java</tt> module. There is no documentation on this yet so | 
| Reid Spencer | 501bfee | 2006-04-26 14:52:19 +0000 | [diff] [blame] | 405 |   you'll need to download the code, compile it, and try it.</p> | 
| Reid Spencer | 501bfee | 2006-04-26 14:52:19 +0000 | [diff] [blame] | 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> | 
| Gordon Henriksen | 5836682 | 2008-02-22 20:58:29 +0000 | [diff] [blame] | 409 |  | 
 | 410 | <div class="question"><p><a name="langirgen"> | 
| Gordon Henriksen | e507905 | 2008-02-22 21:55:51 +0000 | [diff] [blame] | 411 |   I'd like to write a self-hosting LLVM compiler. How should I interface with  | 
 | 412 |   the LLVM middle-end optimizers and back-end code generators? | 
| Gordon Henriksen | 5836682 | 2008-02-22 20:58:29 +0000 | [diff] [blame] | 413 | </a></p></div> | 
 | 414 | <div class="answer"> | 
 | 415 |   <p>Your compiler front-end will communicate with LLVM by creating a module in | 
| Gordon Henriksen | e507905 | 2008-02-22 21:55:51 +0000 | [diff] [blame] | 416 |      the LLVM intermediate representation (IR) format. Assuming you want to  | 
 | 417 |      write your language's compiler in the language itself (rather than C++),  | 
 | 418 |      there are 3 major ways to tackle generating LLVM IR from a front-end:</p> | 
| Gordon Henriksen | 5836682 | 2008-02-22 20:58:29 +0000 | [diff] [blame] | 419 |   <ul> | 
 | 420 |     <li> | 
 | 421 |       <strong>Call into the LLVM libraries code using your language's FFI  | 
 | 422 |               (foreign function interface).</strong> | 
 | 423 |       <ul> | 
 | 424 |         <li><em>for:</em> best tracks changes to the LLVM IR, .ll syntax,  | 
 | 425 |             and .bc format</li> | 
 | 426 |         <li><em>for:</em> enables running LLVM optimization passes without a  | 
 | 427 |             emit/parse overhead</li> | 
 | 428 |         <li><em>for:</em> adapts well to a JIT context</li> | 
 | 429 |         <li><em>against:</em> lots of ugly glue code to write</li> | 
 | 430 |       </ul> | 
 | 431 |     </li> | 
 | 432 |     <li> | 
 | 433 |       <strong>Emit LLVM assembly from your compiler's native language.</strong> | 
 | 434 |       <ul> | 
 | 435 |         <li><em>for:</em> very straightforward to get started</li> | 
 | 436 |         <li><em>against:</em> the .ll parser is slower than the bitcode reader  | 
 | 437 |             when interfacing to the middle end</li> | 
 | 438 |         <li><em>against:</em> you'll have to re-engineer the LLVM IR object  | 
 | 439 |             model and asm writer in your language</li> | 
 | 440 |         <li><em>against:</em> it may be harder to track changes to the IR</li> | 
 | 441 |       </ul> | 
 | 442 |     </li> | 
 | 443 |     <li> | 
 | 444 |       <strong>Emit LLVM bitcode from your compiler's native language.</strong> | 
 | 445 |       <ul> | 
 | 446 |         <li><em>for:</em> can use the more-efficient bitcode reader when  | 
 | 447 |             interfacing to the middle end</li> | 
 | 448 |         <li><em>against:</em> you'll have to re-engineer the LLVM IR object  | 
 | 449 |             model and bitcode writer in your language</li> | 
 | 450 |         <li><em>against:</em> it may be harder to track changes to the IR</li> | 
 | 451 |       </ul> | 
 | 452 |     </li> | 
 | 453 |   </ul> | 
 | 454 |   <p>If you go with the first option, the C bindings in include/llvm-c should | 
 | 455 |      help a lot, since most languages have strong support for interfacing with  | 
 | 456 |      C. The most common hurdle with calling C from managed code is interfacing | 
 | 457 |      with the garbage collector. The C interface was designed to require very  | 
 | 458 |      little memory management, and so is straightforward in this regard.</p> | 
 | 459 | </div> | 
 | 460 |  | 
| Bill Wendling | e9a6c35 | 2007-09-22 09:54:47 +0000 | [diff] [blame] | 461 | <div class="question"><p><a name="langhlsupp"> | 
 | 462 |   What support is there for a higher level source language constructs for  | 
| Reid Spencer | c87f497 | 2006-04-26 15:46:53 +0000 | [diff] [blame] | 463 |   building a compiler?</a></p> | 
| Reid Spencer | 501bfee | 2006-04-26 14:52:19 +0000 | [diff] [blame] | 464 | </div> | 
 | 465 | <div class="answer"> | 
 | 466 |   <p>Currently, there isn't much. LLVM supports an intermediate representation | 
 | 467 |   which is useful for code representation but will not support the high level | 
 | 468 |   (abstract syntax tree) representation needed by most compilers. There are no | 
| Jeff Cohen | 7b8229a | 2006-04-26 21:03:17 +0000 | [diff] [blame] | 469 |   facilities for lexical nor semantic analysis. There is, however, a <i>mostly | 
| Reid Spencer | 501bfee | 2006-04-26 14:52:19 +0000 | [diff] [blame] | 470 |     implemented</i> configuration-driven  | 
 | 471 |   <a href="CompilerDriver.html">compiler driver</a> which simplifies the task | 
 | 472 |   of running optimizations, linking, and executable generation.</p> | 
| Reid Spencer | 501bfee | 2006-04-26 14:52:19 +0000 | [diff] [blame] | 473 | </div> | 
| Chris Lattner | 33bef48 | 2006-08-15 00:43:35 +0000 | [diff] [blame] | 474 |  | 
| Dan Gohman | f003276 | 2008-11-24 17:18:39 +0000 | [diff] [blame] | 475 | <div class="question"><p><a name="getelementptr"> | 
| Bill Wendling | e9a6c35 | 2007-09-22 09:54:47 +0000 | [diff] [blame] | 476 |   I don't understand the GetElementPtr instruction. Help!</a></p> | 
| Chris Lattner | 33bef48 | 2006-08-15 00:43:35 +0000 | [diff] [blame] | 477 | </div> | 
 | 478 | <div class="answer"> | 
 | 479 |   <p>See <a href="GetElementPtr.html">The Often Misunderstood GEP | 
| Bill Wendling | e9a6c35 | 2007-09-22 09:54:47 +0000 | [diff] [blame] | 480 |    Instruction</a>.</p> | 
| Chris Lattner | 33bef48 | 2006-08-15 00:43:35 +0000 | [diff] [blame] | 481 | </div> | 
 | 482 |  | 
| Reid Spencer | 501bfee | 2006-04-26 14:52:19 +0000 | [diff] [blame] | 483 | <!-- *********************************************************************** --> | 
 | 484 | <div class="doc_section"> | 
| Chris Lattner | cc33d70 | 2003-11-19 05:53:12 +0000 | [diff] [blame] | 485 |   <a name="cfe">Using the GCC Front End</a> | 
| John Criswell | 6ea30b0 | 2003-11-18 16:05:23 +0000 | [diff] [blame] | 486 | </div> | 
 | 487 |  | 
 | 488 | <div class="question"> | 
 | 489 | <p> | 
 | 490 | When I compile software that uses a configure script, the configure script | 
 | 491 | thinks my system has all of the header files and libraries it is testing for. | 
 | 492 | How do I get configure to work correctly? | 
 | 493 | </p> | 
 | 494 | </div> | 
 | 495 |  | 
 | 496 | <div class="answer"> | 
 | 497 | <p> | 
 | 498 | The configure script is getting things wrong because the LLVM linker allows | 
 | 499 | symbols to be undefined at link time (so that they can be resolved during JIT | 
 | 500 | or translation to the C back end).  That is why configure thinks your system | 
 | 501 | "has everything." | 
 | 502 | </p> | 
 | 503 | <p> | 
 | 504 | To work around this, perform the following steps: | 
 | 505 | </p> | 
| John Criswell | 6ea30b0 | 2003-11-18 16:05:23 +0000 | [diff] [blame] | 506 | <ol> | 
| Reid Spencer | 434262a | 2007-02-09 15:59:08 +0000 | [diff] [blame] | 507 |   <li>Make sure the CC and CXX environment variables contains the full path to  | 
 | 508 |   the LLVM GCC front end.</li> | 
| John Criswell | 6ea30b0 | 2003-11-18 16:05:23 +0000 | [diff] [blame] | 509 |  | 
| Reid Spencer | 434262a | 2007-02-09 15:59:08 +0000 | [diff] [blame] | 510 |   <li>Make sure that the regular C compiler is first in your PATH. </li> | 
| John Criswell | 6ea30b0 | 2003-11-18 16:05:23 +0000 | [diff] [blame] | 511 |  | 
| Reid Spencer | 434262a | 2007-02-09 15:59:08 +0000 | [diff] [blame] | 512 |   <li>Add the string "-Wl,-native" to your CFLAGS environment variable.</li> | 
| John Criswell | 6ea30b0 | 2003-11-18 16:05:23 +0000 | [diff] [blame] | 513 | </ol> | 
 | 514 |  | 
 | 515 | <p> | 
| Reid Spencer | 434262a | 2007-02-09 15:59:08 +0000 | [diff] [blame] | 516 | This will allow the <tt>llvm-ld</tt> linker to create a native code executable  | 
 | 517 | instead of shell script that runs the JIT.  Creating native code requires  | 
 | 518 | standard linkage, which in turn will allow the configure script to find out if  | 
 | 519 | code is not linking on your system because the feature isn't available on your  | 
 | 520 | system.</p> | 
| John Criswell | 6ea30b0 | 2003-11-18 16:05:23 +0000 | [diff] [blame] | 521 | </div> | 
 | 522 |  | 
| Chris Lattner | cc33d70 | 2003-11-19 05:53:12 +0000 | [diff] [blame] | 523 | <div class="question"> | 
| John Criswell | 6ea30b0 | 2003-11-18 16:05:23 +0000 | [diff] [blame] | 524 | <p> | 
 | 525 | When I compile code using the LLVM GCC front end, it complains that it cannot | 
| John Criswell | cd16119 | 2004-03-12 18:20:15 +0000 | [diff] [blame] | 526 | find libcrtend.a. | 
| John Criswell | 6ea30b0 | 2003-11-18 16:05:23 +0000 | [diff] [blame] | 527 | </p> | 
 | 528 | </div> | 
 | 529 |  | 
| Chris Lattner | cc33d70 | 2003-11-19 05:53:12 +0000 | [diff] [blame] | 530 | <div class="answer"> | 
| John Criswell | 6ea30b0 | 2003-11-18 16:05:23 +0000 | [diff] [blame] | 531 | <p> | 
| Reid Spencer | f96eb57 | 2004-12-15 00:14:01 +0000 | [diff] [blame] | 532 | The only way this can happen is if you haven't installed the runtime library. To | 
 | 533 | correct this, do:</p> | 
| Bill Wendling | d6a68eb | 2007-05-29 09:24:33 +0000 | [diff] [blame] | 534 |  | 
| Misha Brukman | a54d4b2 | 2008-12-17 18:11:40 +0000 | [diff] [blame^] | 535 | <pre class="doc_code"> | 
| Bill Wendling | d6a68eb | 2007-05-29 09:24:33 +0000 | [diff] [blame] | 536 | % cd llvm/runtime | 
 | 537 | % make clean ; make install-bytecode | 
| Reid Spencer | f96eb57 | 2004-12-15 00:14:01 +0000 | [diff] [blame] | 538 | </pre> | 
| John Criswell | 6ea30b0 | 2003-11-18 16:05:23 +0000 | [diff] [blame] | 539 | </div> | 
| Chris Lattner | cc33d70 | 2003-11-19 05:53:12 +0000 | [diff] [blame] | 540 |  | 
| Tanya Lattner | 14fc5c1 | 2005-04-25 20:36:56 +0000 | [diff] [blame] | 541 | <div class="question"> | 
 | 542 | <p> | 
 | 543 | How can I disable all optimizations when compiling code using the LLVM GCC front end? | 
 | 544 | </p> | 
 | 545 | </div> | 
 | 546 |  | 
 | 547 | <div class="answer"> | 
 | 548 | <p> | 
 | 549 | Passing "-Wa,-disable-opt -Wl,-disable-opt" will disable *all* cleanup and | 
 | 550 | optimizations done at the llvm level, leaving you with the truly horrible | 
 | 551 | code that you desire. | 
 | 552 | </p> | 
 | 553 | </div> | 
| Chris Lattner | cc33d70 | 2003-11-19 05:53:12 +0000 | [diff] [blame] | 554 |  | 
| Chris Lattner | af7fd20 | 2006-07-19 18:19:59 +0000 | [diff] [blame] | 555 |  | 
 | 556 | <div class="question"> | 
 | 557 | <p> | 
| Dan Gohman | f003276 | 2008-11-24 17:18:39 +0000 | [diff] [blame] | 558 | <a name="translatecxx">Can I use LLVM to convert C++ code to C code?</a> | 
| Chris Lattner | af7fd20 | 2006-07-19 18:19:59 +0000 | [diff] [blame] | 559 | </p> | 
 | 560 | </div> | 
 | 561 |  | 
 | 562 | <div class="answer"> | 
 | 563 | <p>Yes, you can use LLVM to convert code from any language LLVM supports to C. | 
 | 564 | Note that the generated C code will be very low level (all loops are lowered | 
 | 565 | to gotos, etc) and not very pretty (comments are stripped, original source | 
 | 566 | formatting is totally lost, variables are renamed, expressions are regrouped),  | 
 | 567 | so this may not be what you're looking for.  However, this is a good way to add | 
 | 568 | C++ support for a processor that does not otherwise have a C++ compiler. | 
 | 569 | </p> | 
 | 570 |  | 
 | 571 | <p>Use commands like this:</p> | 
 | 572 |  | 
 | 573 | <ol> | 
| Bill Wendling | e9a6c35 | 2007-09-22 09:54:47 +0000 | [diff] [blame] | 574 |   <li><p>Compile your program as normal with llvm-g++:</p> | 
| Chris Lattner | af7fd20 | 2006-07-19 18:19:59 +0000 | [diff] [blame] | 575 |  | 
| Misha Brukman | a54d4b2 | 2008-12-17 18:11:40 +0000 | [diff] [blame^] | 576 | <pre class="doc_code"> | 
| Bill Wendling | d6a68eb | 2007-05-29 09:24:33 +0000 | [diff] [blame] | 577 | % llvm-g++ x.cpp -o program | 
 | 578 | </pre> | 
| Chris Lattner | af7fd20 | 2006-07-19 18:19:59 +0000 | [diff] [blame] | 579 |  | 
| Bill Wendling | e9a6c35 | 2007-09-22 09:54:47 +0000 | [diff] [blame] | 580 |   <p>or:</p> | 
| Chris Lattner | af7fd20 | 2006-07-19 18:19:59 +0000 | [diff] [blame] | 581 |  | 
| Misha Brukman | a54d4b2 | 2008-12-17 18:11:40 +0000 | [diff] [blame^] | 582 | <pre class="doc_code"> | 
| Bill Wendling | d6a68eb | 2007-05-29 09:24:33 +0000 | [diff] [blame] | 583 | % llvm-g++ a.cpp -c | 
 | 584 | % llvm-g++ b.cpp -c | 
 | 585 | % llvm-g++ a.o b.o -o program | 
 | 586 | </pre> | 
| Chris Lattner | af7fd20 | 2006-07-19 18:19:59 +0000 | [diff] [blame] | 587 |  | 
| Bill Wendling | e9a6c35 | 2007-09-22 09:54:47 +0000 | [diff] [blame] | 588 |       <p>With llvm-gcc3, this will generate program and program.bc.  The .bc | 
 | 589 |          file is the LLVM version of the program all linked together.</p></li> | 
| Chris Lattner | af7fd20 | 2006-07-19 18:19:59 +0000 | [diff] [blame] | 590 |  | 
| Bill Wendling | e9a6c35 | 2007-09-22 09:54:47 +0000 | [diff] [blame] | 591 |   <li><p>Convert the LLVM code to C code, using the LLC tool with the C | 
 | 592 |       backend:</p> | 
| Chris Lattner | af7fd20 | 2006-07-19 18:19:59 +0000 | [diff] [blame] | 593 |  | 
| Misha Brukman | a54d4b2 | 2008-12-17 18:11:40 +0000 | [diff] [blame^] | 594 | <pre class="doc_code"> | 
| Bill Wendling | d6a68eb | 2007-05-29 09:24:33 +0000 | [diff] [blame] | 595 | % llc -march=c program.bc -o program.c | 
| Misha Brukman | a54d4b2 | 2008-12-17 18:11:40 +0000 | [diff] [blame^] | 596 | </pre></li> | 
| Chris Lattner | af7fd20 | 2006-07-19 18:19:59 +0000 | [diff] [blame] | 597 |  | 
| Bill Wendling | e9a6c35 | 2007-09-22 09:54:47 +0000 | [diff] [blame] | 598 | <li><p>Finally, compile the C file:</p> | 
| Chris Lattner | af7fd20 | 2006-07-19 18:19:59 +0000 | [diff] [blame] | 599 |  | 
| Misha Brukman | a54d4b2 | 2008-12-17 18:11:40 +0000 | [diff] [blame^] | 600 | <pre class="doc_code"> | 
| Bill Wendling | d6a68eb | 2007-05-29 09:24:33 +0000 | [diff] [blame] | 601 | % cc x.c | 
| Misha Brukman | a54d4b2 | 2008-12-17 18:11:40 +0000 | [diff] [blame^] | 602 | </pre></li> | 
| Chris Lattner | af7fd20 | 2006-07-19 18:19:59 +0000 | [diff] [blame] | 603 |  | 
 | 604 | </ol> | 
 | 605 |  | 
| Bill Wendling | e9a6c35 | 2007-09-22 09:54:47 +0000 | [diff] [blame] | 606 | <p>Note that, by default, the C backend does not support exception handling.  If | 
 | 607 | you want/need it for a certain program, you can enable it by passing | 
 | 608 | "-enable-correct-eh-support" to the llc program.  The resultant code will use | 
 | 609 | setjmp/longjmp to implement exception support that is correct but relatively | 
 | 610 | slow.</p> | 
| Chris Lattner | b495fb0 | 2006-08-31 04:26:31 +0000 | [diff] [blame] | 611 |  | 
| Bill Wendling | e9a6c35 | 2007-09-22 09:54:47 +0000 | [diff] [blame] | 612 | <p>Also note: this specific sequence of commands won't work if you use a | 
 | 613 | function defined in the C++ runtime library (or any other C++ library).  To | 
 | 614 | access an external C++ library, you must manually compile libstdc++ to LLVM | 
 | 615 | bitcode, statically link it into your program, then use the commands above to | 
 | 616 | convert the whole result into C code.  Alternatively, you can compile the | 
 | 617 | libraries and your application into two different chunks of C code and link | 
 | 618 | them.</p> | 
| Chris Lattner | b495fb0 | 2006-08-31 04:26:31 +0000 | [diff] [blame] | 619 |  | 
| Chris Lattner | af7fd20 | 2006-07-19 18:19:59 +0000 | [diff] [blame] | 620 | </div> | 
 | 621 |  | 
| Chris Lattner | cc33d70 | 2003-11-19 05:53:12 +0000 | [diff] [blame] | 622 | <!-- *********************************************************************** --> | 
 | 623 | <div class="doc_section"> | 
 | 624 |   <a name="cfe_code">Questions about code generated by the GCC front-end</a> | 
 | 625 | </div> | 
 | 626 |  | 
| Misha Brukman | 237dc2a | 2004-12-03 23:58:18 +0000 | [diff] [blame] | 627 | <div class="question"> | 
| Chris Lattner | 5a53c5d | 2005-02-25 20:30:21 +0000 | [diff] [blame] | 628 | <a name="iosinit"></a> | 
| Misha Brukman | 237dc2a | 2004-12-03 23:58:18 +0000 | [diff] [blame] | 629 | <p> What is this <tt>llvm.global_ctors</tt> and | 
 | 630 | <tt>_GLOBAL__I__tmp_webcompile...</tt> stuff that happens when I #include | 
 | 631 | <iostream>?</p> | 
 | 632 | </div> | 
| Chris Lattner | c50bbc9 | 2004-03-29 19:14:35 +0000 | [diff] [blame] | 633 |  | 
 | 634 | <div class="answer"> | 
| Misha Brukman | 237dc2a | 2004-12-03 23:58:18 +0000 | [diff] [blame] | 635 |  | 
 | 636 | <p>If you #include the <iostream> header into a C++ translation unit, the | 
| Chris Lattner | c50bbc9 | 2004-03-29 19:14:35 +0000 | [diff] [blame] | 637 | file will probably use the <tt>std::cin</tt>/<tt>std::cout</tt>/... global | 
 | 638 | objects.  However, C++ does not guarantee an order of initialization between | 
 | 639 | static objects in different translation units, so if a static ctor/dtor in your | 
 | 640 | .cpp file used <tt>std::cout</tt>, for example, the object would not necessarily | 
| Misha Brukman | 237dc2a | 2004-12-03 23:58:18 +0000 | [diff] [blame] | 641 | be automatically initialized before your use.</p> | 
| Chris Lattner | c50bbc9 | 2004-03-29 19:14:35 +0000 | [diff] [blame] | 642 |  | 
| Misha Brukman | 237dc2a | 2004-12-03 23:58:18 +0000 | [diff] [blame] | 643 | <p>To make <tt>std::cout</tt> and friends work correctly in these scenarios, the | 
| Chris Lattner | c50bbc9 | 2004-03-29 19:14:35 +0000 | [diff] [blame] | 644 | STL that we use declares a static object that gets created in every translation | 
| Misha Brukman | 237dc2a | 2004-12-03 23:58:18 +0000 | [diff] [blame] | 645 | unit that includes <tt><iostream></tt>.  This object has a static | 
 | 646 | constructor and destructor that initializes and destroys the global iostream | 
 | 647 | objects before they could possibly be used in the file.  The code that you see | 
 | 648 | in the .ll file corresponds to the constructor and destructor registration code. | 
| Chris Lattner | c50bbc9 | 2004-03-29 19:14:35 +0000 | [diff] [blame] | 649 | </p> | 
 | 650 |  | 
| Misha Brukman | 237dc2a | 2004-12-03 23:58:18 +0000 | [diff] [blame] | 651 | <p>If you would like to make it easier to <b>understand</b> the LLVM code | 
 | 652 | generated by the compiler in the demo page, consider using <tt>printf()</tt> | 
 | 653 | instead of <tt>iostream</tt>s to print values.</p> | 
 | 654 |  | 
| Chris Lattner | c50bbc9 | 2004-03-29 19:14:35 +0000 | [diff] [blame] | 655 | </div> | 
 | 656 |  | 
| Chris Lattner | 5a53c5d | 2005-02-25 20:30:21 +0000 | [diff] [blame] | 657 | <!--=========================================================================--> | 
 | 658 |  | 
 | 659 | <div class="question"><p> | 
 | 660 | <a name="codedce"></a> | 
 | 661 | Where did all of my code go?? | 
 | 662 | </p></div> | 
 | 663 |  | 
 | 664 | <div class="answer"> | 
 | 665 | <p> | 
 | 666 | If you are using the LLVM demo page, you may often wonder what happened to all | 
 | 667 | of the code that you typed in.  Remember that the demo script is running the | 
 | 668 | code through the LLVM optimizers, so if your code doesn't actually do anything | 
 | 669 | useful, it might all be deleted. | 
 | 670 | </p> | 
 | 671 |  | 
 | 672 | <p> | 
 | 673 | To prevent this, make sure that the code is actually needed.  For example, if | 
 | 674 | you are computing some expression, return the value from the function instead of | 
 | 675 | leaving it in a local variable.  If you really want to constrain the optimizer, | 
 | 676 | you can read from and assign to <tt>volatile</tt> global variables. | 
 | 677 | </p> | 
 | 678 | </div> | 
 | 679 |  | 
 | 680 | <!--=========================================================================--> | 
 | 681 |  | 
 | 682 | <div class="question"><p> | 
 | 683 | <a name="undef"></a> | 
 | 684 | <p>What is this "<tt>undef</tt>" thing that shows up in my code? | 
 | 685 | </p></div> | 
 | 686 |  | 
 | 687 | <div class="answer"> | 
 | 688 | <p> | 
 | 689 | <a href="LangRef.html#undef"><tt>undef</tt></a> is the LLVM way of representing | 
 | 690 | a value that is not defined.  You can get these if you do not initialize a  | 
 | 691 | variable before you use it.  For example, the C function:</p> | 
 | 692 |  | 
| Misha Brukman | a54d4b2 | 2008-12-17 18:11:40 +0000 | [diff] [blame^] | 693 | <pre class="doc_code"> | 
| Bill Wendling | d6a68eb | 2007-05-29 09:24:33 +0000 | [diff] [blame] | 694 | int X() { int i; return i; } | 
 | 695 | </pre> | 
| Chris Lattner | 5a53c5d | 2005-02-25 20:30:21 +0000 | [diff] [blame] | 696 |  | 
| Bill Wendling | d6a68eb | 2007-05-29 09:24:33 +0000 | [diff] [blame] | 697 | <p>Is compiled to "<tt>ret i32 undef</tt>" because "<tt>i</tt>" never has | 
 | 698 | a value specified for it.</p> | 
| Chris Lattner | 5a53c5d | 2005-02-25 20:30:21 +0000 | [diff] [blame] | 699 | </div> | 
 | 700 |  | 
| John Criswell | 6ea30b0 | 2003-11-18 16:05:23 +0000 | [diff] [blame] | 701 | <!-- *********************************************************************** --> | 
| John Criswell | c310f62 | 2003-10-13 16:13:06 +0000 | [diff] [blame] | 702 |  | 
 | 703 | <hr> | 
| Misha Brukman | 7ce62cc | 2004-06-01 18:51:03 +0000 | [diff] [blame] | 704 | <address> | 
 | 705 |   <a href="http://jigsaw.w3.org/css-validator/check/referer"><img | 
| Misha Brukman | 4440870 | 2008-12-11 17:34:48 +0000 | [diff] [blame] | 706 |   src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a> | 
| Misha Brukman | 7ce62cc | 2004-06-01 18:51:03 +0000 | [diff] [blame] | 707 |   <a href="http://validator.w3.org/check/referer"><img | 
| Misha Brukman | 4440870 | 2008-12-11 17:34:48 +0000 | [diff] [blame] | 708 |   src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a> | 
| Misha Brukman | 7ce62cc | 2004-06-01 18:51:03 +0000 | [diff] [blame] | 709 |  | 
| Reid Spencer | 05fe4b0 | 2006-03-14 05:39:39 +0000 | [diff] [blame] | 710 |   <a href="http://llvm.org">LLVM Compiler Infrastructure</a><br> | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 711 |   Last modified: $Date$ | 
| Misha Brukman | 7ce62cc | 2004-06-01 18:51:03 +0000 | [diff] [blame] | 712 | </address> | 
| John Criswell | f08c5d8 | 2003-10-24 22:48:20 +0000 | [diff] [blame] | 713 |  | 
| John Criswell | c310f62 | 2003-10-13 16:13:06 +0000 | [diff] [blame] | 714 | </body> | 
 | 715 | </html> |