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