blob: 8067f7e4a97d8ed00c0ac962c32bf6dd9f7cea8d [file] [log] [blame]
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +00001llvm-ar - LLVM archiver
2=======================
3
James Hendersona0566842019-06-27 13:24:46 +00004.. program:: llvm-ar
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +00005
6SYNOPSIS
7--------
8
Rafael Espindola740a6bc2012-08-10 01:57:52 +00009**llvm-ar** [-]{dmpqrtx}[Rabfikou] [relpos] [count] <archive> [files...]
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000010
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000011DESCRIPTION
12-----------
13
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000014The **llvm-ar** command is similar to the common Unix utility, ``ar``. It
15archives several files together into a single file. The intent for this is
16to produce archive libraries by LLVM bitcode that can be linked into an
17LLVM program. However, the archive can contain any kind of file. By default,
18**llvm-ar** generates a symbol table that makes linking faster because
19only the symbol table needs to be consulted, not each individual file member
20of the archive.
21
Rafael Espindola86e4b412013-07-24 13:13:24 +000022The **llvm-ar** command can be used to *read* SVR4, GNU and BSD style archive
23files. However, right now it can only write in the GNU format. If an
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000024SVR4 or BSD style archive is used with the ``r`` (replace) or ``q`` (quick
Rafael Espindola86e4b412013-07-24 13:13:24 +000025update) operations, the archive will be reconstructed in GNU format.
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000026
27Here's where **llvm-ar** departs from previous ``ar`` implementations:
28
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000029*Symbol Table*
30
Rafael Espindola86e4b412013-07-24 13:13:24 +000031 Since **llvm-ar** supports bitcode files. The symbol table it creates
32 is in GNU format and includes both native and bitcode files.
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000033
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000034*Long Paths*
35
Rafael Espindola86e4b412013-07-24 13:13:24 +000036 Currently **llvm-ar** can read GNU and BSD long file names, but only writes
37 archives with the GNU format.
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000038
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000039OPTIONS
40-------
41
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000042The options to **llvm-ar** are compatible with other ``ar`` implementations.
Rafael Espindola740a6bc2012-08-10 01:57:52 +000043However, there are a few modifiers (*R*) that are not found in other ``ar``
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000044implementations. The options to **llvm-ar** specify a single basic operation to
45perform on the archive, a variety of modifiers for that operation, the name of
46the archive file, and an optional list of file names. These options are used to
47determine how **llvm-ar** should process the archive file.
48
49The Operations and Modifiers are explained in the sections below. The minimal
50set of options is at least one operator and the name of the archive. Typically
51archive files end with a ``.a`` suffix, but this is not required. Following
52the *archive-name* comes a list of *files* that indicate the specific members
53of the archive to operate on. If the *files* option is not specified, it
54generally means either "none" or "all" members, depending on the operation.
55
56Operations
57~~~~~~~~~~
58
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000059d
60
61 Delete files from the archive. No modifiers are applicable to this operation.
62 The *files* options specify which members should be removed from the
63 archive. It is not an error if a specified file does not appear in the archive.
64 If no *files* are specified, the archive is not modified.
65
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000066m[abi]
67
68 Move files from one location in the archive to another. The *a*, *b*, and
69 *i* modifiers apply to this operation. The *files* will all be moved
70 to the location given by the modifiers. If no modifiers are used, the files
71 will be moved to the end of the archive. If no *files* are specified, the
72 archive is not modified.
73
Rafael Espindolad20830d2013-07-30 04:06:06 +000074p
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000075
Rafael Espindolad20830d2013-07-30 04:06:06 +000076 Print files to the standard output. This operation simply prints the
77 *files* indicated to the standard output. If no *files* are
78 specified, the entire archive is printed. Printing bitcode files is
79 ill-advised as they might confuse your terminal settings. The *p*
80 operation never modifies the archive.
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000081
Rafael Espindolad20830d2013-07-30 04:06:06 +000082q
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000083
Rafael Espindolad20830d2013-07-30 04:06:06 +000084 Quickly append files to the end of the archive. This operation quickly adds the
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000085 *files* to the archive without checking for duplicates that should be
86 removed first. If no *files* are specified, the archive is not modified.
87 Because of the way that **llvm-ar** constructs the archive file, its dubious
88 whether the *q* operation is any faster than the *r* operation.
89
Rafael Espindolad20830d2013-07-30 04:06:06 +000090r[abu]
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000091
Rafael Espindolad20830d2013-07-30 04:06:06 +000092 Replace or insert file members. The *a*, *b*, and *u*
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000093 modifiers apply to this operation. This operation will replace existing
94 *files* or insert them at the end of the archive if they do not exist. If no
95 *files* are specified, the archive is not modified.
96
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000097t[v]
98
99 Print the table of contents. Without any modifiers, this operation just prints
100 the names of the members to the standard output. With the *v* modifier,
Rafael Espindola740a6bc2012-08-10 01:57:52 +0000101 **llvm-ar** also prints out the file type (B=bitcode, S=symbol
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000102 table, blank=regular file), the permission mode, the owner and group, the
103 size, and the date. If any *files* are specified, the listing is only for
104 those files. If no *files* are specified, the table of contents for the
105 whole archive is printed.
106
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000107x[oP]
108
109 Extract archive members back to files. The *o* modifier applies to this
110 operation. This operation retrieves the indicated *files* from the archive
111 and writes them back to the operating system's file system. If no
112 *files* are specified, the entire archive is extract.
113
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000114Modifiers (operation specific)
115~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
116
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000117The modifiers below are specific to certain operations. See the Operations
118section (above) to determine which modifiers are applicable to which operations.
119
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000120[a]
121
122 When inserting or moving member files, this option specifies the destination of
123 the new files as being after the *relpos* member. If *relpos* is not found,
124 the files are placed at the end of the archive.
125
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000126[b]
127
128 When inserting or moving member files, this option specifies the destination of
129 the new files as being before the *relpos* member. If *relpos* is not
130 found, the files are placed at the end of the archive. This modifier is
Sylvestre Ledru35521e22012-07-23 08:51:15 +0000131 identical to the *i* modifier.
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000132
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000133[i]
134
135 A synonym for the *b* option.
136
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000137[o]
138
139 When extracting files, this option will cause **llvm-ar** to preserve the
140 original modification times of the files it writes.
141
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000142[u]
143
144 When replacing existing files in the archive, only replace those files that have
145 a time stamp than the time stamp of the member in the archive.
146
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000147Modifiers (generic)
148~~~~~~~~~~~~~~~~~~~
149
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000150The modifiers below may be applied to any operation.
151
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000152[c]
153
154 For all operations, **llvm-ar** will always create the archive if it doesn't
155 exist. Normally, **llvm-ar** will print a warning message indicating that the
156 archive is being created. Using this modifier turns off that warning.
157
158
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000159[s]
160
161 This modifier requests that an archive index (or symbol table) be added to the
162 archive. This is the default mode of operation. The symbol table will contain
163 all the externally visible functions and global variables defined by all the
Rafael Espindola668c6422013-06-14 23:25:53 +0000164 bitcode files in the archive.
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000165
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000166[S]
167
168 This modifier is the opposite of the *s* modifier. It instructs **llvm-ar** to
169 not build the symbol table. If both *s* and *S* are used, the last modifier to
170 occur in the options will prevail.
171
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000172[v]
173
174 This modifier instructs **llvm-ar** to be verbose about what it is doing. Each
175 editing operation taken against the archive will produce a line of output saying
176 what is being done.
177
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000178STANDARDS
179---------
180
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000181The **llvm-ar** utility is intended to provide a superset of the IEEE Std 1003.2
182(POSIX.2) functionality for ``ar``. **llvm-ar** can read both SVR4 and BSD4.4 (or
J. Ryan Stinnettd45eaf92019-05-30 16:46:22 +0000183macOS) archives. If the ``f`` modifier is given to the ``x`` or ``r`` operations
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000184then **llvm-ar** will write SVR4 compatible archives. Without this modifier,
185**llvm-ar** will write BSD4.4 compatible archives that have long names
186immediately after the header and indicated using the "#1/ddd" notation for the
187name in the header.
188
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000189FILE FORMAT
190-----------
191
J. Ryan Stinnettd45eaf92019-05-30 16:46:22 +0000192The file format for LLVM Archive files is similar to that of BSD 4.4 or macOS
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000193archive files. In fact, except for the symbol table, the ``ar`` commands on those
194operating systems should be able to read LLVM archive files. The details of the
195file format follow.
196
197Each archive begins with the archive magic number which is the eight printable
198characters "!<arch>\n" where \n represents the newline character (0x0A).
199Following the magic number, the file is composed of even length members that
200begin with an archive header and end with a \n padding character if necessary
201(to make the length even). Each file member is composed of a header (defined
202below), an optional newline-terminated "long file name" and the contents of
203the file.
204
205The fields of the header are described in the items below. All fields of the
206header contain only ASCII characters, are left justified and are right padded
207with space characters.
208
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000209name - char[16]
210
211 This field of the header provides the name of the archive member. If the name is
212 longer than 15 characters or contains a slash (/) character, then this field
213 contains ``#1/nnn`` where ``nnn`` provides the length of the name and the ``#1/``
214 is literal. In this case, the actual name of the file is provided in the ``nnn``
215 bytes immediately following the header. If the name is 15 characters or less, it
216 is contained directly in this field and terminated with a slash (/) character.
217
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000218date - char[12]
219
220 This field provides the date of modification of the file in the form of a
221 decimal encoded number that provides the number of seconds since the epoch
222 (since 00:00:00 Jan 1, 1970) per Posix specifications.
223
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000224uid - char[6]
225
226 This field provides the user id of the file encoded as a decimal ASCII string.
227 This field might not make much sense on non-Unix systems. On Unix, it is the
228 same value as the st_uid field of the stat structure returned by the stat(2)
229 operating system call.
230
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000231gid - char[6]
232
233 This field provides the group id of the file encoded as a decimal ASCII string.
234 This field might not make much sense on non-Unix systems. On Unix, it is the
235 same value as the st_gid field of the stat structure returned by the stat(2)
236 operating system call.
237
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000238mode - char[8]
239
240 This field provides the access mode of the file encoded as an octal ASCII
241 string. This field might not make much sense on non-Unix systems. On Unix, it
242 is the same value as the st_mode field of the stat structure returned by the
243 stat(2) operating system call.
244
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000245size - char[10]
246
247 This field provides the size of the file, in bytes, encoded as a decimal ASCII
Rafael Espindola740a6bc2012-08-10 01:57:52 +0000248 string.
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000249
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000250fmag - char[2]
251
252 This field is the archive file member magic number. Its content is always the
253 two characters back tick (0x60) and newline (0x0A). This provides some measure
254 utility in identifying archive files that have been corrupted.
255
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000256offset - vbr encoded 32-bit integer
257
258 The offset item provides the offset into the archive file where the bitcode
259 member is stored that is associated with the symbol. The offset value is 0
260 based at the start of the first "normal" file member. To derive the actual
261 file offset of the member, you must add the number of bytes occupied by the file
262 signature (8 bytes) and the symbol tables. The value of this item is encoded
263 using variable bit rate encoding to reduce the size of the symbol table.
264 Variable bit rate encoding uses the high bit (0x80) of each byte to indicate
265 if there are more bytes to follow. The remaining 7 bits in each byte carry bits
266 from the value. The final byte does not have the high bit set.
267
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000268length - vbr encoded 32-bit integer
269
270 The length item provides the length of the symbol that follows. Like this
271 *offset* item, the length is variable bit rate encoded.
272
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000273symbol - character array
274
275 The symbol item provides the text of the symbol that is associated with the
276 *offset*. The symbol is not terminated by any character. Its length is provided
277 by the *length* field. Note that is allowed (but unwise) to use non-printing
278 characters (even 0x00) in the symbol. This allows for multiple encodings of
279 symbol names.
280
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000281EXIT STATUS
282-----------
283
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000284If **llvm-ar** succeeds, it will exit with 0. A usage error, results
285in an exit code of 1. A hard (file system typically) error results in an
286exit code of 2. Miscellaneous or unknown errors result in an
287exit code of 3.
288
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000289SEE ALSO
290--------
291
Rafael Espindola668c6422013-06-14 23:25:53 +0000292ar(1)