Nick Lewycky | ebc6765 | 2009-03-01 09:38:29 +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 gold plugin</title> |
| 6 | <link rel="stylesheet" href="llvm.css" type="text/css"> |
| 7 | </head> |
| 8 | <body> |
| 9 | |
| 10 | <div class="doc_title">LLVM gold plugin</div> |
| 11 | <ol> |
| 12 | <li><a href="#introduction">Introduction</a></li> |
| 13 | <li><a href="#build">How to build it</a></li> |
| 14 | <li><a href="#usage">Usage</a></li> |
| 15 | <li><a href="#licensing">Licensing</a></li> |
| 16 | </ol> |
| 17 | <div class="doc_author">Written by Nick Lewycky</div> |
| 18 | |
| 19 | <!--=========================================================================--> |
| 20 | <div class="doc_section"><a name="introduction">Introduction</a></div> |
| 21 | <!--=========================================================================--> |
| 22 | <div class="doc_text"> |
| 23 | <p>Building with link time optimization requires cooperation with the |
| 24 | system linker. To support LTO on Linux systems, we requires that you use |
| 25 | <a href="http://sourceware.org/binutils">gold</a> which has support for |
| 26 | LTO via plugins. This is the same system used by the upcoming |
| 27 | <a href="http://gcc.gnu.org/wiki/LinkTimeOptimization">GCC LTO</a> |
| 28 | support.</p> |
| 29 | <p>The LLVMgold plugin implements the gold |
| 30 | <a href="http://gcc.gnu.org/wiki/whopr/driver">plugin interface</a> on |
| 31 | top of |
| 32 | <a href="http://llvm.org/docs/LinkTimeOptimization.html#lto">libLTO</a>. |
| 33 | The same plugin can also be used by other tools such as <tt>ar</tt> and |
| 34 | <tt>nm</tt>. |
| 35 | </div> |
| 36 | <!--=========================================================================--> |
| 37 | <div class="doc_section"><a name="build">How to build it</a></div> |
| 38 | <!--=========================================================================--> |
| 39 | <div class="doc_text"> |
| 40 | <p>You need to build gold with plugin support and build the LLVMgold |
| 41 | plugin.</p> |
| 42 | <ul> |
| 43 | <li>Build gold with plugin support: |
| 44 | <pre class="doc_code"> |
| 45 | mkdir binutils |
| 46 | cd binutils |
| 47 | cvs -z 9 -d :pserver:anoncvs@sourceware.org:/cvs/src login |
| 48 | <em>{enter "anoncvs" as the password}</em> |
| 49 | cvs -z 9 -d :pserver:anoncvs@sourceware.org:/cvs/src co src |
| 50 | mkdir build |
| 51 | cd build |
| 52 | ../src/configure --enable-gold --enable-plugins |
| 53 | make all-gold |
| 54 | </pre> |
| 55 | That should leave you with binutils/build/gold/ld-new which supports the |
| 56 | -plugin option. |
| 57 | |
| 58 | <li>Build LLVMgold. Configure LLVM with |
| 59 | <tt>--with-binutils-include=/path/to/binutils/src/include</tt> and run |
| 60 | <tt>make</tt>. |
| 61 | </ul> |
| 62 | </div> |
| 63 | <!--=========================================================================--> |
| 64 | <div class="doc_section"><a name="usage">Usage</a></div> |
| 65 | <!--=========================================================================--> |
| 66 | <div class="doc_text"> |
| 67 | <p>The linker takes a <tt>-plugin</tt> option that points to the path of |
| 68 | the plugin <tt>.so</tt> file. To find out what link command <tt>gcc</tt> |
| 69 | would run in a given situation, run <tt>gcc -v <em>[...]</em></tt> and look |
| 70 | for the line where it runs <tt>collect2</tt>. Replace that with |
| 71 | <tt>ld-new -plugin /path/to/LLVMgold.so</tt> to test it out. Once you're |
| 72 | ready to switch to using gold, backup your existing <tt>/usr/bin/ld</tt> |
| 73 | then replace it with <tt>ld-new</tt>.</p> |
| 74 | <p>You can produce bitcode files from <tt>llvm-gcc</tt> using |
| 75 | <tt>-emit-llvm</tt> or <tt>-flto</tt> or <tt>-O4</tt> which is equivalent |
| 76 | to <tt>-O3 -flto</tt>.</p> |
| 77 | <p><tt>llvm-gcc</tt> has a <tt>-use-gold-plugin</tt> option which looks |
| 78 | for the gold plugin in the same directories as it looks for <tt>cc1</tt>. |
| 79 | It will not look for an alternate linker, which is why you need gold to be |
| 80 | the installed system linker in your path.</p> |
| 81 | </div> |
| 82 | <!--=========================================================================--> |
| 83 | <div class="doc_section"><a name="licensing">Licensing</a></div> |
| 84 | <!--=========================================================================--> |
| 85 | <div class="doc_text"> |
| 86 | Gold is licensed under the GPLv3. LLVMgold uses the interface file |
| 87 | <tt>plugin-api.h</tt> from gold which means that the resulting LLVMgold.so |
| 88 | binary is also GPLv3. This can still be used to link non-GPLv3 programs just |
| 89 | as much as gold could without the plugin. |
| 90 | </div> |
| 91 | |
| 92 | <!-- *********************************************************************** --> |
| 93 | <hr> |
| 94 | <address> |
| 95 | <a href="http://jigsaw.w3.org/css-validator/check/referer"><img |
| 96 | src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a> |
| 97 | <a href="http://validator.w3.org/check/referer"><img |
| 98 | src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a> |
| 99 | Written by the |
| 100 | <a href="mailto:nicholas@metrix.on.ca">Nick Lewycky</a><br> |
| 101 | <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br> |
| 102 | Last modified: $Date: 2009-01-01 23:10:51 -0800 (Thu, 01 Jan 2009) $ |
| 103 | </address> |
| 104 | </body> |
| 105 | </html> |