llvm-ld.pod 6.9 KB

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