PageRenderTime 31ms CodeModel.GetById 21ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/3rd_party/llvm/docs/UsingLibraries.html

https://code.google.com/p/softart/
HTML | 448 lines | 418 code | 14 blank | 16 comment | 0 complexity | b149ce87beefaa3a4c89b2f761548af2 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, JSON, MPL-2.0-no-copyleft-exception, GPL-2.0, GPL-3.0, LGPL-3.0, BSD-2-Clause
  1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2<html>
  3<head>
  4  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5  <title>Using The LLVM Libraries</title>
  6  <link rel="stylesheet" href="llvm.css" type="text/css">
  7</head>
  8<body>
  9<h1>Using The LLVM Libraries</h1>
 10<ol>
 11  <li><a href="#abstract">Abstract</a></li>
 12  <li><a href="#introduction">Introduction</a></li>
 13  <li><a href="#descriptions">Library Descriptions</a></li>
 14  <li><a href="#dependencies">Library Dependencies</a></li>
 15  <li><a href="#rot">Linkage Rules Of Thumb</a>
 16	  <ol>
 17      <li><a href="#always">Always link LLVMCore, LLVMSupport, LLVMSystem</a>
 18			<li><a href="#onlyone">Never link both archive and re-linked</a>
 19		</ol>
 20	</li>
 21</ol>
 22
 23<div class="doc_author">
 24  <p>Written by <a href="mailto:rspencer@x10sys.com">Reid Spencer</a></p>
 25</div>
 26
 27<p class="doc_warning">Warning: This document is out of date, for more
 28  information please
 29  see <a href="CommandGuide/html/llvm-config.html">llvm-config</a> or,
 30  if you use CMake, <a href="CMake.html#embedding">the CMake LLVM
 31  guide</a>.</p>
 32
 33<!-- ======================================================================= -->
 34<h2><a name="abstract">Abstract</a></h2>
 35<div>
 36  <p>Amongst other things, LLVM is a toolkit for building compilers, linkers,
 37  runtime executives, virtual machines, and other program execution related
 38  tools. In addition to the LLVM tool set, the functionality of LLVM is
 39  available through a set of libraries.  To use LLVM as a toolkit for
 40  constructing tools, a developer needs to understand what is contained in the
 41  various libraries, what they depend on, and how to use them.  Fortunately,
 42  there is a tool, <tt>llvm-config</tt> to aid with this. This document 
 43  describes the contents of the libraries and how to use <tt>llvm-config</tt>
 44  to generate command line options.
 45</p>
 46</div>
 47
 48<!-- ======================================================================= -->
 49<h2><a name="introduction">Introduction</a></h2>
 50<div>
 51  <p>If you're writing a compiler, virtual machine, or any other utility based 
 52  on LLVM, you'll need to figure out which of the many libraries files you will 
 53  need to link with to be successful. An understanding of the contents of these 
 54  libraries will be useful in coming up with an optimal specification for the 
 55  libraries to link with. The purpose of this document is to reduce some of 
 56  the trial and error that the author experienced in using LLVM.</p>
 57  <p>LLVM produces two types of libraries: archives (ending in <tt>.a</tt>) and
 58  objects (ending in <tt>.o</tt>). However, both are libraries. Libraries ending
 59  in <tt>.o</tt> are known as re-linked libraries because they contain all the
 60  compilation units of the library linked together as a single <tt>.o</tt> file.
 61  Furthermore, several of the libraries have <em>both</em> forms of library. The
 62  re-linked libraries are used whenever you want to include all symbols from the
 63  library. The archive libraries are used whenever you want to only resolve
 64  outstanding symbols at that point in the link without including everything in
 65  the library. </p>
 66  <p>If you're using the LLVM Makefile system to link your tools,you will use 
 67  the <tt>LLVMLIBS</tt> make variable. 
 68  (see the <a href="MakefileGuide.html#LLVMLIBS">Makefile Guide</a> for 
 69  details). This variable specifies which LLVM libraries to link into your tool 
 70  and the order in which they will be linked. You specify re-linked libraries by
 71  naming the library without a suffix. You specify archive libraries by naming
 72  the library with a <tt>.a</tt> suffix but without the <tt>lib</tt> prefix. The
 73  order in which the libraries appear in the <tt>LLVMLIBS</tt> variable
 74  definition is the order in which they will be linked. Getting this order
 75  correct for your tool can sometimes be challenging.
 76</div>
 77<!-- ======================================================================= -->
 78<h2><a name="descriptions">Library Descriptions</a></h2>
 79<div>
 80  <p>The table below categorizes each library
 81<table style="text-align:left">
 82  <tr><th>Library</th><th>Forms</th><th>Description</th></tr>
 83  <tr><th colspan="3">Core Libraries</th></tr>
 84  <tr><td>LLVMArchive</td><td><tt>.a</tt></td>
 85    <td>LLVM archive reading and writing</td></tr>
 86  <tr><td>LLVMAsmParser</td><td><tt>.a</tt></td>
 87    <td>LLVM assembly parsing</td></tr>
 88  <tr><td>LLVMBCReader</td><td><tt>.a</tt></td>
 89    <td>LLVM bitcode reading</td></tr>
 90  <tr><td>LLVMBCWriter</td><td><tt>.a</tt></td>
 91    <td>LLVM bitcode writing</td></tr>
 92  <tr><td>LLVMCore</td><td><tt>.a</tt></td>
 93    <td>LLVM core intermediate representation</td></tr>
 94  <tr><td>LLVMDebugger</td><td><tt>.a</tt></td>
 95    <td>Source level debugging support</td></tr>
 96  <tr><td>LLVMLinker</td><td><tt>.a</tt></td>
 97    <td>Bitcode and archive linking interface</td></tr>
 98  <tr><td>LLVMSupport</td><td><tt>.a</tt></td>
 99    <td>General support utilities</td></tr>
