| 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> | 
|  | 39 | <li>I compile the code, and I get some error about <tt>/localhome</tt>.</li> | 
|  | 40 | <li>The <tt>configure</tt> script finds the right C compiler, but it uses the | 
|  | 41 | LLVM linker from a previous build.  What do I do?</li> | 
|  | 42 | <li>When creating a dynamic library, I get a strange GLIBC error.</li> | 
|  | 43 | <li>I've updated my source tree from CVS, and now my build is trying to use a | 
|  | 44 | file/directory that doesn't exist.</li> | 
|  | 45 | <li>I've modified a Makefile in my source tree, but my build tree keeps using | 
|  | 46 | the old version.  What do I do?</li> | 
|  | 47 | <li>I've upgraded to a new version of LLVM, and I get strange build | 
|  | 48 | errors.</li> | 
|  | 49 | <li>I've built LLVM and am testing it, but the tests freeze.</li> | 
|  | 50 | <li>Why do test results differ when I perform different types of builds?</li> | 
| Chris Lattner | 306acee | 2003-12-22 04:06:12 +0000 | [diff] [blame] | 51 | <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] | 52 | <li>When I use the test suite, all of the C Backend tests fail.  What is | 
|  | 53 | wrong?</li> | 
| Misha Brukman | 1739aec | 2004-09-09 16:36:47 +0000 | [diff] [blame] | 54 | <li>After CVS update, rebuilding gives the error "No rule to make | 
|  | 55 | target".</li> | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 56 | </ol></li> | 
| John Criswell | 76c1e38 | 2003-11-18 16:08:49 +0000 | [diff] [blame] | 57 |  | 
| Reid Spencer | 501bfee | 2006-04-26 14:52:19 +0000 | [diff] [blame^] | 58 | <li><a href="#felangs">Source Languages</a> | 
|  | 59 | <ol> | 
|  | 60 | <li><a href="#langs">What source languages are supported?</a></li> | 
|  | 61 | <li><a href="#langhlsupp">What support is there for higher level source | 
|  | 62 | language constructs for building a compiler?</a></li> | 
|  | 63 | </ol> | 
|  | 64 |  | 
| Chris Lattner | cc33d70 | 2003-11-19 05:53:12 +0000 | [diff] [blame] | 65 | <li><a href="#cfe">Using the GCC Front End</a> | 
| John Criswell | 76c1e38 | 2003-11-18 16:08:49 +0000 | [diff] [blame] | 66 | <ol> | 
|  | 67 | <li> | 
|  | 68 | When I compile software that uses a configure script, the configure script | 
|  | 69 | thinks my system has all of the header files and libraries it is testing | 
|  | 70 | for.  How do I get configure to work correctly? | 
|  | 71 | </li> | 
|  | 72 |  | 
|  | 73 | <li> | 
|  | 74 | 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] | 75 | cannot find libcrtend.a. | 
| John Criswell | 76c1e38 | 2003-11-18 16:08:49 +0000 | [diff] [blame] | 76 | </li> | 
| Tanya Lattner | 14fc5c1 | 2005-04-25 20:36:56 +0000 | [diff] [blame] | 77 |  | 
|  | 78 | <li> | 
|  | 79 | How can I disable all optimizations when compiling code using the LLVM GCC front end? | 
|  | 80 | </li> | 
|  | 81 |  | 
| John Criswell | 76c1e38 | 2003-11-18 16:08:49 +0000 | [diff] [blame] | 82 | </ol> | 
|  | 83 | </li> | 
| Chris Lattner | cc33d70 | 2003-11-19 05:53:12 +0000 | [diff] [blame] | 84 |  | 
|  | 85 | <li><a href="#cfe_code">Questions about code generated by the GCC front-end</a> | 
|  | 86 | <ol> | 
| Chris Lattner | 5a53c5d | 2005-02-25 20:30:21 +0000 | [diff] [blame] | 87 | <li><a href="#__main">What is this <tt>__main()</tt> call that gets inserted into | 
|  | 88 | <tt>main()</tt>?</a></li> | 
|  | 89 | <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] | 90 | <tt>_GLOBAL__I__tmp_webcompile...</tt> stuff that happens when I | 
| Chris Lattner | 5a53c5d | 2005-02-25 20:30:21 +0000 | [diff] [blame] | 91 | #include <iostream>?</a></li> | 
|  | 92 | <li><a href="#codedce">Where did all of my code go??</a></li> | 
|  | 93 | <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] | 94 | </ol> | 
|  | 95 | </li> | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 96 | </ol> | 
|  | 97 |  | 
| Chris Lattner | 7911ce2 | 2004-05-23 21:07:27 +0000 | [diff] [blame] | 98 | <div class="doc_author"> | 
| Reid Spencer | 05fe4b0 | 2006-03-14 05:39:39 +0000 | [diff] [blame] | 99 | <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] | 100 | </div> | 
|  | 101 |  | 
|  | 102 |  | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 103 | <!-- *********************************************************************** --> | 
|  | 104 | <div class="doc_section"> | 
|  | 105 | <a name="license">License</a> | 
|  | 106 | </div> | 
|  | 107 | <!-- *********************************************************************** --> | 
|  | 108 |  | 
|  | 109 | <div class="question"> | 
|  | 110 | <p>Why are the LLVM source code and the front-end distributed under different | 
|  | 111 | licenses?</p> | 
|  | 112 | </div> | 
|  | 113 |  | 
|  | 114 | <div class="answer"> | 
|  | 115 | <p>The C/C++ front-ends are based on GCC and must be distributed under the GPL. | 
|  | 116 | Our aim is to distribute LLVM source code under a <em>much less restrictive</em> | 
|  | 117 | license, in particular one that does not compel users who distribute tools based | 
|  | 118 | on modifying the source to redistribute the modified source code as well.</p> | 
|  | 119 | </div> | 
|  | 120 |  | 
|  | 121 | <div class="question"> | 
|  | 122 | <p>Does the University of Illinois Open Source License really qualify as an | 
|  | 123 | "open source" license?</p> | 
|  | 124 | </div> | 
|  | 125 |  | 
|  | 126 | <div class="answer"> | 
|  | 127 | <p>Yes, the license is <a | 
|  | 128 | href="http://www.opensource.org/licenses/UoI-NCSA.php">certified</a> by the Open | 
|  | 129 | Source Initiative (OSI).</p> | 
|  | 130 | </div> | 
|  | 131 |  | 
|  | 132 | <div class="question"> | 
|  | 133 | <p>Can I modify LLVM source code and redistribute the modified source?</p> | 
|  | 134 | </div> | 
|  | 135 |  | 
|  | 136 | <div class="answer"> | 
|  | 137 | <p>Yes.  The modified source distribution must retain the copyright notice and | 
|  | 138 | follow the three bulletted conditions listed in the <a | 
| Reid Spencer | 05fe4b0 | 2006-03-14 05:39:39 +0000 | [diff] [blame] | 139 | href="http://llvm.org/releases/1.3/LICENSE.TXT">LLVM license</a>.</p> | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 140 | </div> | 
|  | 141 |  | 
|  | 142 | <div class="question"> | 
|  | 143 | <p>Can I modify LLVM source code and redistribute binaries or other tools based | 
|  | 144 | on it, without redistributing the source?</p> | 
|  | 145 | </div> | 
|  | 146 |  | 
|  | 147 | <div class="answer"> | 
|  | 148 | <p>Yes, this is why we distribute LLVM under a less restrictive license than | 
|  | 149 | GPL, as explained in the first question above.</p> | 
|  | 150 | </div> | 
|  | 151 |  | 
|  | 152 | <!-- *********************************************************************** --> | 
|  | 153 | <div class="doc_section"> | 
|  | 154 | <a name="source">Source Code</a> | 
|  | 155 | </div> | 
|  | 156 | <!-- *********************************************************************** --> | 
|  | 157 |  | 
|  | 158 | <div class="question"> | 
|  | 159 | <p>In what language is LLVM written?</p> | 
|  | 160 | </div> | 
|  | 161 |  | 
|  | 162 | <div class="answer"> | 
|  | 163 | <p>All of the LLVM tools and libraries are written in C++ with extensive use of | 
|  | 164 | the STL.</p> | 
|  | 165 | </div> | 
|  | 166 |  | 
|  | 167 | <div class="question"> | 
|  | 168 | <p>How portable is the LLVM source code?</p> | 
|  | 169 | </div> | 
|  | 170 |  | 
|  | 171 | <div class="answer"> | 
|  | 172 | <p>The LLVM source code should be portable to most modern UNIX-like operating | 
|  | 173 | systems.  Most of the code is written in standard C++ with operating system | 
|  | 174 | services abstracted to a support library.  The tools required to build and test | 
|  | 175 | LLVM have been ported to a plethora of platforms.</p> | 
|  | 176 |  | 
|  | 177 | <p>Some porting problems may exist in the following areas:</p> | 
|  | 178 |  | 
|  | 179 | <ul> | 
|  | 180 |  | 
|  | 181 | <li>The GCC front end code is not as portable as the LLVM suite, so it may not | 
|  | 182 | compile as well on unsupported platforms.</li> | 
|  | 183 |  | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 184 | <li>The LLVM build system relies heavily on UNIX shell tools, like the Bourne | 
|  | 185 | Shell and sed.  Porting to systems without these tools (MacOS 9, Plan 9) will | 
|  | 186 | require more effort.</li> | 
|  | 187 |  | 
|  | 188 | </ul> | 
|  | 189 |  | 
|  | 190 | </div> | 
|  | 191 |  | 
|  | 192 | <!-- *********************************************************************** --> | 
|  | 193 | <div class="doc_section"> | 
|  | 194 | <a name="build">Build Problems</a> | 
|  | 195 | </div> | 
|  | 196 | <!-- *********************************************************************** --> | 
|  | 197 |  | 
|  | 198 | <div class="question"> | 
|  | 199 | <p>When I run configure, it finds the wrong C compiler.</p> | 
|  | 200 | </div> | 
|  | 201 |  | 
|  | 202 | <div class="answer"> | 
|  | 203 |  | 
|  | 204 | <p>The <tt>configure</tt> script attempts to locate first <tt>gcc</tt> and then | 
|  | 205 | <tt>cc</tt>, unless it finds compiler paths set in <tt>CC</tt> and <tt>CXX</tt> | 
|  | 206 | for the C and C++ compiler, respectively.</p> | 
|  | 207 |  | 
|  | 208 | <p>If <tt>configure</tt> finds the wrong compiler, either adjust your | 
|  | 209 | <tt>PATH</tt> environment variable or set <tt>CC</tt> and <tt>CXX</tt> | 
|  | 210 | explicitly.</p> | 
|  | 211 |  | 
|  | 212 | </div> | 
|  | 213 |  | 
|  | 214 | <div class="question"> | 
|  | 215 | <p>I compile the code, and I get some error about <tt>/localhome</tt>.</p> | 
|  | 216 | </div> | 
|  | 217 |  | 
|  | 218 | <div class="answer"> | 
|  | 219 |  | 
|  | 220 | <p>There are several possible causes for this.  The first is that you didn't set | 
|  | 221 | a pathname properly when using <tt>configure</tt>, and it defaulted to a | 
|  | 222 | pathname that we use on our research machines.</p> | 
|  | 223 |  | 
|  | 224 | <p>Another possibility is that we hardcoded a path in our Makefiles.  If you see | 
|  | 225 | this, please email the LLVM bug mailing list with the name of the offending | 
|  | 226 | Makefile and a description of what is wrong with it.</p> | 
|  | 227 |  | 
|  | 228 | </div> | 
|  | 229 |  | 
|  | 230 | <div class="question"> | 
|  | 231 | <p>The <tt>configure</tt> script finds the right C compiler, but it uses the | 
|  | 232 | LLVM linker from a previous build.  What do I do?</p> | 
|  | 233 | </div> | 
|  | 234 |  | 
|  | 235 | <div class="answer"> | 
|  | 236 | <p>The <tt>configure</tt> script uses the <tt>PATH</tt> to find executables, so | 
|  | 237 | if it's grabbing the wrong linker/assembler/etc, there are two ways to fix | 
|  | 238 | it:</p> | 
|  | 239 |  | 
|  | 240 | <ol> | 
|  | 241 |  | 
|  | 242 | <li><p>Adjust your <tt>PATH</tt> environment variable so that the correct | 
|  | 243 | program appears first in the <tt>PATH</tt>.  This may work, but may not be | 
|  | 244 | convenient when you want them <i>first</i> in your path for other | 
|  | 245 | work.</p></li> | 
|  | 246 |  | 
|  | 247 | <li><p>Run <tt>configure</tt> with an alternative <tt>PATH</tt> that is | 
|  | 248 | correct. In a Borne compatible shell, the syntax would be:</p> | 
|  | 249 |  | 
| Misha Brukman | 7ce62cc | 2004-06-01 18:51:03 +0000 | [diff] [blame] | 250 | <p><tt>PATH=[the path without the bad program] ./configure ...</tt></p> | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 251 |  | 
|  | 252 | <p>This is still somewhat inconvenient, but it allows <tt>configure</tt> | 
|  | 253 | to do its work without having to adjust your <tt>PATH</tt> | 
|  | 254 | permanently.</p></li> | 
|  | 255 |  | 
|  | 256 | </ol> | 
|  | 257 |  | 
|  | 258 | </div> | 
|  | 259 |  | 
|  | 260 | <div class="question"> | 
|  | 261 | <p>When creating a dynamic library, I get a strange GLIBC error.</p> | 
|  | 262 | </div> | 
|  | 263 |  | 
|  | 264 | <div class="answer"> | 
|  | 265 | <p>Under some operating systems (i.e. Linux), libtool does not work correctly if | 
|  | 266 | GCC was compiled with the --disable-shared option.  To work around this, install | 
|  | 267 | your own version of GCC that has shared libraries enabled by default.</p> | 
|  | 268 | </div> | 
|  | 269 |  | 
|  | 270 | <div class="question"> | 
|  | 271 | <p>I've updated my source tree from CVS, and now my build is trying to use a | 
|  | 272 | file/directory that doesn't exist.</p> | 
|  | 273 | </div> | 
|  | 274 |  | 
|  | 275 | <div class="answer"> | 
|  | 276 | <p>You need to re-run configure in your object directory.  When new Makefiles | 
|  | 277 | are added to the source tree, they have to be copied over to the object tree in | 
|  | 278 | order to be used by the build.</p> | 
|  | 279 | </div> | 
|  | 280 |  | 
|  | 281 | <div class="question"> | 
|  | 282 | <p>I've modified a Makefile in my source tree, but my build tree keeps using the | 
|  | 283 | old version.  What do I do?</p> | 
|  | 284 | </div> | 
|  | 285 |  | 
|  | 286 | <div class="answer"> | 
|  | 287 |  | 
|  | 288 | <p>If the Makefile already exists in your object tree, you | 
|  | 289 | can just run the following command in the top level directory of your object | 
|  | 290 | tree:</p> | 
|  | 291 |  | 
|  | 292 | <p><tt>./config.status <relative path to Makefile></tt><p> | 
|  | 293 |  | 
|  | 294 | <p>If the Makefile is new, you will have to modify the configure script to copy | 
|  | 295 | it over.</p> | 
|  | 296 |  | 
|  | 297 | </div> | 
|  | 298 |  | 
|  | 299 | <div class="question"> | 
|  | 300 | <p>I've upgraded to a new version of LLVM, and I get strange build errors.</p> | 
|  | 301 | </div> | 
|  | 302 |  | 
|  | 303 | <div class="answer"> | 
|  | 304 |  | 
|  | 305 | <p>Sometimes, changes to the LLVM source code alters how the build system works. | 
|  | 306 | Changes in libtool, autoconf, or header file dependencies are especially prone | 
|  | 307 | to this sort of problem.</p> | 
|  | 308 |  | 
|  | 309 | <p>The best thing to try is to remove the old files and re-build.  In most | 
|  | 310 | cases, this takes care of the problem.  To do this, just type <tt>make | 
|  | 311 | clean</tt> and then <tt>make</tt> in the directory that fails to build.</p> | 
|  | 312 |  | 
|  | 313 | </div> | 
|  | 314 |  | 
|  | 315 | <div class="question"> | 
|  | 316 | <p>I've built LLVM and am testing it, but the tests freeze.</p> | 
|  | 317 | </div> | 
|  | 318 |  | 
|  | 319 | <div class="answer"> | 
|  | 320 |  | 
|  | 321 | <p>This is most likely occurring because you built a profile or release | 
|  | 322 | (optimized) build of LLVM and have not specified the same information on the | 
|  | 323 | <tt>gmake</tt> command line.</p> | 
|  | 324 |  | 
|  | 325 | <p>For example, if you built LLVM with the command:</p> | 
|  | 326 |  | 
|  | 327 | <p><tt>gmake ENABLE_PROFILING=1</tt> | 
|  | 328 |  | 
|  | 329 | <p>...then you must run the tests with the following commands:</p> | 
|  | 330 |  | 
|  | 331 | <p><tt>cd llvm/test<br>gmake  ENABLE_PROFILING=1</tt></p> | 
|  | 332 |  | 
|  | 333 | </div> | 
|  | 334 |  | 
|  | 335 | <div class="question"> | 
|  | 336 | <p>Why do test results differ when I perform different types of builds?</p> | 
|  | 337 | </div> | 
|  | 338 |  | 
|  | 339 | <div class="answer"> | 
|  | 340 |  | 
|  | 341 | <p>The LLVM test suite is dependent upon several features of the LLVM tools and | 
|  | 342 | libraries.</p> | 
|  | 343 |  | 
|  | 344 | <p>First, the debugging assertions in code are not enabled in optimized or | 
|  | 345 | profiling builds.  Hence, tests that used to fail may pass.</p> | 
|  | 346 |  | 
|  | 347 | <p>Second, some tests may rely upon debugging options or behavior that is only | 
|  | 348 | available in the debug build.  These tests will fail in an optimized or profile | 
|  | 349 | build.</p> | 
|  | 350 |  | 
|  | 351 | </div> | 
|  | 352 |  | 
| Chris Lattner | 8a0b924 | 2003-12-08 05:43:19 +0000 | [diff] [blame] | 353 | <div class="question"> | 
| Chris Lattner | 306acee | 2003-12-22 04:06:12 +0000 | [diff] [blame] | 354 | <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] | 355 | </div> | 
|  | 356 |  | 
|  | 357 | <div class="answer"> | 
| Chris Lattner | 306acee | 2003-12-22 04:06:12 +0000 | [diff] [blame] | 358 | <p>This is <a href="http://gcc.gnu.org/PR?13392">a bug in GCC</a>, and | 
|  | 359 | affects projects other than LLVM.  Try upgrading or downgrading your GCC.</p> | 
| Chris Lattner | 8a0b924 | 2003-12-08 05:43:19 +0000 | [diff] [blame] | 360 | </div> | 
|  | 361 |  | 
| John Criswell | d179961 | 2004-03-29 20:23:11 +0000 | [diff] [blame] | 362 | <div class="question"> | 
| Misha Brukman | 1739aec | 2004-09-09 16:36:47 +0000 | [diff] [blame] | 363 | <p>After CVS update, rebuilding gives the error "No rule to make target".</p> | 
|  | 364 | </div> | 
|  | 365 |  | 
|  | 366 | <div class="answer"> | 
|  | 367 | <p>If the error is of the form:</p> | 
|  | 368 |  | 
|  | 369 | <div class="doc_code"> | 
|  | 370 | <tt> | 
|  | 371 | gmake[2]: *** No rule to make target `/path/to/somefile', needed by | 
|  | 372 | `/path/to/another/file.d'.<br> | 
|  | 373 | Stop. | 
|  | 374 | </tt> | 
|  | 375 | </div> | 
|  | 376 |  | 
|  | 377 | <p>This may occur anytime files are moved within the CVS repository or removed | 
|  | 378 | entirely.  In this case, the best solution is to erase all <tt>.d</tt> files, | 
|  | 379 | which list dependencies for source files, and rebuild:</p> | 
|  | 380 |  | 
|  | 381 | <div class="doc_code"> | 
|  | 382 | <pre> | 
|  | 383 | % cd $LLVM_OBJ_DIR | 
|  | 384 | % rm -f `find . -name \*\.d` | 
|  | 385 | % gmake | 
|  | 386 | </pre> | 
|  | 387 | </div> | 
|  | 388 |  | 
|  | 389 | <p>In other cases, it may be necessary to run <tt>make clean</tt> before | 
|  | 390 | rebuilding.</p> | 
|  | 391 | </div> | 
|  | 392 |  | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 393 | <!-- *********************************************************************** --> | 
| John Criswell | 6ea30b0 | 2003-11-18 16:05:23 +0000 | [diff] [blame] | 394 | <div class="doc_section"> | 
| Reid Spencer | 501bfee | 2006-04-26 14:52:19 +0000 | [diff] [blame^] | 395 | <a name="felangs">Source Languages</a> | 
|  | 396 | </div> | 
|  | 397 |  | 
|  | 398 | <div class="question"><p>What source languages are supported?</p></div> | 
|  | 399 | <div name="langs" class="answer"> | 
|  | 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 | 
|  | 404 | <tt>llvm-java</tt> CVS repository. There is no documentation on this yet so | 
|  | 405 | you'll need to download the code, compile it, and try it.</p> | 
|  | 406 | <p>In the <tt>examples/BFtoLLVM</tt> directory is a translator for the | 
|  | 407 | BrainF*** language (2002 Language Specification).</p> | 
|  | 408 | <p>In the <tt>projects/Stacker</tt> directory is a compiler and runtime | 
|  | 409 | library for the Stacker language, a "toy" language loosely based on Forth.</p> | 
|  | 410 | <p>The PyPy developers are working on integrating LLVM into the PyPy backend | 
|  | 411 | so that PyPy language can translate to LLVM.</p> | 
|  | 412 | </div> | 
|  | 413 | <div name="langhlsupp" class="question"> | 
|  | 414 | <p>What support is there for a higher level source language constructs for | 
|  | 415 | building a compiler?</p> | 
|  | 416 | </div> | 
|  | 417 | <div class="answer"> | 
|  | 418 | <p>Currently, there isn't much. LLVM supports an intermediate representation | 
|  | 419 | which is useful for code representation but will not support the high level | 
|  | 420 | (abstract syntax tree) representation needed by most compilers. There are no | 
|  | 421 | facilities for lexical nor semantica analysis. There is, however, a <i>mostly | 
|  | 422 | implemented</i> configuration-driven | 
|  | 423 | <a href="CompilerDriver.html">compiler driver</a> which simplifies the task | 
|  | 424 | of running optimizations, linking, and executable generation.</p> | 
|  | 425 | <p>You might be interested in following the progress of the <a | 
|  | 426 | href="http://hlvm.org">HLVM Project</a> which is attempting to address these | 
|  | 427 | issues.</p> | 
|  | 428 | </div> | 
|  | 429 | <!-- *********************************************************************** --> | 
|  | 430 | <div class="doc_section"> | 
| Chris Lattner | cc33d70 | 2003-11-19 05:53:12 +0000 | [diff] [blame] | 431 | <a name="cfe">Using the GCC Front End</a> | 
| John Criswell | 6ea30b0 | 2003-11-18 16:05:23 +0000 | [diff] [blame] | 432 | </div> | 
|  | 433 |  | 
|  | 434 | <div class="question"> | 
|  | 435 | <p> | 
|  | 436 | When I compile software that uses a configure script, the configure script | 
|  | 437 | thinks my system has all of the header files and libraries it is testing for. | 
|  | 438 | How do I get configure to work correctly? | 
|  | 439 | </p> | 
|  | 440 | </div> | 
|  | 441 |  | 
|  | 442 | <div class="answer"> | 
|  | 443 | <p> | 
|  | 444 | The configure script is getting things wrong because the LLVM linker allows | 
|  | 445 | symbols to be undefined at link time (so that they can be resolved during JIT | 
|  | 446 | or translation to the C back end).  That is why configure thinks your system | 
|  | 447 | "has everything." | 
|  | 448 | </p> | 
|  | 449 | <p> | 
|  | 450 | To work around this, perform the following steps: | 
|  | 451 | </p> | 
|  | 452 |  | 
|  | 453 | <ol> | 
|  | 454 | <li> | 
|  | 455 | Make sure the CC and CXX environment variables contains the full path to the | 
|  | 456 | LLVM GCC front end. | 
|  | 457 | </li> | 
|  | 458 |  | 
|  | 459 | <li> | 
|  | 460 | Make sure that the regular C compiler is first in your PATH. | 
|  | 461 | </li> | 
|  | 462 |  | 
|  | 463 | <li> | 
|  | 464 | Add the string "-Wl,-native" to your CFLAGS environment variable. | 
|  | 465 | </li> | 
|  | 466 | </ol> | 
|  | 467 |  | 
|  | 468 | <p> | 
|  | 469 | This will allow the gccld linker to create a native code executable instead of | 
|  | 470 | a shell script that runs the JIT.  Creating native code requires standard | 
|  | 471 | linkage, which in turn will allow the configure script to find out if code is | 
|  | 472 | not linking on your system because the feature isn't available on your system. | 
|  | 473 | </p> | 
|  | 474 | </div> | 
|  | 475 |  | 
| Chris Lattner | cc33d70 | 2003-11-19 05:53:12 +0000 | [diff] [blame] | 476 | <div class="question"> | 
| John Criswell | 6ea30b0 | 2003-11-18 16:05:23 +0000 | [diff] [blame] | 477 | <p> | 
|  | 478 | 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] | 479 | find libcrtend.a. | 
| John Criswell | 6ea30b0 | 2003-11-18 16:05:23 +0000 | [diff] [blame] | 480 | </p> | 
|  | 481 | </div> | 
|  | 482 |  | 
| Chris Lattner | cc33d70 | 2003-11-19 05:53:12 +0000 | [diff] [blame] | 483 | <div class="answer"> | 
| John Criswell | 6ea30b0 | 2003-11-18 16:05:23 +0000 | [diff] [blame] | 484 | <p> | 
| Reid Spencer | f96eb57 | 2004-12-15 00:14:01 +0000 | [diff] [blame] | 485 | The only way this can happen is if you haven't installed the runtime library. To | 
|  | 486 | correct this, do:</p> | 
|  | 487 | <pre> | 
|  | 488 | % cd llvm/runtime | 
|  | 489 | % make clean ; make install-bytecode | 
|  | 490 | </pre> | 
| John Criswell | 6ea30b0 | 2003-11-18 16:05:23 +0000 | [diff] [blame] | 491 | </div> | 
| Chris Lattner | cc33d70 | 2003-11-19 05:53:12 +0000 | [diff] [blame] | 492 |  | 
| Tanya Lattner | 14fc5c1 | 2005-04-25 20:36:56 +0000 | [diff] [blame] | 493 | <div class="question"> | 
|  | 494 | <p> | 
|  | 495 | How can I disable all optimizations when compiling code using the LLVM GCC front end? | 
|  | 496 | </p> | 
|  | 497 | </div> | 
|  | 498 |  | 
|  | 499 | <div class="answer"> | 
|  | 500 | <p> | 
|  | 501 | Passing "-Wa,-disable-opt -Wl,-disable-opt" will disable *all* cleanup and | 
|  | 502 | optimizations done at the llvm level, leaving you with the truly horrible | 
|  | 503 | code that you desire. | 
|  | 504 | </p> | 
|  | 505 | </div> | 
| Chris Lattner | cc33d70 | 2003-11-19 05:53:12 +0000 | [diff] [blame] | 506 |  | 
|  | 507 | <!-- *********************************************************************** --> | 
|  | 508 | <div class="doc_section"> | 
|  | 509 | <a name="cfe_code">Questions about code generated by the GCC front-end</a> | 
|  | 510 | </div> | 
|  | 511 |  | 
| Chris Lattner | a28e3ce | 2003-12-16 22:33:55 +0000 | [diff] [blame] | 512 | <div class="question"><p> | 
| Chris Lattner | 5a53c5d | 2005-02-25 20:30:21 +0000 | [diff] [blame] | 513 | <a name="__main"></a> | 
| Chris Lattner | cc33d70 | 2003-11-19 05:53:12 +0000 | [diff] [blame] | 514 | What is this <tt>__main()</tt> call that gets inserted into <tt>main()</tt>? | 
| Chris Lattner | a28e3ce | 2003-12-16 22:33:55 +0000 | [diff] [blame] | 515 | </p></div> | 
| Chris Lattner | cc33d70 | 2003-11-19 05:53:12 +0000 | [diff] [blame] | 516 |  | 
|  | 517 | <div class="answer"> | 
|  | 518 | <p> | 
|  | 519 | The <tt>__main</tt> call is inserted by the C/C++ compiler in order to guarantee | 
|  | 520 | that static constructors and destructors are called when the program starts up | 
|  | 521 | and shuts down.  In C, you can create static constructors and destructors by | 
|  | 522 | using GCC extensions, and in C++ you can do so by creating a global variable | 
|  | 523 | whose class has a ctor or dtor. | 
|  | 524 | </p> | 
|  | 525 |  | 
|  | 526 | <p> | 
|  | 527 | The actual implementation of <tt>__main</tt> lives in the | 
|  | 528 | <tt>llvm/runtime/GCCLibraries/crtend/</tt> directory in the source-base, and is | 
|  | 529 | linked in automatically when you link the program. | 
|  | 530 | </p> | 
| Chris Lattner | cc33d70 | 2003-11-19 05:53:12 +0000 | [diff] [blame] | 531 | </div> | 
|  | 532 |  | 
| Chris Lattner | a28e3ce | 2003-12-16 22:33:55 +0000 | [diff] [blame] | 533 | <!--=========================================================================--> | 
| Chris Lattner | cc33d70 | 2003-11-19 05:53:12 +0000 | [diff] [blame] | 534 |  | 
| Misha Brukman | 237dc2a | 2004-12-03 23:58:18 +0000 | [diff] [blame] | 535 | <div class="question"> | 
| Chris Lattner | 5a53c5d | 2005-02-25 20:30:21 +0000 | [diff] [blame] | 536 | <a name="iosinit"></a> | 
| Misha Brukman | 237dc2a | 2004-12-03 23:58:18 +0000 | [diff] [blame] | 537 | <p> What is this <tt>llvm.global_ctors</tt> and | 
|  | 538 | <tt>_GLOBAL__I__tmp_webcompile...</tt> stuff that happens when I #include | 
|  | 539 | <iostream>?</p> | 
|  | 540 | </div> | 
| Chris Lattner | c50bbc9 | 2004-03-29 19:14:35 +0000 | [diff] [blame] | 541 |  | 
|  | 542 | <div class="answer"> | 
| Misha Brukman | 237dc2a | 2004-12-03 23:58:18 +0000 | [diff] [blame] | 543 |  | 
|  | 544 | <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] | 545 | file will probably use the <tt>std::cin</tt>/<tt>std::cout</tt>/... global | 
|  | 546 | objects.  However, C++ does not guarantee an order of initialization between | 
|  | 547 | static objects in different translation units, so if a static ctor/dtor in your | 
|  | 548 | .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] | 549 | be automatically initialized before your use.</p> | 
| Chris Lattner | c50bbc9 | 2004-03-29 19:14:35 +0000 | [diff] [blame] | 550 |  | 
| Misha Brukman | 237dc2a | 2004-12-03 23:58:18 +0000 | [diff] [blame] | 551 | <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] | 552 | 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] | 553 | unit that includes <tt><iostream></tt>.  This object has a static | 
|  | 554 | constructor and destructor that initializes and destroys the global iostream | 
|  | 555 | objects before they could possibly be used in the file.  The code that you see | 
|  | 556 | in the .ll file corresponds to the constructor and destructor registration code. | 
| Chris Lattner | c50bbc9 | 2004-03-29 19:14:35 +0000 | [diff] [blame] | 557 | </p> | 
|  | 558 |  | 
| Misha Brukman | 237dc2a | 2004-12-03 23:58:18 +0000 | [diff] [blame] | 559 | <p>If you would like to make it easier to <b>understand</b> the LLVM code | 
|  | 560 | generated by the compiler in the demo page, consider using <tt>printf()</tt> | 
|  | 561 | instead of <tt>iostream</tt>s to print values.</p> | 
|  | 562 |  | 
| Chris Lattner | c50bbc9 | 2004-03-29 19:14:35 +0000 | [diff] [blame] | 563 | </div> | 
|  | 564 |  | 
| Chris Lattner | 5a53c5d | 2005-02-25 20:30:21 +0000 | [diff] [blame] | 565 | <!--=========================================================================--> | 
|  | 566 |  | 
|  | 567 | <div class="question"><p> | 
|  | 568 | <a name="codedce"></a> | 
|  | 569 | Where did all of my code go?? | 
|  | 570 | </p></div> | 
|  | 571 |  | 
|  | 572 | <div class="answer"> | 
|  | 573 | <p> | 
|  | 574 | If you are using the LLVM demo page, you may often wonder what happened to all | 
|  | 575 | of the code that you typed in.  Remember that the demo script is running the | 
|  | 576 | code through the LLVM optimizers, so if your code doesn't actually do anything | 
|  | 577 | useful, it might all be deleted. | 
|  | 578 | </p> | 
|  | 579 |  | 
|  | 580 | <p> | 
|  | 581 | To prevent this, make sure that the code is actually needed.  For example, if | 
|  | 582 | you are computing some expression, return the value from the function instead of | 
|  | 583 | leaving it in a local variable.  If you really want to constrain the optimizer, | 
|  | 584 | you can read from and assign to <tt>volatile</tt> global variables. | 
|  | 585 | </p> | 
|  | 586 | </div> | 
|  | 587 |  | 
|  | 588 | <!--=========================================================================--> | 
|  | 589 |  | 
|  | 590 | <div class="question"><p> | 
|  | 591 | <a name="undef"></a> | 
|  | 592 | <p>What is this "<tt>undef</tt>" thing that shows up in my code? | 
|  | 593 | </p></div> | 
|  | 594 |  | 
|  | 595 | <div class="answer"> | 
|  | 596 | <p> | 
|  | 597 | <a href="LangRef.html#undef"><tt>undef</tt></a> is the LLVM way of representing | 
|  | 598 | a value that is not defined.  You can get these if you do not initialize a | 
|  | 599 | variable before you use it.  For example, the C function:</p> | 
|  | 600 |  | 
|  | 601 | <div class="doc_code"> | 
|  | 602 | <tt>int X() { int i; return i; }</tt> | 
|  | 603 | </div> | 
|  | 604 |  | 
|  | 605 | <p>Is compiled to "<tt>ret int undef</tt>" because "i" never has a value | 
|  | 606 | specified for it. | 
|  | 607 | </p> | 
|  | 608 | </div> | 
|  | 609 |  | 
| John Criswell | 6ea30b0 | 2003-11-18 16:05:23 +0000 | [diff] [blame] | 610 | <!-- *********************************************************************** --> | 
| John Criswell | c310f62 | 2003-10-13 16:13:06 +0000 | [diff] [blame] | 611 |  | 
|  | 612 | <hr> | 
| Misha Brukman | 7ce62cc | 2004-06-01 18:51:03 +0000 | [diff] [blame] | 613 | <address> | 
|  | 614 | <a href="http://jigsaw.w3.org/css-validator/check/referer"><img | 
|  | 615 | src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a> | 
|  | 616 | <a href="http://validator.w3.org/check/referer"><img | 
|  | 617 | src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a> | 
|  | 618 |  | 
| Reid Spencer | 05fe4b0 | 2006-03-14 05:39:39 +0000 | [diff] [blame] | 619 | <a href="http://llvm.org">LLVM Compiler Infrastructure</a><br> | 
| Misha Brukman | a653885 | 2003-11-06 21:55:44 +0000 | [diff] [blame] | 620 | Last modified: $Date$ | 
| Misha Brukman | 7ce62cc | 2004-06-01 18:51:03 +0000 | [diff] [blame] | 621 | </address> | 
| John Criswell | f08c5d8 | 2003-10-24 22:48:20 +0000 | [diff] [blame] | 622 |  | 
| John Criswell | c310f62 | 2003-10-13 16:13:06 +0000 | [diff] [blame] | 623 | </body> | 
|  | 624 | </html> |