xref: /freebsd/share/man/man5/ar.5 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
13860fcc7SKai Wang.\" Copyright (c) 2010 Joseph Koshy.  All rights reserved.
212d64ed1SJoseph Koshy.\"
312d64ed1SJoseph Koshy.\" Redistribution and use in source and binary forms, with or without
412d64ed1SJoseph Koshy.\" modification, are permitted provided that the following conditions
512d64ed1SJoseph Koshy.\" are met:
612d64ed1SJoseph Koshy.\" 1. Redistributions of source code must retain the above copyright
712d64ed1SJoseph Koshy.\"    notice, this list of conditions and the following disclaimer.
812d64ed1SJoseph Koshy.\" 2. Redistributions in binary form must reproduce the above copyright
912d64ed1SJoseph Koshy.\"    notice, this list of conditions and the following disclaimer in the
1012d64ed1SJoseph Koshy.\"    documentation and/or other materials provided with the distribution.
1112d64ed1SJoseph Koshy.\"
123860fcc7SKai Wang.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
133860fcc7SKai Wang.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
143860fcc7SKai Wang.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
153860fcc7SKai Wang.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
163860fcc7SKai Wang.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
173860fcc7SKai Wang.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
183860fcc7SKai Wang.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
193860fcc7SKai Wang.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
203860fcc7SKai Wang.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
213860fcc7SKai Wang.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
223860fcc7SKai Wang.\" SUCH DAMAGE.
2312d64ed1SJoseph Koshy.\"
243860fcc7SKai Wang.Dd November 28, 2010
253860fcc7SKai Wang.Dt AR 5
26bea977e7SJoel Dahl.Os
2712d64ed1SJoseph Koshy.Sh NAME
2812d64ed1SJoseph Koshy.Nm ar
293860fcc7SKai Wang.Nd archive file format for
3012d64ed1SJoseph Koshy.Xr ar 1
3112d64ed1SJoseph Koshyand
3212d64ed1SJoseph Koshy.Xr ranlib 1
333860fcc7SKai Wang.Sh SYNOPSIS
3412d64ed1SJoseph Koshy.In ar.h
353860fcc7SKai Wang.Sh DESCRIPTION
3612d64ed1SJoseph Koshy.Xr ar 1
373860fcc7SKai Wangarchives are created and managed by the
383860fcc7SKai Wang.Xr ar 1
393860fcc7SKai Wangand
403860fcc7SKai Wang.Xr ranlib 1
413860fcc7SKai Wangutilities.
423860fcc7SKai WangThese archives are typically used during program development to
433860fcc7SKai Wanghold libraries of program objects.
443860fcc7SKai WangAn
453860fcc7SKai Wang.Xr ar 1
463860fcc7SKai Wangarchive is contained in a single operating system file.
4712d64ed1SJoseph Koshy.Pp
483860fcc7SKai WangThis manual page documents two variants of the
493860fcc7SKai Wang.Xr ar 1
503860fcc7SKai Wangarchive format: the BSD archive format, and the SVR4/GNU archive
513860fcc7SKai Wangformat.
5212d64ed1SJoseph Koshy.Pp
533860fcc7SKai WangIn both variants the archive file starts with an identifying byte
543860fcc7SKai Wangsequence of the seven ASCII characters
553860fcc7SKai Wang.Sq Li "!<arch>"
563860fcc7SKai Wangfollowed by a ASCII linefeed character
573860fcc7SKai Wang.Po
583860fcc7SKai Wangsee the constant
593860fcc7SKai Wang.Dq ARMAG
603860fcc7SKai Wangin the header file
613860fcc7SKai Wang.In ar.h
623860fcc7SKai Wang.Pc .
6312d64ed1SJoseph Koshy.Pp
643860fcc7SKai WangArchive members follow the initial identifying byte sequence.
653860fcc7SKai WangEach archive member is prefixed by a fixed size header describing the
663860fcc7SKai Wangfile attributes associated with the member.
673860fcc7SKai Wang.Ss "Archive Headers"
683860fcc7SKai WangAn archive header describes the file attributes for the archive member that
693860fcc7SKai Wangfollows it.
7012d64ed1SJoseph KoshyThe
71*16e36754SEdward Tomasz Napierala.Nm
723860fcc7SKai Wangformat only supports a limited number of attributes: the file name,
733860fcc7SKai Wangthe file creation time stamp, the uid and gid of the creator, the file
743860fcc7SKai Wangmode and the file size.
7512d64ed1SJoseph Koshy.Pp
763860fcc7SKai WangArchive headers are placed at an even byte offset in the archive file.
773860fcc7SKai WangIf the data for an archive member ends at an odd byte offset, then a
783860fcc7SKai Wangpadding byte with value 0x0A is used to position the next archive
793860fcc7SKai Wangheader on an even byte offset.
803860fcc7SKai Wang.Pp
813860fcc7SKai WangAn archive header comprises the following fixed sized fields:
823860fcc7SKai Wang.Bl -tag -width "Li ar_name"
833860fcc7SKai Wang.It Ar ar_name
843860fcc7SKai Wang(16 bytes) The file name of the archive member.
853860fcc7SKai WangThe format of this field varies between the BSD and SVR4/GNU formats and
863860fcc7SKai Wangis described in more detail in the section
873860fcc7SKai Wang.Sx "Representing File Names"
883860fcc7SKai Wangbelow.
893860fcc7SKai Wang.It Ar ar_date
903860fcc7SKai Wang(12 bytes) The file modification time for the member in seconds since the
913860fcc7SKai Wangepoch, encoded as a decimal number.
923860fcc7SKai Wang.It Ar ar_uid
933860fcc7SKai Wang(6 bytes) The uid associated with the archive member, encoded as a
943860fcc7SKai Wangdecimal number.
953860fcc7SKai Wang.It Ar ar_gid
963860fcc7SKai Wang(6 bytes) The gid associated with the archive member, encoded as a
973860fcc7SKai Wangdecimal number.
983860fcc7SKai Wang.It Ar ar_mode
993860fcc7SKai Wang(8 bytes) The file mode for the archive member, encoded as an octal
1003860fcc7SKai Wangnumber.
1013860fcc7SKai Wang.It Ar ar_size
1023860fcc7SKai Wang(10 bytes) In the SVR4/GNU archive format this field holds the size in
1033860fcc7SKai Wangbytes of the archive member, encoded as a decimal number.
1043860fcc7SKai WangIn the BSD archive format, for short file names, this field
1053860fcc7SKai Wangholds the size in bytes of the archive member, encoded as a decimal
1063860fcc7SKai Wangnumber.
1073860fcc7SKai WangFor long file names
1083860fcc7SKai Wang.Po
1093860fcc7SKai Wangsee
1103860fcc7SKai Wang.Sx "Representing File Names"
1113860fcc7SKai Wangbelow
1123860fcc7SKai Wang.Pc ,
1133860fcc7SKai Wangthe field contains the combined size of the
1143860fcc7SKai Wangarchive member and its file name, encoded as a decimal number.
1153860fcc7SKai Wang.It Ar ar_fmag
1163860fcc7SKai Wang(2 bytes) This field holds 2 bytes with values 0x96 and 0x0A
1173860fcc7SKai Wangrespectively, marking the end of the header.
1183860fcc7SKai Wang.El
1193860fcc7SKai Wang.Pp
1203860fcc7SKai WangUnused bytes in the fields of an archive header are set to the value
1213860fcc7SKai Wang0x20.
1223860fcc7SKai Wang.Ss "Representing File Names"
1233860fcc7SKai WangThe BSD and SVR4/GNU variants use different schemes for encoding file
1243860fcc7SKai Wangnames for members.
1253860fcc7SKai Wang.Bl -tag -width "SVR4/GNU"
1263860fcc7SKai Wang.It "BSD"
1273860fcc7SKai WangFile names that are up to 16 bytes long and which do not contain
1283860fcc7SKai Wangembedded spaces are stored directly in the
1293860fcc7SKai Wang.Ar ar_name
1303860fcc7SKai Wangfield of the archive header.
1313860fcc7SKai WangFile names that are either longer than 16 bytes or which contain
1323860fcc7SKai Wangembedded spaces are stored immediately after the archive header
1333860fcc7SKai Wangand the
1343860fcc7SKai Wang.Ar ar_name
1353860fcc7SKai Wangfield of the archive header is set to the string
1363860fcc7SKai Wang.Dq "#1/"
1373860fcc7SKai Wangfollowed by a decimal representation of the number of bytes needed for
1383860fcc7SKai Wangthe file name.
1393860fcc7SKai WangIn addition, the
1403860fcc7SKai Wang.Ar ar_size
1413860fcc7SKai Wangfield of the archive header is set to the decimal representation of
1423860fcc7SKai Wangthe combined sizes of the archive member and the file name.
1433860fcc7SKai WangThe file contents of the member follows the file name without further
1443860fcc7SKai Wangpadding.
1453860fcc7SKai Wang.Pp
1463860fcc7SKai WangAs an example, if the file name for a member was
1473860fcc7SKai Wang.Dq "A B"
1483860fcc7SKai Wangand its contents was the string
1493860fcc7SKai Wang.Dq "C D" ,
1503860fcc7SKai Wangthen the
1513860fcc7SKai Wang.Ar ar_name
1523860fcc7SKai Wangfield of the header would contain
1533860fcc7SKai Wang.Dq Li "#1/3" ,
1543860fcc7SKai Wangthe
1553860fcc7SKai Wang.Ar ar_size
1563860fcc7SKai Wangfield of the header would contain
1573860fcc7SKai Wang.Dq Li 6 ,
1583860fcc7SKai Wangand the bytes immediately following the header would be 0x41, 0x20,
1593860fcc7SKai Wang0x42, 0x43, 0x20 and 0x44
1603860fcc7SKai Wang.Po
1613860fcc7SKai WangASCII
1623860fcc7SKai Wang.Dq "A BC D"
1633860fcc7SKai Wang.Pc .
1643860fcc7SKai Wang.It "SVR4/GNU"
1653860fcc7SKai WangFile names that are up to 15 characters long are stored directly in the
1663860fcc7SKai Wang.Ar ar_name
1673860fcc7SKai Wangfield of the header, terminated by a
1683860fcc7SKai Wang.Dq Li /
1693860fcc7SKai Wangcharacter.
1703860fcc7SKai Wang.Pp
1713860fcc7SKai WangIf the file name is larger than would fit in space for the
1723860fcc7SKai Wang.Ar ar_name
1733860fcc7SKai Wangfield, then the actual file name is kept in the archive
1743860fcc7SKai Wangstring table
1753860fcc7SKai Wang.Po
1763860fcc7SKai Wangsee
1773860fcc7SKai Wang.Sx "Archive String Tables"
1783860fcc7SKai Wangbelow
1793860fcc7SKai Wang.Pc ,
1803860fcc7SKai Wangand the decimal offset of the file name in the string table is stored
1813860fcc7SKai Wangin the
1823860fcc7SKai Wang.Ar ar_name
1833860fcc7SKai Wangfield, prefixed by a
1843860fcc7SKai Wang.Dq Li /
1853860fcc7SKai Wangcharacter.
1863860fcc7SKai Wang.Pp
1873860fcc7SKai WangAs an example, if the real file name has been stored at offset 768 in
1883860fcc7SKai Wangthe archive string table, the
1893860fcc7SKai Wang.Ar ar_name
1903860fcc7SKai Wangfield of the header will contain the string
1913860fcc7SKai Wang.Dq /768 .
1923860fcc7SKai Wang.El
1933860fcc7SKai Wang.Ss "Special Archive Members"
1943860fcc7SKai WangThe following archive members are special.
1953860fcc7SKai Wang.Bl -tag -width indent
1963860fcc7SKai Wang.It Dq Li /
1973860fcc7SKai WangIn the SVR4/GNU variant of the archive format, the archive member with
1983860fcc7SKai Wangname
1993860fcc7SKai Wang.Dq Li /
2003860fcc7SKai Wangdenotes an archive symbol table.
2013860fcc7SKai WangIf present, this member will be the very first member in the
2023860fcc7SKai Wangarchive.
2033860fcc7SKai Wang.It Dq Li //
2043860fcc7SKai WangIn the SVR4/GNU variant of the archive format, the archive member with
2053860fcc7SKai Wangname
2063860fcc7SKai Wang.Dq Li //
2073860fcc7SKai Wangdenotes the archive string table.
2083860fcc7SKai WangThis special member is used to hold filenames that do not fit in the
2093860fcc7SKai Wangfile name field of the header
2103860fcc7SKai Wang.Po
2113860fcc7SKai Wangsee
2123860fcc7SKai Wang.Sx "Representing File Names"
2133860fcc7SKai Wangabove
2143860fcc7SKai Wang.Pc .
2153860fcc7SKai WangIf present, this member immediately follows the archive symbol table
2163860fcc7SKai Wangif an archive symbol table is present, or is the first member otherwise.
2173860fcc7SKai Wang.It Dq Li "__.SYMDEF"
2183860fcc7SKai WangThis special member contains the archive symbol table in the BSD
2193860fcc7SKai Wangvariant of the archive format.
2203860fcc7SKai WangIf present, this member will be the very first member in the
2213860fcc7SKai Wangarchive.
2223860fcc7SKai Wang.El
2233860fcc7SKai Wang.Ss "Archive String Tables"
2243860fcc7SKai WangAn archive string table is used in the SVR4/GNU archive format to hold
2253860fcc7SKai Wangfile names that are too large to fit into the constraints of the
2263860fcc7SKai Wang.Ar ar_name
2273860fcc7SKai Wangfield of the archive header.
2283860fcc7SKai WangAn archive string table contains a sequence of file names.
2293860fcc7SKai WangEach file name in the archive string table is terminated by the
2303860fcc7SKai Wangbyte sequence 0x2F, 0x0A
2313860fcc7SKai Wang.Po
2323860fcc7SKai Wangthe ASCII string
2333860fcc7SKai Wang.Dq "/\en"
2343860fcc7SKai Wang.Pc .
2353860fcc7SKai WangNo padding is used to separate adjacent file names.
2363860fcc7SKai Wang.Ss "Archive Symbol Tables"
2373860fcc7SKai WangArchive symbol tables are used to speed up link editing by providing a
2383860fcc7SKai Wangmapping between the program symbols defined in the archive
2393860fcc7SKai Wangand the corresponding archive members.
2403860fcc7SKai WangArchive symbol tables are managed by the
2413860fcc7SKai Wang.Xr ranlib 1
2423860fcc7SKai Wangutility.
2433860fcc7SKai Wang.Pp
2443860fcc7SKai WangThe format of archive symbol tables is as follows:
2453860fcc7SKai Wang.Bl -tag -width "SVR4/GNU"
24612d64ed1SJoseph Koshy.It BSD
2473860fcc7SKai WangIn the BSD archive format, the archive symbol table comprises
2483860fcc7SKai Wangof two parts: a part containing an array of
2493860fcc7SKai Wang.Vt "struct ranlib"
2503860fcc7SKai Wangdescriptors, followed by a part containing a symbol string table.
2513860fcc7SKai WangThe sizes and layout of the structures that make up a BSD format
2523860fcc7SKai Wangarchive symbol table are machine dependent.
2533860fcc7SKai Wang.Pp
2543860fcc7SKai WangThe part containing
2553860fcc7SKai Wang.Vt "struct ranlib"
2563860fcc7SKai Wangdescriptors begins with a field containing the size in bytes of the
2573860fcc7SKai Wangarray of
2583860fcc7SKai Wang.Vt "struct ranlib"
2593860fcc7SKai Wangdescriptors encoded as a C
2603860fcc7SKai Wang.Vt long
2613860fcc7SKai Wangvalue.
2623860fcc7SKai Wang.Pp
2633860fcc7SKai WangThe array of
2643860fcc7SKai Wang.Vt "struct ranlib"
2653860fcc7SKai Wangdescriptors follows the size field.
2663860fcc7SKai WangEach
2673860fcc7SKai Wang.Vt "struct ranlib"
2683860fcc7SKai Wangdescriptor describes one symbol.
2693860fcc7SKai Wang.Pp
2703860fcc7SKai WangA
2713860fcc7SKai Wang.Vt "struct ranlib"
2723860fcc7SKai Wangdescriptor comprises two fields:
2733860fcc7SKai Wang.Bl -tag -width "Ar ran_strx" -compact
2743860fcc7SKai Wang.It Ar ran_strx
2753860fcc7SKai Wang.Pq C Vt long
2763860fcc7SKai WangThis field contains the zero-based offset of the symbol name in the
2773860fcc7SKai Wangsymbol string table.
2783860fcc7SKai Wang.It Ar ran_off
2793860fcc7SKai Wang.Pq C Vt long
2803860fcc7SKai WangThis field is the file offset to the archive header for the archive
2813860fcc7SKai Wangmember defining the symbol.
28212d64ed1SJoseph Koshy.El
2833860fcc7SKai Wang.Pp
2843860fcc7SKai WangThe part containing the symbol string table begins with a field
2853860fcc7SKai Wangcontaining the size in bytes of the string table, encoded as a C
2863860fcc7SKai Wang.Vt long
2873860fcc7SKai Wangvalue.
2883860fcc7SKai WangThis string table follows the size field, and contains
2893860fcc7SKai WangNUL-terminated strings for the symbols in the symbol table.
29012d64ed1SJoseph Koshy.It SVR4/GNU
2913860fcc7SKai WangIn the SVR4/GNU archive format, the archive symbol table starts with a
2923860fcc7SKai Wang4-byte binary value containing the number of entries contained in the
2933860fcc7SKai Wangarchive symbol table.
2943860fcc7SKai WangThis count of entries is stored most significant byte first.
2953860fcc7SKai Wang.Pp
2963860fcc7SKai WangNext, there are
2973860fcc7SKai Wang.Ar count
2983860fcc7SKai Wang4-byte numbers, each stored most significant byte first.
2993860fcc7SKai WangEach number is a binary offset to the archive header for the member in
3003860fcc7SKai Wangthe archive file for the corresponding symbol table entry.
3013860fcc7SKai Wang.Pp
3023860fcc7SKai WangAfter the binary offset values, there are
3033860fcc7SKai Wang.Ar count
3043860fcc7SKai WangNUL-terminated strings in sequence, holding the symbol names for
3053860fcc7SKai Wangthe corresponding symbol table entries.
30612d64ed1SJoseph Koshy.El
3073860fcc7SKai Wang.Sh STANDARDS COMPLIANCE
3083860fcc7SKai WangThe
30912d64ed1SJoseph Koshy.Xr ar 1
3103860fcc7SKai Wangarchive format is not currently specified by a standard.
3113860fcc7SKai Wang.Pp
3123860fcc7SKai WangThis manual page documents the
3133860fcc7SKai Wang.Xr ar 1
3143860fcc7SKai Wangarchive formats used by the
3153860fcc7SKai Wang.Bx 4.4
3163860fcc7SKai Wangand
3173860fcc7SKai Wang.Ux SVR4
3183860fcc7SKai Wangoperating system releases.
31912d64ed1SJoseph Koshy.Sh SEE ALSO
32012d64ed1SJoseph Koshy.Xr ar 1 ,
3213860fcc7SKai Wang.Xr ld 1 ,
32212d64ed1SJoseph Koshy.Xr ranlib 1 ,
32312d64ed1SJoseph Koshy.Xr elf 3 ,
3243860fcc7SKai Wang.Xr elf_getarsym 3 ,
3253860fcc7SKai Wang.Xr elf_rand 3
326