llvm-ar.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. llvm-ar - LLVM archiver
  2. =======================
  3. SYNOPSIS
  4. --------
  5. **llvm-ar** [-]{dmpqrtx}[Rabfikou] [relpos] [count] <archive> [files...]
  6. DESCRIPTION
  7. -----------
  8. The **llvm-ar** command is similar to the common Unix utility, ``ar``. It
  9. archives several files together into a single file. The intent for this is
  10. to produce archive libraries by LLVM bitcode that can be linked into an
  11. LLVM program. However, the archive can contain any kind of file. By default,
  12. **llvm-ar** generates a symbol table that makes linking faster because
  13. only the symbol table needs to be consulted, not each individual file member
  14. of the archive.
  15. The **llvm-ar** command can be used to *read* SVR4, GNU and BSD style archive
  16. files. However, right now it can only write in the GNU format. If an
  17. SVR4 or BSD style archive is used with the ``r`` (replace) or ``q`` (quick
  18. update) operations, the archive will be reconstructed in GNU format.
  19. Here's where **llvm-ar** departs from previous ``ar`` implementations:
  20. *Symbol Table*
  21. Since **llvm-ar** supports bitcode files. The symbol table it creates
  22. is in GNU format and includes both native and bitcode files.
  23. *Long Paths*
  24. Currently **llvm-ar** can read GNU and BSD long file names, but only writes
  25. archives with the GNU format.
  26. OPTIONS
  27. -------
  28. The options to **llvm-ar** are compatible with other ``ar`` implementations.
  29. However, there are a few modifiers (*R*) that are not found in other ``ar``
  30. implementations. The options to **llvm-ar** specify a single basic operation to
  31. perform on the archive, a variety of modifiers for that operation, the name of
  32. the archive file, and an optional list of file names. These options are used to
  33. determine how **llvm-ar** should process the archive file.
  34. The Operations and Modifiers are explained in the sections below. The minimal
  35. set of options is at least one operator and the name of the archive. Typically
  36. archive files end with a ``.a`` suffix, but this is not required. Following
  37. the *archive-name* comes a list of *files* that indicate the specific members
  38. of the archive to operate on. If the *files* option is not specified, it
  39. generally means either "none" or "all" members, depending on the operation.
  40. Operations
  41. ~~~~~~~~~~
  42. d
  43. Delete files from the archive. No modifiers are applicable to this operation.
  44. The *files* options specify which members should be removed from the
  45. archive. It is not an error if a specified file does not appear in the archive.
  46. If no *files* are specified, the archive is not modified.
  47. m[abi]
  48. Move files from one location in the archive to another. The *a*, *b*, and
  49. *i* modifiers apply to this operation. The *files* will all be moved
  50. to the location given by the modifiers. If no modifiers are used, the files
  51. will be moved to the end of the archive. If no *files* are specified, the
  52. archive is not modified.
  53. p
  54. Print files to the standard output. This operation simply prints the
  55. *files* indicated to the standard output. If no *files* are
  56. specified, the entire archive is printed. Printing bitcode files is
  57. ill-advised as they might confuse your terminal settings. The *p*
  58. operation never modifies the archive.
  59. q
  60. Quickly append files to the end of the archive. This operation quickly adds the
  61. *files* to the archive without checking for duplicates that should be
  62. removed first. If no *files* are specified, the archive is not modified.
  63. Because of the way that **llvm-ar** constructs the archive file, its dubious
  64. whether the *q* operation is any faster than the *r* operation.
  65. r[abu]
  66. Replace or insert file members. The *a*, *b*, and *u*
  67. modifiers apply to this operation. This operation will replace existing
  68. *files* or insert them at the end of the archive if they do not exist. If no
  69. *files* are specified, the archive is not modified.
  70. t[v]
  71. Print the table of contents. Without any modifiers, this operation just prints
  72. the names of the members to the standard output. With the *v* modifier,
  73. **llvm-ar** also prints out the file type (B=bitcode, S=symbol
  74. table, blank=regular file), the permission mode, the owner and group, the
  75. size, and the date. If any *files* are specified, the listing is only for
  76. those files. If no *files* are specified, the table of contents for the
  77. whole archive is printed.
  78. x[oP]
  79. Extract archive members back to files. The *o* modifier applies to this
  80. operation. This operation retrieves the indicated *files* from the archive
  81. and writes them back to the operating system's file system. If no
  82. *files* are specified, the entire archive is extract.
  83. Modifiers (operation specific)
  84. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  85. The modifiers below are specific to certain operations. See the Operations
  86. section (above) to determine which modifiers are applicable to which operations.
  87. [a]
  88. When inserting or moving member files, this option specifies the destination of
  89. the new files as being after the *relpos* member. If *relpos* is not found,
  90. the files are placed at the end of the archive.
  91. [b]
  92. When inserting or moving member files, this option specifies the destination of
  93. the new files as being before the *relpos* member. If *relpos* is not
  94. found, the files are placed at the end of the archive. This modifier is
  95. identical to the *i* modifier.
  96. [i]
  97. A synonym for the *b* option.
  98. [o]
  99. When extracting files, this option will cause **llvm-ar** to preserve the
  100. original modification times of the files it writes.
  101. [u]
  102. When replacing existing files in the archive, only replace those files that have
  103. a time stamp than the time stamp of the member in the archive.
  104. Modifiers (generic)
  105. ~~~~~~~~~~~~~~~~~~~
  106. The modifiers below may be applied to any operation.
  107. [c]
  108. For all operations, **llvm-ar** will always create the archive if it doesn't
  109. exist. Normally, **llvm-ar** will print a warning message indicating that the
  110. archive is being created. Using this modifier turns off that warning.
  111. [s]
  112. This modifier requests that an archive index (or symbol table) be added to the
  113. archive. This is the default mode of operation. The symbol table will contain
  114. all the externally visible functions and global variables defined by all the
  115. bitcode files in the archive.
  116. [S]
  117. This modifier is the opposite of the *s* modifier. It instructs **llvm-ar** to
  118. not build the symbol table. If both *s* and *S* are used, the last modifier to
  119. occur in the options will prevail.
  120. [v]
  121. This modifier instructs **llvm-ar** to be verbose about what it is doing. Each
  122. editing operation taken against the archive will produce a line of output saying
  123. what is being done.
  124. STANDARDS
  125. ---------
  126. The **llvm-ar** utility is intended to provide a superset of the IEEE Std 1003.2
  127. (POSIX.2) functionality for ``ar``. **llvm-ar** can read both SVR4 and BSD4.4 (or
  128. Mac OS X) archives. If the ``f`` modifier is given to the ``x`` or ``r`` operations
  129. then **llvm-ar** will write SVR4 compatible archives. Without this modifier,
  130. **llvm-ar** will write BSD4.4 compatible archives that have long names
  131. immediately after the header and indicated using the "#1/ddd" notation for the
  132. name in the header.
  133. FILE FORMAT
  134. -----------
  135. The file format for LLVM Archive files is similar to that of BSD 4.4 or Mac OSX
  136. archive files. In fact, except for the symbol table, the ``ar`` commands on those
  137. operating systems should be able to read LLVM archive files. The details of the
  138. file format follow.
  139. Each archive begins with the archive magic number which is the eight printable
  140. characters "!<arch>\n" where \n represents the newline character (0x0A).
  141. Following the magic number, the file is composed of even length members that
  142. begin with an archive header and end with a \n padding character if necessary
  143. (to make the length even). Each file member is composed of a header (defined
  144. below), an optional newline-terminated "long file name" and the contents of
  145. the file.
  146. The fields of the header are described in the items below. All fields of the
  147. header contain only ASCII characters, are left justified and are right padded
  148. with space characters.
  149. name - char[16]
  150. This field of the header provides the name of the archive member. If the name is
  151. longer than 15 characters or contains a slash (/) character, then this field
  152. contains ``#1/nnn`` where ``nnn`` provides the length of the name and the ``#1/``
  153. is literal. In this case, the actual name of the file is provided in the ``nnn``
  154. bytes immediately following the header. If the name is 15 characters or less, it
  155. is contained directly in this field and terminated with a slash (/) character.
  156. date - char[12]
  157. This field provides the date of modification of the file in the form of a
  158. decimal encoded number that provides the number of seconds since the epoch
  159. (since 00:00:00 Jan 1, 1970) per Posix specifications.
  160. uid - char[6]
  161. This field provides the user id of the file encoded as a decimal ASCII string.
  162. This field might not make much sense on non-Unix systems. On Unix, it is the
  163. same value as the st_uid field of the stat structure returned by the stat(2)
  164. operating system call.
  165. gid - char[6]
  166. This field provides the group id of the file encoded as a decimal ASCII string.
  167. This field might not make much sense on non-Unix systems. On Unix, it is the
  168. same value as the st_gid field of the stat structure returned by the stat(2)
  169. operating system call.
  170. mode - char[8]
  171. This field provides the access mode of the file encoded as an octal ASCII
  172. string. This field might not make much sense on non-Unix systems. On Unix, it
  173. is the same value as the st_mode field of the stat structure returned by the
  174. stat(2) operating system call.
  175. size - char[10]
  176. This field provides the size of the file, in bytes, encoded as a decimal ASCII
  177. string.
  178. fmag - char[2]
  179. This field is the archive file member magic number. Its content is always the
  180. two characters back tick (0x60) and newline (0x0A). This provides some measure
  181. utility in identifying archive files that have been corrupted.
  182. offset - vbr encoded 32-bit integer
  183. The offset item provides the offset into the archive file where the bitcode
  184. member is stored that is associated with the symbol. The offset value is 0
  185. based at the start of the first "normal" file member. To derive the actual
  186. file offset of the member, you must add the number of bytes occupied by the file
  187. signature (8 bytes) and the symbol tables. The value of this item is encoded
  188. using variable bit rate encoding to reduce the size of the symbol table.
  189. Variable bit rate encoding uses the high bit (0x80) of each byte to indicate
  190. if there are more bytes to follow. The remaining 7 bits in each byte carry bits
  191. from the value. The final byte does not have the high bit set.
  192. length - vbr encoded 32-bit integer
  193. The length item provides the length of the symbol that follows. Like this
  194. *offset* item, the length is variable bit rate encoded.
  195. symbol - character array
  196. The symbol item provides the text of the symbol that is associated with the
  197. *offset*. The symbol is not terminated by any character. Its length is provided
  198. by the *length* field. Note that is allowed (but unwise) to use non-printing
  199. characters (even 0x00) in the symbol. This allows for multiple encodings of
  200. symbol names.
  201. EXIT STATUS
  202. -----------
  203. If **llvm-ar** succeeds, it will exit with 0. A usage error, results
  204. in an exit code of 1. A hard (file system typically) error results in an
  205. exit code of 2. Miscellaneous or unknown errors result in an
  206. exit code of 3.
  207. SEE ALSO
  208. --------
  209. ar(1)