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