xref: /freebsd/share/man/man5/ar.5 (revision 16e3675494a9e93e2866ac80d5e4fbe46de45792)
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.\"
2412d64ed1SJoseph Koshy.\" $FreeBSD$
2512d64ed1SJoseph Koshy.\"
263860fcc7SKai Wang.Dd November 28, 2010
273860fcc7SKai Wang.Dt AR 5
28bea977e7SJoel Dahl.Os
2912d64ed1SJoseph Koshy.Sh NAME
3012d64ed1SJoseph Koshy.Nm ar
313860fcc7SKai Wang.Nd archive file format for
3212d64ed1SJoseph Koshy.Xr ar 1
3312d64ed1SJoseph Koshyand
3412d64ed1SJoseph Koshy.Xr ranlib 1
353860fcc7SKai Wang.Sh SYNOPSIS
3612d64ed1SJoseph Koshy.In ar.h
373860fcc7SKai Wang.Sh DESCRIPTION
3812d64ed1SJoseph Koshy.Xr ar 1
393860fcc7SKai Wangarchives are created and managed by the
403860fcc7SKai Wang.Xr ar 1
413860fcc7SKai Wangand
423860fcc7SKai Wang.Xr ranlib 1
433860fcc7SKai Wangutilities.
443860fcc7SKai WangThese archives are typically used during program development to
453860fcc7SKai Wanghold libraries of program objects.
463860fcc7SKai WangAn
473860fcc7SKai Wang.Xr ar 1
483860fcc7SKai Wangarchive is contained in a single operating system file.
4912d64ed1SJoseph Koshy.Pp
503860fcc7SKai WangThis manual page documents two variants of the
513860fcc7SKai Wang.Xr ar 1
523860fcc7SKai Wangarchive format: the BSD archive format, and the SVR4/GNU archive
533860fcc7SKai Wangformat.
5412d64ed1SJoseph Koshy.Pp
553860fcc7SKai WangIn both variants the archive file starts with an identifying byte
563860fcc7SKai Wangsequence of the seven ASCII characters
573860fcc7SKai Wang.Sq Li "!<arch>"
583860fcc7SKai Wangfollowed by a ASCII linefeed character
593860fcc7SKai Wang.Po
603860fcc7SKai Wangsee the constant
613860fcc7SKai Wang.Dq ARMAG
623860fcc7SKai Wangin the header file
633860fcc7SKai Wang.In ar.h
643860fcc7SKai Wang.Pc .
6512d64ed1SJoseph Koshy.Pp
663860fcc7SKai WangArchive members follow the initial identifying byte sequence.
673860fcc7SKai WangEach archive member is prefixed by a fixed size header describing the
683860fcc7SKai Wangfile attributes associated with the member.
693860fcc7SKai Wang.Ss "Archive Headers"
703860fcc7SKai WangAn archive header describes the file attributes for the archive member that
713860fcc7SKai Wangfollows it.
7212d64ed1SJoseph KoshyThe
73*16e36754SEdward Tomasz Napierala.Nm
743860fcc7SKai Wangformat only supports a limited number of attributes: the file name,
753860fcc7SKai Wangthe file creation time stamp, the uid and gid of the creator, the file
763860fcc7SKai Wangmode and the file size.
7712d64ed1SJoseph Koshy.Pp
783860fcc7SKai WangArchive headers are placed at an even byte offset in the archive file.
793860fcc7SKai WangIf the data for an archive member ends at an odd byte offset, then a
803860fcc7SKai Wangpadding byte with value 0x0A is used to position the next archive
813860fcc7SKai Wangheader on an even byte offset.
823860fcc7SKai Wang.Pp
833860fcc7SKai WangAn archive header comprises the following fixed sized fields:
843860fcc7SKai Wang.Bl -tag -width "Li ar_name"
853860fcc7SKai Wang.It Ar ar_name
863860fcc7SKai Wang(16 bytes) The file name of the archive member.
873860fcc7SKai WangThe format of this field varies between the BSD and SVR4/GNU formats and
883860fcc7SKai Wangis described in more detail in the section
893860fcc7SKai Wang.Sx "Representing File Names"
903860fcc7SKai Wangbelow.
913860fcc7SKai Wang.It Ar ar_date
923860fcc7SKai Wang(12 bytes) The file modification time for the member in seconds since the
933860fcc7SKai Wangepoch, encoded as a decimal number.
943860fcc7SKai Wang.It Ar ar_uid
953860fcc7SKai Wang(6 bytes) The uid associated with the archive member, encoded as a
963860fcc7SKai Wangdecimal number.
973860fcc7SKai Wang.It Ar ar_gid
983860fcc7SKai Wang(6 bytes) The gid associated with the archive member, encoded as a
993860fcc7SKai Wangdecimal number.
1003860fcc7SKai Wang.It Ar ar_mode
1013860fcc7SKai Wang(8 bytes) The file mode for the archive member, encoded as an octal
1023860fcc7SKai Wangnumber.
1033860fcc7SKai Wang.It Ar ar_size
1043860fcc7SKai Wang(10 bytes) In the SVR4/GNU archive format this field holds the size in
1053860fcc7SKai Wangbytes of the archive member, encoded as a decimal number.
1063860fcc7SKai WangIn the BSD archive format, for short file names, this field
1073860fcc7SKai Wangholds the size in bytes of the archive member, encoded as a decimal
1083860fcc7SKai Wangnumber.
1093860fcc7SKai WangFor long file names
1103860fcc7SKai Wang.Po
1113860fcc7SKai Wangsee
1123860fcc7SKai Wang.Sx "Representing File Names"
1133860fcc7SKai Wangbelow
1143860fcc7SKai Wang.Pc ,
1153860fcc7SKai Wangthe field contains the combined size of the
1163860fcc7SKai Wangarchive member and its file name, encoded as a decimal number.
1173860fcc7SKai Wang.It Ar ar_fmag
1183860fcc7SKai Wang(2 bytes) This field holds 2 bytes with values 0x96 and 0x0A
1193860fcc7SKai Wangrespectively, marking the end of the header.
1203860fcc7SKai Wang.El
1213860fcc7SKai Wang.Pp
1223860fcc7SKai WangUnused bytes in the fields of an archive header are set to the value
1233860fcc7SKai Wang0x20.
1243860fcc7SKai Wang.Ss "Representing File Names"
1253860fcc7SKai WangThe BSD and SVR4/GNU variants use different schemes for encoding file
1263860fcc7SKai Wangnames for members.
1273860fcc7SKai Wang.Bl -tag -width "SVR4/GNU"
1283860fcc7SKai Wang.It "BSD"
1293860fcc7SKai WangFile names that are up to 16 bytes long and which do not contain
1303860fcc7SKai Wangembedded spaces are stored directly in the
1313860fcc7SKai Wang.Ar ar_name
1323860fcc7SKai Wangfield of the archive header.
1333860fcc7SKai WangFile names that are either longer than 16 bytes or which contain
1343860fcc7SKai Wangembedded spaces are stored immediately after the archive header
1353860fcc7SKai Wangand the
1363860fcc7SKai Wang.Ar ar_name
1373860fcc7SKai Wangfield of the archive header is set to the string
1383860fcc7SKai Wang.Dq "#1/"
1393860fcc7SKai Wangfollowed by a decimal representation of the number of bytes needed for
1403860fcc7SKai Wangthe file name.
1413860fcc7SKai WangIn addition, the
1423860fcc7SKai Wang.Ar ar_size
1433860fcc7SKai Wangfield of the archive header is set to the decimal representation of
1443860fcc7SKai Wangthe combined sizes of the archive member and the file name.
1453860fcc7SKai WangThe file contents of the member follows the file name without further
1463860fcc7SKai Wangpadding.
1473860fcc7SKai Wang.Pp
1483860fcc7SKai WangAs an example, if the file name for a member was
1493860fcc7SKai Wang.Dq "A B"
1503860fcc7SKai Wangand its contents was the string
1513860fcc7SKai Wang.Dq "C D" ,
1523860fcc7SKai Wangthen the
1533860fcc7SKai Wang.Ar ar_name
1543860fcc7SKai Wangfield of the header would contain
1553860fcc7SKai Wang.Dq Li "#1/3" ,
1563860fcc7SKai Wangthe
1573860fcc7SKai Wang.Ar ar_size
1583860fcc7SKai Wangfield of the header would contain
1593860fcc7SKai Wang.Dq Li 6 ,
1603860fcc7SKai Wangand the bytes immediately following the header would be 0x41, 0x20,
1613860fcc7SKai Wang0x42, 0x43, 0x20 and 0x44
1623860fcc7SKai Wang.Po
1633860fcc7SKai WangASCII
1643860fcc7SKai Wang.Dq "A BC D"
1653860fcc7SKai Wang.Pc .
1663860fcc7SKai Wang.It "SVR4/GNU"
1673860fcc7SKai WangFile names that are up to 15 characters long are stored directly in the
1683860fcc7SKai Wang.Ar ar_name
1693860fcc7SKai Wangfield of the header, terminated by a
1703860fcc7SKai Wang.Dq Li /
1713860fcc7SKai Wangcharacter.
1723860fcc7SKai Wang.Pp
1733860fcc7SKai WangIf the file name is larger than would fit in space for the
1743860fcc7SKai Wang.Ar ar_name
1753860fcc7SKai Wangfield, then the actual file name is kept in the archive
1763860fcc7SKai Wangstring table
1773860fcc7SKai Wang.Po
1783860fcc7SKai Wangsee
1793860fcc7SKai Wang.Sx "Archive String Tables"
1803860fcc7SKai Wangbelow
1813860fcc7SKai Wang.Pc ,
1823860fcc7SKai Wangand the decimal offset of the file name in the string table is stored
1833860fcc7SKai Wangin the
1843860fcc7SKai Wang.Ar ar_name
1853860fcc7SKai Wangfield, prefixed by a
1863860fcc7SKai Wang.Dq Li /
1873860fcc7SKai Wangcharacter.
1883860fcc7SKai Wang.Pp
1893860fcc7SKai WangAs an example, if the real file name has been stored at offset 768 in
1903860fcc7SKai Wangthe archive string table, the
1913860fcc7SKai Wang.Ar ar_name
1923860fcc7SKai Wangfield of the header will contain the string
1933860fcc7SKai Wang.Dq /768 .
1943860fcc7SKai Wang.El
1953860fcc7SKai Wang.Ss "Special Archive Members"
1963860fcc7SKai WangThe following archive members are special.
1973860fcc7SKai Wang.Bl -tag -width indent
1983860fcc7SKai Wang.It Dq Li /
1993860fcc7SKai WangIn the SVR4/GNU variant of the archive format, the archive member with
2003860fcc7SKai Wangname
2013860fcc7SKai Wang.Dq Li /
2023860fcc7SKai Wangdenotes an archive symbol table.
2033860fcc7SKai WangIf present, this member will be the very first member in the
2043860fcc7SKai Wangarchive.
2053860fcc7SKai Wang.It Dq Li //
2063860fcc7SKai WangIn the SVR4/GNU variant of the archive format, the archive member with
2073860fcc7SKai Wangname
2083860fcc7SKai Wang.Dq Li //
2093860fcc7SKai Wangdenotes the archive string table.
2103860fcc7SKai WangThis special member is used to hold filenames that do not fit in the
2113860fcc7SKai Wangfile name field of the header
2123860fcc7SKai Wang.Po
2133860fcc7SKai Wangsee
2143860fcc7SKai Wang.Sx "Representing File Names"
2153860fcc7SKai Wangabove
2163860fcc7SKai Wang.Pc .
2173860fcc7SKai WangIf present, this member immediately follows the archive symbol table
2183860fcc7SKai Wangif an archive symbol table is present, or is the first member otherwise.
2193860fcc7SKai Wang.It Dq Li "__.SYMDEF"
2203860fcc7SKai WangThis special member contains the archive symbol table in the BSD
2213860fcc7SKai Wangvariant of the archive format.
2223860fcc7SKai WangIf present, this member will be the very first member in the
2233860fcc7SKai Wangarchive.
2243860fcc7SKai Wang.El
2253860fcc7SKai Wang.Ss "Archive String Tables"
2263860fcc7SKai WangAn archive string table is used in the SVR4/GNU archive format to hold
2273860fcc7SKai Wangfile names that are too large to fit into the constraints of the
2283860fcc7SKai Wang.Ar ar_name
2293860fcc7SKai Wangfield of the archive header.
2303860fcc7SKai WangAn archive string table contains a sequence of file names.
2313860fcc7SKai WangEach file name in the archive string table is terminated by the
2323860fcc7SKai Wangbyte sequence 0x2F, 0x0A
2333860fcc7SKai Wang.Po
2343860fcc7SKai Wangthe ASCII string
2353860fcc7SKai Wang.Dq "/\en"
2363860fcc7SKai Wang.Pc .
2373860fcc7SKai WangNo padding is used to separate adjacent file names.
2383860fcc7SKai Wang.Ss "Archive Symbol Tables"
2393860fcc7SKai WangArchive symbol tables are used to speed up link editing by providing a
2403860fcc7SKai Wangmapping between the program symbols defined in the archive
2413860fcc7SKai Wangand the corresponding archive members.
2423860fcc7SKai WangArchive symbol tables are managed by the
2433860fcc7SKai Wang.Xr ranlib 1
2443860fcc7SKai Wangutility.
2453860fcc7SKai Wang.Pp
2463860fcc7SKai WangThe format of archive symbol tables is as follows:
2473860fcc7SKai Wang.Bl -tag -width "SVR4/GNU"
24812d64ed1SJoseph Koshy.It BSD
2493860fcc7SKai WangIn the BSD archive format, the archive symbol table comprises
2503860fcc7SKai Wangof two parts: a part containing an array of
2513860fcc7SKai Wang.Vt "struct ranlib"
2523860fcc7SKai Wangdescriptors, followed by a part containing a symbol string table.
2533860fcc7SKai WangThe sizes and layout of the structures that make up a BSD format
2543860fcc7SKai Wangarchive symbol table are machine dependent.
2553860fcc7SKai Wang.Pp
2563860fcc7SKai WangThe part containing
2573860fcc7SKai Wang.Vt "struct ranlib"
2583860fcc7SKai Wangdescriptors begins with a field containing the size in bytes of the
2593860fcc7SKai Wangarray of
2603860fcc7SKai Wang.Vt "struct ranlib"
2613860fcc7SKai Wangdescriptors encoded as a C
2623860fcc7SKai Wang.Vt long
2633860fcc7SKai Wangvalue.
2643860fcc7SKai Wang.Pp
2653860fcc7SKai WangThe array of
2663860fcc7SKai Wang.Vt "struct ranlib"
2673860fcc7SKai Wangdescriptors follows the size field.
2683860fcc7SKai WangEach
2693860fcc7SKai Wang.Vt "struct ranlib"
2703860fcc7SKai Wangdescriptor describes one symbol.
2713860fcc7SKai Wang.Pp
2723860fcc7SKai WangA
2733860fcc7SKai Wang.Vt "struct ranlib"
2743860fcc7SKai Wangdescriptor comprises two fields:
2753860fcc7SKai Wang.Bl -tag -width "Ar ran_strx" -compact
2763860fcc7SKai Wang.It Ar ran_strx
2773860fcc7SKai Wang.Pq C Vt long
2783860fcc7SKai WangThis field contains the zero-based offset of the symbol name in the
2793860fcc7SKai Wangsymbol string table.
2803860fcc7SKai Wang.It Ar ran_off
2813860fcc7SKai Wang.Pq C Vt long
2823860fcc7SKai WangThis field is the file offset to the archive header for the archive
2833860fcc7SKai Wangmember defining the symbol.
28412d64ed1SJoseph Koshy.El
2853860fcc7SKai Wang.Pp
2863860fcc7SKai WangThe part containing the symbol string table begins with a field
2873860fcc7SKai Wangcontaining the size in bytes of the string table, encoded as a C
2883860fcc7SKai Wang.Vt long
2893860fcc7SKai Wangvalue.
2903860fcc7SKai WangThis string table follows the size field, and contains
2913860fcc7SKai WangNUL-terminated strings for the symbols in the symbol table.
29212d64ed1SJoseph Koshy.It SVR4/GNU
2933860fcc7SKai WangIn the SVR4/GNU archive format, the archive symbol table starts with a
2943860fcc7SKai Wang4-byte binary value containing the number of entries contained in the
2953860fcc7SKai Wangarchive symbol table.
2963860fcc7SKai WangThis count of entries is stored most significant byte first.
2973860fcc7SKai Wang.Pp
2983860fcc7SKai WangNext, there are
2993860fcc7SKai Wang.Ar count
3003860fcc7SKai Wang4-byte numbers, each stored most significant byte first.
3013860fcc7SKai WangEach number is a binary offset to the archive header for the member in
3023860fcc7SKai Wangthe archive file for the corresponding symbol table entry.
3033860fcc7SKai Wang.Pp
3043860fcc7SKai WangAfter the binary offset values, there are
3053860fcc7SKai Wang.Ar count
3063860fcc7SKai WangNUL-terminated strings in sequence, holding the symbol names for
3073860fcc7SKai Wangthe corresponding symbol table entries.
30812d64ed1SJoseph Koshy.El
3093860fcc7SKai Wang.Sh STANDARDS COMPLIANCE
3103860fcc7SKai WangThe
31112d64ed1SJoseph Koshy.Xr ar 1
3123860fcc7SKai Wangarchive format is not currently specified by a standard.
3133860fcc7SKai Wang.Pp
3143860fcc7SKai WangThis manual page documents the
3153860fcc7SKai Wang.Xr ar 1
3163860fcc7SKai Wangarchive formats used by the
3173860fcc7SKai Wang.Bx 4.4
3183860fcc7SKai Wangand
3193860fcc7SKai Wang.Ux SVR4
3203860fcc7SKai Wangoperating system releases.
32112d64ed1SJoseph Koshy.Sh SEE ALSO
32212d64ed1SJoseph Koshy.Xr ar 1 ,
3233860fcc7SKai Wang.Xr ld 1 ,
32412d64ed1SJoseph Koshy.Xr ranlib 1 ,
32512d64ed1SJoseph Koshy.Xr elf 3 ,
3263860fcc7SKai Wang.Xr elf_getarsym 3 ,
3273860fcc7SKai Wang.Xr elf_rand 3
328