100  <tr><td>LLVMSystem</td><td><tt>.a</tt></td>
101    <td>Operating system abstraction layer</td></tr>
102  <tr><td>LLVMbzip2</td><td><tt>.a</tt></td>
103    <td>BZip2 compression library</td></tr>
104
105  <tr><th colspan="3">Analysis Libraries</th></tr>
106  <tr><td>LLVMAnalysis</td><td><tt>.a</tt></td>
107    <td>Various analysis passes.</td></tr>
108  <tr><td>LLVMDataStructure</td><td><tt>.o</tt></td>
109    <td>Data structure analysis passes.</td></tr>
110  <tr><td>LLVMipa</td><td><tt>.a</tt></td>
111    <td>Inter-procedural analysis passes.</td></tr>
112
113  <tr><th colspan="3">Transformation Libraries</th></tr>
114  <tr><td>LLVMInstrumentation</td><td><tt>.a</tt></td>
115    <td>Instrumentation passes.</td></tr>
116  <tr><td>LLVMipo</td><td><tt>.a</tt></td>
117    <td>All inter-procedural optimization passes.</td></tr>
118  <tr><td>LLVMScalarOpts</td><td><tt>.a</tt></td>
119    <td>All scalar optimization passes.</td></tr>
120  <tr><td>LLVMTransformUtils</td><td><tt>.a</tt></td>
121    <td>Transformation utilities used by many passes.</td></tr>
122
123  <tr><th colspan="3">Code Generation Libraries </th></tr>
124  <tr><td>LLVMCodeGen</td><td><tt>.o</tt></td>
125    <td>Native code generation infrastructure</td></tr>
126  <tr><td>LLVMSelectionDAG</td><td><tt>.o</tt></td>
127    <td>Aggressive instruction selector for directed acyclic graphs</td></tr>
128
129  <tr><th colspan="3">Target Libraries</th></tr>
130  <tr><td>LLVMAlpha</td><td><tt>.o</tt></td>
131    <td>Code generation for Alpha architecture</td></tr>
132  <tr><td>LLVMARM</td><td><tt>.o</tt></td>
133    <td>Code generation for ARM architecture</td></tr>
134  <tr><td>LLVMCBackend</td><td><tt>.o</tt></td>
135    <td>'C' language code generator.</td></tr>
136  <tr><td>LLVMPowerPC</td><td><tt>.o</tt></td>
137    <td>Code generation for PowerPC architecture</td></tr>
138  <tr><td>LLVMSparc</td><td><tt>.o</tt></td>
139    <td>Code generation for Sparc architecture</td></tr>
140  <tr><td>LLVMTarget</td><td><tt>.a</tt></td>
141    <td>Generic code generation utilities.</td></tr>
142  <tr><td>LLVMX86</td><td><tt>.o</tt></td>
143    <td>Code generation for Intel x86 architecture</td></tr>
144
145  <tr><th colspan="3">Runtime Libraries</th></tr>
146  <tr><td>LLVMInterpreter</td><td><tt>.o</tt></td>
147    <td>Bitcode Interpreter</td></tr>
148  <tr><td>LLVMJIT</td><td><tt>.o</tt></td>
149    <td>Bitcode JIT Compiler</td></tr>
150  <tr><td>LLVMExecutionEngine</td><td><tt>.o</tt></td>
151    <td>Virtual machine engine</td></tr>
152</table>
153</div>
154
155<!-- ======================================================================= -->
156<h2><a name="dependencies">Using llvm-config</a></h2>
157<div>
158  <p>The <tt>llvm-config</tt> tool is a perl script that produces on its output
159  various kinds of information. For example, the source or object directories 
160  used to build LLVM can be accessed by passing options to <tt>llvm-config</tt>.
161  For complete details on this tool, please see the
162  <a href="CommandGuide/html/llvm-config.html">manual page</a>.</p>
163  <p>To understand the relationships between libraries, the <tt>llvm-config</tt>
164  can be very useful. If all you know is that you want certain libraries to
165  be available, you can generate the complete set of libraries to link with
166  using one of four options, as below:</p>
167  <ol>
168    <li><tt>--ldflags</tt>. This generates the command line options necessary to
169    be passed to the <tt>ld</tt> tool in order to link with LLVM. Most notably,
170    the <tt>-L</tt> option is provided to specify a library search directory 
171    that contains the LLVM libraries.</li>
172    <li><tt>--libs</tt>. This generates command line options suitable for
173    use with a gcc-style linker. That is, libraries are given with a -l option
174    and object files are given with a full path.</li>
175    <li><tt>--libnames</tt>. This generates a list of just the library file
176    names. If you know the directory in which these files reside (see --ldflags)
177    then you can find the libraries there.</li>
178    <li><tt>--libfiles</tt>. This generates the full path names of the
179    LLVM library files.</li>
180  </ol>
181  <p>If you wish to delve further into how <tt>llvm-config</tt> generates the
182  correct order (based on library dependencies), please see the tool named
183  <tt>GenLibDeps.pl</tt> in the <tt>utils</tt> source directory of LLVM.</p>
184
185  <!-- =======NOTE: =========================================================-->
186  <!-- === The following graphs and <dl> list are generated automatically ===-->
187  <!-- === by the util named GenLibDeps.pl in the llvm/utils directory.   ===-->
188  <!-- === This should be updated whenever new libraries are added,       ===-->
189  <!-- === removed, or changed                                            ===-->
190  <!-- =======NOTE: =========================================================-->
191  <h3>Dependency Relationships Of Libraries</h3>
192  <p>This graph shows the dependency of archive libraries on other archive 
193  libraries or objects. Where a library has both archive and object forms, only
194  the archive form is shown.</p>
195  <img src="img/libdeps.gif" alt="Library Dependencies">
196  <h3>Dependency Relationships Of Object Files</h3>
197  <p>This graph shows the dependency of object files on archive libraries or 
198  other objects. Where a library has both object and archive forms, only the 
199  dependency to the archive form is shown.</p> 
200  <img src="img/objdeps.gif" alt="Object File Dependencies">
201  <p>The following list shows the dependency relationships between libraries in
202  textual form. The information is the same as shown on the graphs but arranged
203  alphabetically.</p>
204<dl>
205  <dt><b>libLLVMAnalysis.a</b></dt><dd><ul>
206    <li>libLLVMCore.a</li>
207    <li>libLLVMSupport.a</li>
208    <li>libLLVMSystem.a</li>
209    <li>libLLVMTarget.a</li>
210  </ul></dd>
211  <dt><b>libLLVMArchive.a</b></dt><dd><ul>
212    <li>libLLVMBCReader.a</li>
213    <li>libLLVMCore.a</li>
214    <li>libLLVMSupport.a</li>
215    <li>libLLVMSystem.a</li>
216  </ul></dd>
217  <dt><b>libLLVMAsmParser.a</b></dt><dd><ul>
218    <li>libLLVMCore.a</li>
219    <li>libLLVMSystem.a</li>
220  </ul></dd>
221  <dt><b>libLLVMBCReader.a</b></dt><dd><ul>
222    <li>libLLVMCore.a</li>
223    <li>libLLVMSupport.a</li>
224    <li>libLLVMSystem.a</li>
225  </ul></dd>
226  <dt><b>libLLVMBCWriter.a</b></dt><dd><ul>
227    <li>libLLVMCore.a</li>
228    <li>libLLVMSupport.a</li>
229    <li>libLLVMSystem.a</li>
230  </ul></dd>
231  <dt><b>libLLVMCodeGen.a</b></dt><dd><ul>
232    <li>libLLVMAnalysis.a</li>
233    <li>libLLVMCore.a</li>
234    <li>libLLVMScalarOpts.a</li>
235    <li>libLLVMSupport.a</li>
236    <li>libLLVMSystem.a</li>
237    <li>libLLVMTarget.a</li>
238    <li>libLLVMTransformUtils.a</li>
239  </ul></dd>
240  <dt><b>libLLVMCore.a</b></dt><dd><ul>
241    <li>libLLVMSupport.a</li>
242    <li>libLLVMSystem.a</li>
243  </ul></dd>
244  <dt><b>libLLVMDebugger.a</b></dt><dd><ul>
245    <li>libLLVMBCReader.a</li>
246    <li>libLLVMCore.a</li>
247    <li>libLLVMSupport.a</li>
248    <li>libLLVMSystem.a</li>
249  </ul></dd>
250  <dt><b>libLLVMInstrumentation.a</b></dt><dd><ul>
251    <li>libLLVMCore.a</li>
252    <li>libLLVMScalarOpts.a</li>
253    <li>libLLVMSupport.a</li>
254    <li>libLLVMTransformUtils.a</li>
255  </ul></dd>
256  <dt><b>libLLVMLinker.a</b></dt><dd><ul>
257    <li>libLLVMArchive.a</li>
258    <li>libLLVMBCReader.a</li>
259    <li>libLLVMCore.a</li>
260    <li>libLLVMSupport.a</li>
261    <li>libLLVMSystem.a</li>
262  </ul></dd>
263  <dt><b>libLLVMScalarOpts.a</b></dt><dd><ul>
264    <li>libLLVMAnalysis.a</li>
265    <li>libLLVMCore.a</li>
266    <li>libLLVMSupport.a</li>
267    <li>libLLVMSystem.a</li>
268    <li>libLLVMTarget.a</li>
269    <li>libLLVMTransformUtils.a</li>
270  </ul></dd>
271  <dt><b>libLLVMSelectionDAG.a</b></dt><dd><ul>
272    <li>libLLVMAnalysis.a</li>
273    <li>libLLVMCodeGen.a</li>
274    <li>libLLVMCore.a</li>
275    <li>libLLVMSupport.a</li>
276    <li>libLLVMSystem.a</li>
277    <li>libLLVMTarget.a</li>
278    <li>libLLVMTransformUtils.a</li>
279  </ul></dd>
280  <dt><b>libLLVMSupport.a</b></dt><dd><ul>
281    <li>libLLVMSystem.a</li>
282    <li>libLLVMbzip2.a</li>
283  </ul></dd>
284  <dt><b>libLLVMSystem.a</b></dt><dd>
285  </dd>
286  <dt><b>libLLVMTarget.a</b></dt><dd><ul>
287    <li>libLLVMCore.a</li>
288    <li>libLLVMSupport.a</li>
289    <li>libLLVMSystem.a</li>
290  </ul></dd>
291  <dt><b>libLLVMTransformUtils.a</b></dt><dd><ul>
292    <li>libLLVMAnalysis.a</li>
293    <li>libLLVMCore.a</li>
294    <li>libLLVMSupport.a</li>
295    <li>libLLVMSystem.a</li>
296    <li>libLLVMTarget.a</li>
297    <li>libLLVMipa.a</li>
298  </ul></dd>
299  <dt><b>libLLVMbzip2.a</b></dt><dd>
300  </dd>
301  <dt><b>libLLVMipa.a</b></dt><dd><ul>
302    <li>libLLVMAnalysis.a</li>
303    <li>libLLVMCore.a</li>
304    <li>libLLVMSupport.a</li>
305    <li>libLLVMSystem.a</li>
306  </ul></dd>
307  <dt><b>libLLVMipo.a</b></dt><dd><ul>
308    <li>libLLVMAnalysis.a</li>
309    <li>libLLVMCore.a</li>
310    <li>libLLVMSupport.a</li>
311    <li>libLLVMSystem.a</li>
312    <li>libLLVMTarget.a</li>
313    <li>libLLVMTransformUtils.a</li>
314    <li>libLLVMipa.a</li>
315  </ul></dd>
316  <dt><b>libLLVMlto.a</b></dt><dd><ul>
317    <li>libLLVMAnalysis.a</li>
318    <li>libLLVMBCReader.a</li>
319    <li>libLLVMBCWriter.a</li>
320    <li>libLLVMCore.a</li>
321    <li>libLLVMLinker.a</li>
322    <li>libLLVMScalarOpts.a</li>
323    <li>libLLVMSupport.a</li>
324    <li>libLLVMSystem.a</li>
325    <li>libLLVMTarget.a</li>
326    <li>libLLVMipa.a</li>
327    <li>libLLVMipo.a</li>
328  </ul></dd>
329  <dt><b>LLVMARM.o</b></dt><dd><ul>
330    <li>libLLVMCodeGen.a</li>
331    <li>libLLVMCore.a</li>
332    <li>libLLVMSelectionDAG.a</li>
333    <li>libLLVMSupport.a</li>
334    <li>libLLVMSystem.a</li>
335    <li>libLLVMTarget.a</li>
336  </ul></dd>
337  <dt><b>LLVMAlpha.o</b></dt><dd><ul>
338    <li>libLLVMCodeGen.a</li>
339    <li>libLLVMCore.a</li>
340    <li>libLLVMSelectionDAG.a</li>
341    <li>libLLVMSupport.a</li>
342    <li>libLLVMSystem.a</li>
343    <li>libLLVMTarget.a</li>
344  </ul></dd>
345  <dt><b>LLVMCBackend.o</b></dt><dd><ul>
346    <li>libLLVMAnalysis.a</li>
347    <li>libLLVMCodeGen.a</li>
348    <li>libLLVMCore.a</li>
349    <li>libLLVMScalarOpts.a</li>
350    <li>libLLVMSupport.a</li>
351    <li>libLLVMSystem.a</li>
352    <li>libLLVMTarget.a</li>
353    <li>libLLVMTransformUtils.a</li>
354    <li>libLLVMipa.a</li>
355  </ul></dd>
356  <dt><b>LLVMExecutionEngine.o</b></dt><dd><ul>
357    <li>libLLVMCore.a</li>
358    <li>libLLVMSupport.a</li>
359    <li>libLLVMSystem.a</li>
360    <li>libLLVMTarget.a</li>
361  </ul></dd>
362  <dt><b>LLVMInterpreter.o</b></dt><dd><ul>
363    <li>LLVMExecutionEngine.o</li>
364    <li>libLLVMCodeGen.a</li>
365    <li>libLLVMCore.a</li>
366    <li>libLLVMSupport.a</li>
367    <li>libLLVMSystem.a</li>
368    <li>libLLVMTarget.a</li>
369  </ul></dd>
370  <dt><b>LLVMJIT.o</b></dt><dd><ul>
371    <li>LLVMExecutionEngine.o</li>
372    <li>libLLVMCore.a</li>
373    <li>libLLVMSupport.a</li>
374    <li>libLLVMSystem.a</li>
375    <li>libLLVMTarget.a</li>
376  </ul></dd>
377  <dt><b>LLVMPowerPC.o</b></dt><dd><ul>
378    <li>libLLVMCodeGen.a</li>
379    <li>libLLVMCore.a</li>
380    <li>libLLVMSelectionDAG.a</li>
381    <li>libLLVMSupport.a</li>
382    <li>libLLVMSystem.a</li>
383    <li>libLLVMTarget.a</li>
384  </ul></dd>
385  <dt><b>LLVMSparc.o</b></dt><dd><ul>
386    <li>libLLVMCodeGen.a</li>
387    <li>libLLVMCore.a</li>
388    <li>libLLVMSelectionDAG.a</li>
389    <li>libLLVMSupport.a</li>
390    <li>libLLVMSystem.a</li>
391    <li>libLLVMTarget.a</li>
392  </ul></dd>
393  <dt><b>LLVMX86.o</b></dt><dd><ul>
394    <li>libLLVMCodeGen.a</li>
395    <li>libLLVMCore.a</li>
396    <li>libLLVMSelectionDAG.a</li>
397    <li>libLLVMSupport.a</li>
398    <li>libLLVMSystem.a</li>
399    <li>libLLVMTarget.a</li>
400  </ul></dd>
401</dl>
402</div>
403
404<!-- ======================================================================= -->
405<h2><a name="rot">Linkage Rules Of Thumb</a></h2>
406<div>
407	<p>This section contains various "rules of thumb" about what files you
408	should link into your programs.</p>
409<!-- ======================================================================= -->
410<h3>
411  <a name="always">Always Link LLVMCore, LLVMSupport, and LLVMSystem</a>
412</h3>
413<div>
414  <p>No matter what you do with LLVM, the last three entries in the value of 
415  your LLVMLIBS make variable should always be: 
416  <tt>LLVMCore LLVMSupport.a LLVMSystem.a</tt>. There are no <tt>LLVM</tt> 
417  programs that don't depend on these three.</p>
418</div>
419<!-- ======================================================================= -->
420<h3>
421  <a name="onlyone">Never link both archive and re-linked library</a>
422</h3>
423<div>
424  <p>There is never any point to linking both the re-linked (<tt>.o</tt>) and
425  the archive (<tt>.a</tt>) versions of a library. Since the re-linked version
426  includes the entire library, the archive version will not resolve any symbols.
427  You could even end up with link error if you place the archive version before
428  the re-linked version on the linker's command line.</p>
429</div>
430
431</div>
432
433<!-- ======================================================================= -->
434<hr>
435<div class="doc_footer">
436<address>
437  <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
438    src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a>
439  <a href="http://validator.w3.org/check/referer"><img
440    src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a>
441  <a href="mailto:rspencer@x10sys.com">Reid Spencer</a>
442</address>
443<a href="http://llvm.org/">The LLVM Compiler Infrastructure</a> 
444<br>Last modified: $Date: 2011-11-03 14:43:23 +0800 (Thu, 03 Nov 2011) $ </div>
445</body>
446</html>
447<!-- vim: sw=2 ts=2 ai
448-->