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