afeefa9b1a9d7d55d0cc677b8ac29f75d512bad1
[oota-llvm.git] / docs / CommandGuide / llvm-ld.pod
1 =pod
2
3 =head1 NAME
4
5 llvm-ld - LLVM linker
6
7 =head1 SYNOPSIS
8
9 B<llvm-ld> <options> <files>
10
11 =head1 DESCRIPTION
12
13 The B<llvm-ld> tool takes a set of LLVM bytecode files and links them
14 together into a single LLVM bytecode file.  The output bytecode file can be
15 another bytecode file or an executable bytecode program.  Using additional
16 options, B<llvm-ld> is able to produce native code executables.
17
18 The B<llvm-ld> tool is the main linker for LLVM. It is used to link together
19 the output of LLVM front-end compilers and run "link time" optimizations (mostly
20 the inter-procedural kind).
21
22 The B<llvm-ld> tools attemps to mimic the interface provided by the default
23 system linker so that it can act as a I<drop-in> replacement.
24
25 =head2 Search Order
26
27 When looking for objects specified on the command line, B<llvm-ld> will search 
28 for the object first in the current directory and then in the directory 
29 specified by the B<LLVM_LIB_SEARCH_PATH> environment variable.  If it cannot 
30 find the object, it fails.
31
32 When looking for a library specified with the B<-l> option, B<llvm-ld> first
33 attempts to load a file with that name from the current directory.  If that
34 fails, it looks for libI<library>.bc, libI<library>.a, or libI<library>.I<shared
35 library extension>, in that order, in each directory added to the library search
36 path with the B<-L> option.  These directories are searched in the order they
37 are specified.  If the library cannot be located, then B<llvm-ld> looks in the
38 directory specified by the B<LLVM_LIB_SEARCH_PATH> environment variable.  If it
39 does not find a library there, it fails.
40
41 The I<shared library extension> may be I<.so>, I<.dyld>, I<.dll>, or something
42 different, depending upon the system.
43
44 The B<-L> option is global.  It does not matter where it is specified in the
45 list of command line arguments; the directory is simply added to the search path
46 and is applied to all libraries, preceding or succeeding, in the command line.
47
48 =head2 Link order
49
50 All object and bytecode files are linked first in the order they were 
51 specified on the command line.  All library files are linked next.  
52 Some libraries may not be linked into the object program; see below.
53
54 =head2 Library Linkage
55
56 Object files and static bytecode objects are always linked into the output
57 file.  Library archives (.a files) load only the objects within the archive
58 that define symbols needed by the output file.  Hence, libraries should be
59 listed after the object files and libraries which need them; otherwise, the
60 library may not be linked in, and the dependent library will not have its
61 undefined symbols defined.
62
63 =head2 Native code generation
64
65 The B<llvm-ld> program has limited support for native code generation, when
66 using the B<-native> or B<-native-cbe> options. Native code generation is
67 perfomed by converting the linked bytecode into native assembly (.s) or C code
68 and running the system compiler (typically gcc) on the result.
69
70 =head1 OPTIONS
71
72 =head2 General Options
73
74 =item B<-help>
75
76 Print a summary of command line options.
77
78 =item B<-v>
79
80 Specifies verbose mode. In this mode the linker will print additional
81 information about the actions it takes, programs it executes, etc. 
82
83 =item B<-stats>
84
85 Print statistics.
86
87 =item B<-time-passes>
88
89 Record the amount of time needed for each pass and print it to standard
90 error.
91
92 =head2 Input/Output Options
93
94 =over
95
96 =item B<-o> F<filename>
97
98 This overrides the default output file and specifies the name of the file that
99 should be generated by the linker. By default, B<llvm-ld> generates a file named
100 F<a.out> for compatibility with B<ld>. The output will be written to
101 F<filename>.
102
103 =item B<-l>F<name>
104
105 This option specifies the F<name> of a library to search when resolving symbols
106 for the program. Only the base name should be specified as F<name>, without a
107 F<lib> prefix or any suffix. 
108
109 =item B<-L>F<Path>
110
111 This option tells B<llvm-ld> to look in F<Path> to find any library subsequently
112 specified with the B<-l> option. The paths will be searched in the order in
113 which they are specified on the command line. If the library is still not found,
114 a small set of system specific directories will also be searched. Note that
115 libraries specified with the B<-l> option that occur I<before> any B<-L> options
116 will not search the paths given by the B<-L> options following it.
117
118 =item B<-link-as-library>
119
120 Link the bytecode files together as a library, not an executable. In this mode,
121 undefined symbols will be permitted.
122
123 =item B<-r>
124
125 An alias for -link-as-library.
126
127 =item B<-march=>C<target>
128
129 Specifies the kind of machine for which code or assembly should be generated.
130
131 =item B<-native>
132
133 Generate a native machine code executable.
134
135 When generating native executables, B<llvm-ld> first checks for a bytecode
136 version of the library and links it in, if necessary.  If the library is
137 missing, B<llvm-ld> skips it.  Then, B<llvm-ld> links in the same
138 libraries as native code.
139
140 In this way, B<llvm-ld> should be able to link in optimized bytecode
141 subsets of common libraries and then link in any part of the library that
142 hasn't been converted to bytecode.
143
144 =item B<-native-cbe>
145
146 Generate a native machine code executable with the LLVM C backend.
147       
148 This option is identical to the B<-native> option, but uses the
149 C backend to generate code for the program instead of an LLVM native
150 code generator.
151
152 =item B<-disable-compression>
153
154 Do not compress bytecode files.
155
156 =back
157
158 =head2 Optimization Options
159
160 =over 
161
162 =item B<-O0>
163
164 An alias for the -O1 option.
165
166 =item B<-O1>
167
168 Optimize for linking speed, not execution speed. The optimizer will attempt to
169 reduce the size of the linked program to reduce I/O but will not otherwise
170 perform any link-time optimizations.
171
172 =item B<-O2>
173
174 Perform only the minimal or required set of scalar optimizations.
175
176 =item B<-03>
177
178 An alias for the -O2 option.
179
180 =item B<-04>
181
182 Perform the standard link time inter-procedural optimizations. This will 
183 attempt to optimize the program taking the entire program into consideration.
184
185 =item B<-O5>
186
187 Perform aggressive link time optimizations. This is the same as -O4 but works
188 more aggressively to optimize the program.
189
190 =item B<-disable-inlining>
191
192 Do not run the inlining pass. Functions will not be inlined into other
193 functions.
194
195 =item B<-disable-opt>
196
197 Completely disable optimization. The various B<-On> options will be ignored and
198 no link time optimization passes will be run.
199
200 =item B<-disable-internalize>
201
202 Do not mark all symbols as internal.
203
204 =item B<-verify-each>
205
206 Run the verification pass after each of the passes to verify intermediate
207 results.
208
209 =item B<-strip-all>
210
211 Strip all debug and symbol information from the executable to make it smaller.
212
213 =item B<-strip-debug>
214
215 Strip all debug information from the executable to make it smaller.
216
217 =item B<-s>
218
219 An alias for B<-strip-all>.
220
221 =item B<-S>
222
223 An alias for B<-strip-debug>.
224
225 =item B<-export-dynamic>
226
227 An alias for B<-disable-internalize>
228
229 =item B<-load> F<module>
230
231 Load an optimization module, F<module>, which is expected to be a dynamic
232 library that provides the function name C<RunOptimizations>. This function will
233 be passed the PassManager, and the optimization level (values 0-5 based on the
234 B<-On> option). This function may add passes to the PassManager that should be
235 run. This feature allows the optimization passes of B<llvm-ld> to be extended.
236
237 =item B<-post-link-opt>F<Path>
238
239 Run post-link optimization program. After linking is completed a bytecode file
240 will be generated. It will be passed to the program specified by F<Path> as the
241 first argument. The second argument to the program will be the name of a
242 temporary file into which the program should place its optimized output. For
243 example, the "no-op optimization" would be a simple shell script:
244
245 =over
246
247 #!/bin/bash
248 cp $1 $2
249
250 =back
251
252 =back
253
254
255 =head1 EXIT STATUS
256
257 If B<llvm-ld> succeeds, it will exit with 0 return code.  If an error occurs,
258 it will exit with a non-zero return code.
259
260 =head1 ENVIRONMENT
261
262 The C<LLVM_LIB_SEARCH_PATH> environment variable is used to find bytecode
263 libraries. Any paths specified in this variable will be searched after the C<-L>
264 options.
265
266 =head1 SEE ALSO
267
268 L<llvm-link|llvm-link>
269
270 =head1 AUTHORS
271
272 Maintained by the LLVM Team (L<http://llvm.org>).
273
274 =cut