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