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