13fe401a5SEd Maste.\" Copyright (c) 2010 Joseph Koshy. All rights reserved. 23fe401a5SEd Maste.\" 33fe401a5SEd Maste.\" Redistribution and use in source and binary forms, with or without 43fe401a5SEd Maste.\" modification, are permitted provided that the following conditions 53fe401a5SEd Maste.\" are met: 63fe401a5SEd Maste.\" 1. Redistributions of source code must retain the above copyright 73fe401a5SEd Maste.\" notice, this list of conditions and the following disclaimer. 83fe401a5SEd Maste.\" 2. Redistributions in binary form must reproduce the above copyright 93fe401a5SEd Maste.\" notice, this list of conditions and the following disclaimer in the 103fe401a5SEd Maste.\" documentation and/or other materials provided with the distribution. 113fe401a5SEd Maste.\" 123fe401a5SEd Maste.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 133fe401a5SEd Maste.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 143fe401a5SEd Maste.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 153fe401a5SEd Maste.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 163fe401a5SEd Maste.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 173fe401a5SEd Maste.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 183fe401a5SEd Maste.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 193fe401a5SEd Maste.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 203fe401a5SEd Maste.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 213fe401a5SEd Maste.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 223fe401a5SEd Maste.\" SUCH DAMAGE. 233fe401a5SEd Maste.\" 24*ae500c1fSEd Maste.\" $Id: ar.5 3642 2018-10-14 14:24:28Z jkoshy $ 253fe401a5SEd Maste.\" 26*ae500c1fSEd Maste.Dd September 30, 2018 273fe401a5SEd Maste.Dt AR 5 28*ae500c1fSEd Maste.Os 293fe401a5SEd Maste.Sh NAME 303fe401a5SEd Maste.Nm ar 313fe401a5SEd Maste.Nd archive file format for 323fe401a5SEd Maste.Xr ar 1 333fe401a5SEd Masteand 343fe401a5SEd Maste.Xr ranlib 1 353fe401a5SEd Maste.Sh SYNOPSIS 363fe401a5SEd Maste.In ar.h 373fe401a5SEd Maste.Sh DESCRIPTION 383fe401a5SEd Maste.Xr ar 1 393fe401a5SEd Mastearchives are created and managed by the 403fe401a5SEd Maste.Xr ar 1 413fe401a5SEd Masteand 423fe401a5SEd Maste.Xr ranlib 1 433fe401a5SEd Masteutilities. 443fe401a5SEd MasteThese archives are typically used during program development to 453fe401a5SEd Mastehold libraries of program objects. 463fe401a5SEd MasteAn 473fe401a5SEd Maste.Xr ar 1 483fe401a5SEd Mastearchive is contained in a single operating system file. 493fe401a5SEd Maste.Pp 503fe401a5SEd MasteThis manual page documents two variants of the 513fe401a5SEd Maste.Xr ar 1 523fe401a5SEd Mastearchive format: the BSD archive format, and the SVR4/GNU archive 533fe401a5SEd Masteformat. 543fe401a5SEd Maste.Pp 553fe401a5SEd MasteIn both variants the archive file starts with an identifying byte 563fe401a5SEd Mastesequence of the seven ASCII characters 573fe401a5SEd Maste.Sq Li "!<arch>" 583fe401a5SEd Mastefollowed by a ASCII linefeed character 593fe401a5SEd Maste.Po 603fe401a5SEd Mastesee the constant 613fe401a5SEd Maste.Dq ARMAG 623fe401a5SEd Mastein the header file 633fe401a5SEd Maste.In ar.h 643fe401a5SEd Maste.Pc . 653fe401a5SEd Maste.Pp 663fe401a5SEd MasteArchive members follow the initial identifying byte sequence. 673fe401a5SEd MasteEach archive member is prefixed by a fixed size header describing the 683fe401a5SEd Mastefile attributes associated with the member. 693fe401a5SEd Maste.Ss "Archive Headers" 703fe401a5SEd MasteAn archive header describes the file attributes for the archive member that 713fe401a5SEd Mastefollows it. 723fe401a5SEd MasteThe 733fe401a5SEd Maste.Xr ar 5 743fe401a5SEd Masteformat only supports a limited number of attributes: the file name, 753fe401a5SEd Mastethe file creation time stamp, the uid and gid of the creator, the file 763fe401a5SEd Mastemode and the file size. 773fe401a5SEd Maste.Pp 783fe401a5SEd MasteArchive headers are placed at an even byte offset in the archive file. 793fe401a5SEd MasteIf the data for an archive member ends at an odd byte offset, then a 803fe401a5SEd Mastepadding byte with value 0x0A is used to position the next archive 813fe401a5SEd Masteheader on an even byte offset. 823fe401a5SEd Maste.Pp 833fe401a5SEd MasteAn archive header comprises the following fixed sized fields: 843fe401a5SEd Maste.Bl -tag -width "Li ar_name" 853fe401a5SEd Maste.It Ar ar_name 863fe401a5SEd Maste(16 bytes) The file name of the archive member. 87*ae500c1fSEd MasteThis field names a leaf file; absolute paths and relative paths containing 88*ae500c1fSEd Mastedirectory names are not supported. 893fe401a5SEd MasteThe format of this field varies between the BSD and SVR4/GNU formats and 903fe401a5SEd Masteis described in more detail in the section 913fe401a5SEd Maste.Sx "Representing File Names" 923fe401a5SEd Mastebelow. 933fe401a5SEd Maste.It Ar ar_date 943fe401a5SEd Maste(12 bytes) The file modification time for the member in seconds since the 953fe401a5SEd Masteepoch, encoded as a decimal number. 963fe401a5SEd Maste.It Ar ar_uid 973fe401a5SEd Maste(6 bytes) The uid associated with the archive member, encoded as a 983fe401a5SEd Mastedecimal number. 993fe401a5SEd Maste.It Ar ar_gid 1003fe401a5SEd Maste(6 bytes) The gid associated with the archive member, encoded as a 1013fe401a5SEd Mastedecimal number. 1023fe401a5SEd Maste.It Ar ar_mode 1033fe401a5SEd Maste(8 bytes) The file mode for the archive member, encoded as an octal 1043fe401a5SEd Mastenumber. 1053fe401a5SEd Maste.It Ar ar_size 1063fe401a5SEd Maste(10 bytes) In the SVR4/GNU archive format this field holds the size in 1073fe401a5SEd Mastebytes of the archive member, encoded as a decimal number. 1083fe401a5SEd MasteIn the BSD archive format, for short file names, this field 1093fe401a5SEd Masteholds the size in bytes of the archive member, encoded as a decimal 1103fe401a5SEd Mastenumber. 1113fe401a5SEd MasteFor long file names 1123fe401a5SEd Maste.Po 1133fe401a5SEd Mastesee 1143fe401a5SEd Maste.Sx "Representing File Names" 1153fe401a5SEd Mastebelow 1163fe401a5SEd Maste.Pc , 1173fe401a5SEd Mastethe field contains the combined size of the 1183fe401a5SEd Mastearchive member and its file name, encoded as a decimal number. 1193fe401a5SEd Maste.It Ar ar_fmag 1203fe401a5SEd Maste(2 bytes) This field holds 2 bytes with values 0x96 and 0x0A 1213fe401a5SEd Masterespectively, marking the end of the header. 1223fe401a5SEd Maste.El 1233fe401a5SEd Maste.Pp 1243fe401a5SEd MasteUnused bytes in the fields of an archive header are set to the value 1253fe401a5SEd Maste0x20. 1263fe401a5SEd Maste.Ss "Representing File Names" 1273fe401a5SEd MasteThe BSD and SVR4/GNU variants use different schemes for encoding file 1283fe401a5SEd Mastenames for members. 1293fe401a5SEd Maste.Bl -tag -width "SVR4/GNU" 1303fe401a5SEd Maste.It "BSD" 1313fe401a5SEd MasteFile names that are up to 16 bytes long and which do not contain 1323fe401a5SEd Masteembedded spaces are stored directly in the 1333fe401a5SEd Maste.Ar ar_name 1343fe401a5SEd Mastefield of the archive header. 1353fe401a5SEd MasteFile names that are either longer than 16 bytes or which contain 1363fe401a5SEd Masteembedded spaces are stored immediately after the archive header 1373fe401a5SEd Masteand the 1383fe401a5SEd Maste.Ar ar_name 1393fe401a5SEd Mastefield of the archive header is set to the string 1403fe401a5SEd Maste.Dq "#1/" 1413fe401a5SEd Mastefollowed by a decimal representation of the number of bytes needed for 1423fe401a5SEd Mastethe file name. 1433fe401a5SEd MasteIn addition, the 1443fe401a5SEd Maste.Ar ar_size 1453fe401a5SEd Mastefield of the archive header is set to the decimal representation of 1463fe401a5SEd Mastethe combined sizes of the archive member and the file name. 1473fe401a5SEd MasteThe file contents of the member follows the file name without further 1483fe401a5SEd Mastepadding. 1493fe401a5SEd Maste.Pp 1503fe401a5SEd MasteAs an example, if the file name for a member was 1513fe401a5SEd Maste.Dq "A B" 1523fe401a5SEd Masteand its contents was the string 1533fe401a5SEd Maste.Dq "C D" , 1543fe401a5SEd Mastethen the 1553fe401a5SEd Maste.Ar ar_name 1563fe401a5SEd Mastefield of the header would contain 1573fe401a5SEd Maste.Dq Li "#1/3" , 1583fe401a5SEd Mastethe 1593fe401a5SEd Maste.Ar ar_size 1603fe401a5SEd Mastefield of the header would contain 1613fe401a5SEd Maste.Dq Li 6 , 1623fe401a5SEd Masteand the bytes immediately following the header would be 0x41, 0x20, 1633fe401a5SEd Maste0x42, 0x43, 0x20 and 0x44 1643fe401a5SEd Maste.Po 1653fe401a5SEd MasteASCII 1663fe401a5SEd Maste.Dq "A BC D" 1673fe401a5SEd Maste.Pc . 1683fe401a5SEd Maste.It "SVR4/GNU" 1693fe401a5SEd MasteFile names that are up to 15 characters long are stored directly in the 1703fe401a5SEd Maste.Ar ar_name 1713fe401a5SEd Mastefield of the header, terminated by a 1723fe401a5SEd Maste.Dq Li / 1733fe401a5SEd Mastecharacter. 1743fe401a5SEd Maste.Pp 1753fe401a5SEd MasteIf the file name is larger than would fit in space for the 1763fe401a5SEd Maste.Ar ar_name 1773fe401a5SEd Mastefield, then the actual file name is kept in the archive 1783fe401a5SEd Mastestring table 1793fe401a5SEd Maste.Po 1803fe401a5SEd Mastesee 1813fe401a5SEd Maste.Sx "Archive String Tables" 1823fe401a5SEd Mastebelow 1833fe401a5SEd Maste.Pc , 1843fe401a5SEd Masteand the decimal offset of the file name in the string table is stored 1853fe401a5SEd Mastein the 1863fe401a5SEd Maste.Ar ar_name 1873fe401a5SEd Mastefield, prefixed by a 1883fe401a5SEd Maste.Dq Li / 1893fe401a5SEd Mastecharacter. 1903fe401a5SEd Maste.Pp 1913fe401a5SEd MasteAs an example, if the real file name has been stored at offset 768 in 1923fe401a5SEd Mastethe archive string table, the 1933fe401a5SEd Maste.Ar ar_name 1943fe401a5SEd Mastefield of the header will contain the string 1953fe401a5SEd Maste.Dq /768 . 1963fe401a5SEd Maste.El 1973fe401a5SEd Maste.Ss "Special Archive Members" 1983fe401a5SEd MasteThe following archive members are special. 1993fe401a5SEd Maste.Bl -tag -width indent 2003fe401a5SEd Maste.It Dq Li / 2013fe401a5SEd MasteIn the SVR4/GNU variant of the archive format, the archive member with 2023fe401a5SEd Mastename 2033fe401a5SEd Maste.Dq Li / 2043fe401a5SEd Mastedenotes an archive symbol table. 2053fe401a5SEd MasteIf present, this member will be the very first member in the 2063fe401a5SEd Mastearchive. 2073fe401a5SEd Maste.It Dq Li // 2083fe401a5SEd MasteIn the SVR4/GNU variant of the archive format, the archive member with 2093fe401a5SEd Mastename 2103fe401a5SEd Maste.Dq Li // 2113fe401a5SEd Mastedenotes the archive string table. 2123fe401a5SEd MasteThis special member is used to hold filenames that do not fit in the 2133fe401a5SEd Mastefile name field of the header 2143fe401a5SEd Maste.Po 2153fe401a5SEd Mastesee 2163fe401a5SEd Maste.Sx "Representing File Names" 2173fe401a5SEd Masteabove 2183fe401a5SEd Maste.Pc . 2193fe401a5SEd MasteIf present, this member immediately follows the archive symbol table 2203fe401a5SEd Masteif an archive symbol table is present, or is the first member otherwise. 2213fe401a5SEd Maste.It Dq Li "__.SYMDEF" 2223fe401a5SEd MasteThis special member contains the archive symbol table in the BSD 2233fe401a5SEd Mastevariant of the archive format. 2243fe401a5SEd MasteIf present, this member will be the very first member in the 2253fe401a5SEd Mastearchive. 2263fe401a5SEd Maste.El 2273fe401a5SEd Maste.Ss "Archive String Tables" 2283fe401a5SEd MasteAn archive string table is used in the SVR4/GNU archive format to hold 2293fe401a5SEd Mastefile names that are too large to fit into the constraints of the 2303fe401a5SEd Maste.Ar ar_name 2313fe401a5SEd Mastefield of the archive header. 2323fe401a5SEd MasteAn archive string table contains a sequence of file names. 2333fe401a5SEd MasteEach file name in the archive string table is terminated by the 2343fe401a5SEd Mastebyte sequence 0x2F, 0x0A 2353fe401a5SEd Maste.Po 2363fe401a5SEd Mastethe ASCII string 2373fe401a5SEd Maste.Dq "/\en" 2383fe401a5SEd Maste.Pc . 2393fe401a5SEd MasteNo padding is used to separate adjacent file names. 2403fe401a5SEd Maste.Ss "Archive Symbol Tables" 2413fe401a5SEd MasteArchive symbol tables are used to speed up link editing by providing a 2423fe401a5SEd Mastemapping between the program symbols defined in the archive 2433fe401a5SEd Masteand the corresponding archive members. 2443fe401a5SEd MasteArchive symbol tables are managed by the 2453fe401a5SEd Maste.Xr ranlib 1 2463fe401a5SEd Masteutility. 2473fe401a5SEd Maste.Pp 2483fe401a5SEd MasteThe format of archive symbol tables is as follows: 2493fe401a5SEd Maste.Bl -tag -width "SVR4/GNU" 2503fe401a5SEd Maste.It BSD 2513fe401a5SEd MasteIn the BSD archive format, the archive symbol table comprises 2523fe401a5SEd Masteof two parts: a part containing an array of 2533fe401a5SEd Maste.Vt "struct ranlib" 2543fe401a5SEd Mastedescriptors, followed by a part containing a symbol string table. 2553fe401a5SEd MasteThe sizes and layout of the structures that make up a BSD format 2563fe401a5SEd Mastearchive symbol table are machine dependent. 2573fe401a5SEd Maste.Pp 2583fe401a5SEd MasteThe part containing 2593fe401a5SEd Maste.Vt "struct ranlib" 2603fe401a5SEd Mastedescriptors begins with a field containing the size in bytes of the 2613fe401a5SEd Mastearray of 2623fe401a5SEd Maste.Vt "struct ranlib" 2633fe401a5SEd Mastedescriptors encoded as a C 2643fe401a5SEd Maste.Vt long 2653fe401a5SEd Mastevalue. 2663fe401a5SEd Maste.Pp 2673fe401a5SEd MasteThe array of 2683fe401a5SEd Maste.Vt "struct ranlib" 2693fe401a5SEd Mastedescriptors follows the size field. 2703fe401a5SEd MasteEach 2713fe401a5SEd Maste.Vt "struct ranlib" 2723fe401a5SEd Mastedescriptor describes one symbol. 2733fe401a5SEd Maste.Pp 2743fe401a5SEd MasteA 2753fe401a5SEd Maste.Vt "struct ranlib" 2763fe401a5SEd Mastedescriptor comprises two fields: 2773fe401a5SEd Maste.Bl -tag -width "Ar ran_strx" -compact 2783fe401a5SEd Maste.It Ar ran_strx 2793fe401a5SEd Maste.Pq C Vt long 2803fe401a5SEd MasteThis field contains the zero-based offset of the symbol name in the 2813fe401a5SEd Mastesymbol string table. 2823fe401a5SEd Maste.It Ar ran_off 2833fe401a5SEd Maste.Pq C Vt long 2843fe401a5SEd MasteThis field is the file offset to the archive header for the archive 2853fe401a5SEd Mastemember defining the symbol. 2863fe401a5SEd Maste.El 2873fe401a5SEd Maste.Pp 2883fe401a5SEd MasteThe part containing the symbol string table begins with a field 2893fe401a5SEd Mastecontaining the size in bytes of the string table, encoded as a C 2903fe401a5SEd Maste.Vt long 2913fe401a5SEd Mastevalue. 2923fe401a5SEd MasteThis string table follows the size field, and contains 2933fe401a5SEd MasteNUL-terminated strings for the symbols in the symbol table. 2943fe401a5SEd Maste.It SVR4/GNU 2953fe401a5SEd MasteIn the SVR4/GNU archive format, the archive symbol table starts with a 2963fe401a5SEd Maste4-byte binary value containing the number of entries contained in the 2973fe401a5SEd Mastearchive symbol table. 2983fe401a5SEd MasteThis count of entries is stored most significant byte first. 2993fe401a5SEd Maste.Pp 3003fe401a5SEd MasteNext, there are 3013fe401a5SEd Maste.Ar count 3023fe401a5SEd Maste4-byte numbers, each stored most significant byte first. 3033fe401a5SEd MasteEach number is a binary offset to the archive header for the member in 3043fe401a5SEd Mastethe archive file for the corresponding symbol table entry. 3053fe401a5SEd Maste.Pp 3063fe401a5SEd MasteAfter the binary offset values, there are 3073fe401a5SEd Maste.Ar count 3083fe401a5SEd MasteNUL-terminated strings in sequence, holding the symbol names for 3093fe401a5SEd Mastethe corresponding symbol table entries. 3103fe401a5SEd Maste.El 3113fe401a5SEd Maste.Sh STANDARDS COMPLIANCE 3123fe401a5SEd MasteThe 3133fe401a5SEd Maste.Xr ar 1 3143fe401a5SEd Mastearchive format is not currently specified by a standard. 3153fe401a5SEd Maste.Pp 3163fe401a5SEd MasteThis manual page documents the 3173fe401a5SEd Maste.Xr ar 1 3183fe401a5SEd Mastearchive formats used by the 3193fe401a5SEd Maste.Bx 4.4 3203fe401a5SEd Masteand 3213fe401a5SEd Maste.Ux SVR4 3223fe401a5SEd Masteoperating system releases. 3233fe401a5SEd Maste.Sh SEE ALSO 3243fe401a5SEd Maste.Xr ar 1 , 3253fe401a5SEd Maste.Xr ld 1 , 3263fe401a5SEd Maste.Xr ranlib 1 , 3273fe401a5SEd Maste.Xr elf 3 , 3283fe401a5SEd Maste.Xr elf_getarsym 3 , 3293fe401a5SEd Maste.Xr elf_rand 3 330