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