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