xref: /freebsd/share/man/man5/ar.5 (revision 3860fcc7f07c2d92b5e5a99d92a2cbd3081e8acf)
1*3860fcc7SKai 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.\"
12*3860fcc7SKai Wang.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13*3860fcc7SKai Wang.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14*3860fcc7SKai Wang.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15*3860fcc7SKai Wang.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16*3860fcc7SKai Wang.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17*3860fcc7SKai Wang.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18*3860fcc7SKai Wang.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19*3860fcc7SKai Wang.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20*3860fcc7SKai Wang.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21*3860fcc7SKai Wang.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22*3860fcc7SKai Wang.\" SUCH DAMAGE.
2312d64ed1SJoseph Koshy.\"
2412d64ed1SJoseph Koshy.\" $FreeBSD$
2512d64ed1SJoseph Koshy.\"
26*3860fcc7SKai Wang.Dd November 28, 2010
27aa12cea2SUlrich Spörlein.Os
28*3860fcc7SKai Wang.Dt AR 5
2912d64ed1SJoseph Koshy.Sh NAME
3012d64ed1SJoseph Koshy.Nm ar
31*3860fcc7SKai Wang.Nd archive file format for
3212d64ed1SJoseph Koshy.Xr ar 1
3312d64ed1SJoseph Koshyand
3412d64ed1SJoseph Koshy.Xr ranlib 1
35*3860fcc7SKai Wang.Sh SYNOPSIS
3612d64ed1SJoseph Koshy.In ar.h
37*3860fcc7SKai Wang.Sh DESCRIPTION
3812d64ed1SJoseph Koshy.Xr ar 1
39*3860fcc7SKai Wangarchives are created and managed by the
40*3860fcc7SKai Wang.Xr ar 1
41*3860fcc7SKai Wangand
42*3860fcc7SKai Wang.Xr ranlib 1
43*3860fcc7SKai Wangutilities.
44*3860fcc7SKai WangThese archives are typically used during program development to
45*3860fcc7SKai Wanghold libraries of program objects.
46*3860fcc7SKai WangAn
47*3860fcc7SKai Wang.Xr ar 1
48*3860fcc7SKai Wangarchive is contained in a single operating system file.
4912d64ed1SJoseph Koshy.Pp
50*3860fcc7SKai WangThis manual page documents two variants of the
51*3860fcc7SKai Wang.Xr ar 1
52*3860fcc7SKai Wangarchive format: the BSD archive format, and the SVR4/GNU archive
53*3860fcc7SKai Wangformat.
5412d64ed1SJoseph Koshy.Pp
55*3860fcc7SKai WangIn both variants the archive file starts with an identifying byte
56*3860fcc7SKai Wangsequence of the seven ASCII characters
57*3860fcc7SKai Wang.Sq Li "!<arch>"
58*3860fcc7SKai Wangfollowed by a ASCII linefeed character
59*3860fcc7SKai Wang.Po
60*3860fcc7SKai Wangsee the constant
61*3860fcc7SKai Wang.Dq ARMAG
62*3860fcc7SKai Wangin the header file
63*3860fcc7SKai Wang.In ar.h
64*3860fcc7SKai Wang.Pc .
6512d64ed1SJoseph Koshy.Pp
66*3860fcc7SKai WangArchive members follow the initial identifying byte sequence.
67*3860fcc7SKai WangEach archive member is prefixed by a fixed size header describing the
68*3860fcc7SKai Wangfile attributes associated with the member.
69*3860fcc7SKai Wang.Ss "Archive Headers"
70*3860fcc7SKai WangAn archive header describes the file attributes for the archive member that
71*3860fcc7SKai Wangfollows it.
7212d64ed1SJoseph KoshyThe
73*3860fcc7SKai Wang.Xr ar 5
74*3860fcc7SKai Wangformat only supports a limited number of attributes: the file name,
75*3860fcc7SKai Wangthe file creation time stamp, the uid and gid of the creator, the file
76*3860fcc7SKai Wangmode and the file size.
7712d64ed1SJoseph Koshy.Pp
78*3860fcc7SKai WangArchive headers are placed at an even byte offset in the archive file.
79*3860fcc7SKai WangIf the data for an archive member ends at an odd byte offset, then a
80*3860fcc7SKai Wangpadding byte with value 0x0A is used to position the next archive
81*3860fcc7SKai Wangheader on an even byte offset.
82*3860fcc7SKai Wang.Pp
83*3860fcc7SKai WangAn archive header comprises the following fixed sized fields:
84*3860fcc7SKai Wang.Bl -tag -width "Li ar_name"
85*3860fcc7SKai Wang.It Ar ar_name
86*3860fcc7SKai Wang(16 bytes) The file name of the archive member.
87*3860fcc7SKai WangThe format of this field varies between the BSD and SVR4/GNU formats and
88*3860fcc7SKai Wangis described in more detail in the section
89*3860fcc7SKai Wang.Sx "Representing File Names"
90*3860fcc7SKai Wangbelow.
91*3860fcc7SKai Wang.It Ar ar_date
92*3860fcc7SKai Wang(12 bytes) The file modification time for the member in seconds since the
93*3860fcc7SKai Wangepoch, encoded as a decimal number.
94*3860fcc7SKai Wang.It Ar ar_uid
95*3860fcc7SKai Wang(6 bytes) The uid associated with the archive member, encoded as a
96*3860fcc7SKai Wangdecimal number.
97*3860fcc7SKai Wang.It Ar ar_gid
98*3860fcc7SKai Wang(6 bytes) The gid associated with the archive member, encoded as a
99*3860fcc7SKai Wangdecimal number.
100*3860fcc7SKai Wang.It Ar ar_mode
101*3860fcc7SKai Wang(8 bytes) The file mode for the archive member, encoded as an octal
102*3860fcc7SKai Wangnumber.
103*3860fcc7SKai Wang.It Ar ar_size
104*3860fcc7SKai Wang(10 bytes) In the SVR4/GNU archive format this field holds the size in
105*3860fcc7SKai Wangbytes of the archive member, encoded as a decimal number.
106*3860fcc7SKai WangIn the BSD archive format, for short file names, this field
107*3860fcc7SKai Wangholds the size in bytes of the archive member, encoded as a decimal
108*3860fcc7SKai Wangnumber.
109*3860fcc7SKai WangFor long file names
110*3860fcc7SKai Wang.Po
111*3860fcc7SKai Wangsee
112*3860fcc7SKai Wang.Sx "Representing File Names"
113*3860fcc7SKai Wangbelow
114*3860fcc7SKai Wang.Pc ,
115*3860fcc7SKai Wangthe field contains the combined size of the
116*3860fcc7SKai Wangarchive member and its file name, encoded as a decimal number.
117*3860fcc7SKai Wang.It Ar ar_fmag
118*3860fcc7SKai Wang(2 bytes) This field holds 2 bytes with values 0x96 and 0x0A
119*3860fcc7SKai Wangrespectively, marking the end of the header.
120*3860fcc7SKai Wang.El
121*3860fcc7SKai Wang.Pp
122*3860fcc7SKai WangUnused bytes in the fields of an archive header are set to the value
123*3860fcc7SKai Wang0x20.
124*3860fcc7SKai Wang.Ss "Representing File Names"
125*3860fcc7SKai WangThe BSD and SVR4/GNU variants use different schemes for encoding file
126*3860fcc7SKai Wangnames for members.
127*3860fcc7SKai Wang.Bl -tag -width "SVR4/GNU"
128*3860fcc7SKai Wang.It "BSD"
129*3860fcc7SKai WangFile names that are upto 16 bytes long and which do not contain
130*3860fcc7SKai Wangembedded spaces are stored directly in the
131*3860fcc7SKai Wang.Ar ar_name
132*3860fcc7SKai Wangfield of the archive header.
133*3860fcc7SKai WangFile names that are either longer than 16 bytes or which contain
134*3860fcc7SKai Wangembedded spaces are stored immediately after the archive header
135*3860fcc7SKai Wangand the
136*3860fcc7SKai Wang.Ar ar_name
137*3860fcc7SKai Wangfield of the archive header is set to the string
138*3860fcc7SKai Wang.Dq "#1/"
139*3860fcc7SKai Wangfollowed by a decimal representation of the number of bytes needed for
140*3860fcc7SKai Wangthe file name.
141*3860fcc7SKai WangIn addition, the
142*3860fcc7SKai Wang.Ar ar_size
143*3860fcc7SKai Wangfield of the archive header is set to the decimal representation of
144*3860fcc7SKai Wangthe combined sizes of the archive member and the file name.
145*3860fcc7SKai WangThe file contents of the member follows the file name without further
146*3860fcc7SKai Wangpadding.
147*3860fcc7SKai Wang.Pp
148*3860fcc7SKai WangAs an example, if the file name for a member was
149*3860fcc7SKai Wang.Dq "A B"
150*3860fcc7SKai Wangand its contents was the string
151*3860fcc7SKai Wang.Dq "C D" ,
152*3860fcc7SKai Wangthen the
153*3860fcc7SKai Wang.Ar ar_name
154*3860fcc7SKai Wangfield of the header would contain
155*3860fcc7SKai Wang.Dq Li "#1/3" ,
156*3860fcc7SKai Wangthe
157*3860fcc7SKai Wang.Ar ar_size
158*3860fcc7SKai Wangfield of the header would contain
159*3860fcc7SKai Wang.Dq Li 6 ,
160*3860fcc7SKai Wangand the bytes immediately following the header would be 0x41, 0x20,
161*3860fcc7SKai Wang0x42, 0x43, 0x20 and 0x44
162*3860fcc7SKai Wang.Po
163*3860fcc7SKai WangASCII
164*3860fcc7SKai Wang.Dq "A BC D"
165*3860fcc7SKai Wang.Pc .
166*3860fcc7SKai Wang.It "SVR4/GNU"
167*3860fcc7SKai WangFile names that are upto 15 characters long are stored directly in the
168*3860fcc7SKai Wang.Ar ar_name
169*3860fcc7SKai Wangfield of the header, terminated by a
170*3860fcc7SKai Wang.Dq Li /
171*3860fcc7SKai Wangcharacter.
172*3860fcc7SKai Wang.Pp
173*3860fcc7SKai WangIf the file name is larger than would fit in space for the
174*3860fcc7SKai Wang.Ar ar_name
175*3860fcc7SKai Wangfield, then the actual file name is kept in the archive
176*3860fcc7SKai Wangstring table
177*3860fcc7SKai Wang.Po
178*3860fcc7SKai Wangsee
179*3860fcc7SKai Wang.Sx "Archive String Tables"
180*3860fcc7SKai Wangbelow
181*3860fcc7SKai Wang.Pc ,
182*3860fcc7SKai Wangand the decimal offset of the file name in the string table is stored
183*3860fcc7SKai Wangin the
184*3860fcc7SKai Wang.Ar ar_name
185*3860fcc7SKai Wangfield, prefixed by a
186*3860fcc7SKai Wang.Dq Li /
187*3860fcc7SKai Wangcharacter.
188*3860fcc7SKai Wang.Pp
189*3860fcc7SKai WangAs an example, if the real file name has been stored at offset 768 in
190*3860fcc7SKai Wangthe archive string table, the
191*3860fcc7SKai Wang.Ar ar_name
192*3860fcc7SKai Wangfield of the header will contain the string
193*3860fcc7SKai Wang.Dq /768 .
194*3860fcc7SKai Wang.El
195*3860fcc7SKai Wang.Ss "Special Archive Members"
196*3860fcc7SKai WangThe following archive members are special.
197*3860fcc7SKai Wang.Bl -tag -width indent
198*3860fcc7SKai Wang.It Dq Li /
199*3860fcc7SKai WangIn the SVR4/GNU variant of the archive format, the archive member with
200*3860fcc7SKai Wangname
201*3860fcc7SKai Wang.Dq Li /
202*3860fcc7SKai Wangdenotes an archive symbol table.
203*3860fcc7SKai WangIf present, this member will be the very first member in the
204*3860fcc7SKai Wangarchive.
205*3860fcc7SKai Wang.It Dq Li //
206*3860fcc7SKai WangIn the SVR4/GNU variant of the archive format, the archive member with
207*3860fcc7SKai Wangname
208*3860fcc7SKai Wang.Dq Li //
209*3860fcc7SKai Wangdenotes the archive string table.
210*3860fcc7SKai WangThis special member is used to hold filenames that do not fit in the
211*3860fcc7SKai Wangfile name field of the header
212*3860fcc7SKai Wang.Po
213*3860fcc7SKai Wangsee
214*3860fcc7SKai Wang.Sx "Representing File Names"
215*3860fcc7SKai Wangabove
216*3860fcc7SKai Wang.Pc .
217*3860fcc7SKai WangIf present, this member immediately follows the archive symbol table
218*3860fcc7SKai Wangif an archive symbol table is present, or is the first member otherwise.
219*3860fcc7SKai Wang.It Dq Li "__.SYMDEF"
220*3860fcc7SKai WangThis special member contains the archive symbol table in the BSD
221*3860fcc7SKai Wangvariant of the archive format.
222*3860fcc7SKai WangIf present, this member will be the very first member in the
223*3860fcc7SKai Wangarchive.
224*3860fcc7SKai Wang.El
225*3860fcc7SKai Wang.Ss "Archive String Tables"
226*3860fcc7SKai WangAn archive string table is used in the SVR4/GNU archive format to hold
227*3860fcc7SKai Wangfile names that are too large to fit into the constraints of the
228*3860fcc7SKai Wang.Ar ar_name
229*3860fcc7SKai Wangfield of the archive header.
230*3860fcc7SKai WangAn archive string table contains a sequence of file names.
231*3860fcc7SKai WangEach file name in the archive string table is terminated by the
232*3860fcc7SKai Wangbyte sequence 0x2F, 0x0A
233*3860fcc7SKai Wang.Po
234*3860fcc7SKai Wangthe ASCII string
235*3860fcc7SKai Wang.Dq "/\en"
236*3860fcc7SKai Wang.Pc .
237*3860fcc7SKai WangNo padding is used to separate adjacent file names.
238*3860fcc7SKai Wang.Ss "Archive Symbol Tables"
239*3860fcc7SKai WangArchive symbol tables are used to speed up link editing by providing a
240*3860fcc7SKai Wangmapping between the program symbols defined in the archive
241*3860fcc7SKai Wangand the corresponding archive members.
242*3860fcc7SKai WangArchive symbol tables are managed by the
243*3860fcc7SKai Wang.Xr ranlib 1
244*3860fcc7SKai Wangutility.
245*3860fcc7SKai Wang.Pp
246*3860fcc7SKai WangThe format of archive symbol tables is as follows:
247*3860fcc7SKai Wang.Bl -tag -width "SVR4/GNU"
24812d64ed1SJoseph Koshy.It BSD
249*3860fcc7SKai WangIn the BSD archive format, the archive symbol table comprises
250*3860fcc7SKai Wangof two parts: a part containing an array of
251*3860fcc7SKai Wang.Vt "struct ranlib"
252*3860fcc7SKai Wangdescriptors, followed by a part containing a symbol string table.
253*3860fcc7SKai WangThe sizes and layout of the structures that make up a BSD format
254*3860fcc7SKai Wangarchive symbol table are machine dependent.
255*3860fcc7SKai Wang.Pp
256*3860fcc7SKai WangThe part containing
257*3860fcc7SKai Wang.Vt "struct ranlib"
258*3860fcc7SKai Wangdescriptors begins with a field containing the size in bytes of the
259*3860fcc7SKai Wangarray of
260*3860fcc7SKai Wang.Vt "struct ranlib"
261*3860fcc7SKai Wangdescriptors encoded as a C
262*3860fcc7SKai Wang.Vt long
263*3860fcc7SKai Wangvalue.
264*3860fcc7SKai Wang.Pp
265*3860fcc7SKai WangThe array of
266*3860fcc7SKai Wang.Vt "struct ranlib"
267*3860fcc7SKai Wangdescriptors follows the size field.
268*3860fcc7SKai WangEach
269*3860fcc7SKai Wang.Vt "struct ranlib"
270*3860fcc7SKai Wangdescriptor describes one symbol.
271*3860fcc7SKai Wang.Pp
272*3860fcc7SKai WangA
273*3860fcc7SKai Wang.Vt "struct ranlib"
274*3860fcc7SKai Wangdescriptor comprises two fields:
275*3860fcc7SKai Wang.Bl -tag -width "Ar ran_strx" -compact
276*3860fcc7SKai Wang.It Ar ran_strx
277*3860fcc7SKai Wang.Pq C Vt long
278*3860fcc7SKai WangThis field contains the zero-based offset of the symbol name in the
279*3860fcc7SKai Wangsymbol string table.
280*3860fcc7SKai Wang.It Ar ran_off
281*3860fcc7SKai Wang.Pq C Vt long
282*3860fcc7SKai WangThis field is the file offset to the archive header for the archive
283*3860fcc7SKai Wangmember defining the symbol.
28412d64ed1SJoseph Koshy.El
285*3860fcc7SKai Wang.Pp
286*3860fcc7SKai WangThe part containing the symbol string table begins with a field
287*3860fcc7SKai Wangcontaining the size in bytes of the string table, encoded as a C
288*3860fcc7SKai Wang.Vt long
289*3860fcc7SKai Wangvalue.
290*3860fcc7SKai WangThis string table follows the size field, and contains
291*3860fcc7SKai WangNUL-terminated strings for the symbols in the symbol table.
29212d64ed1SJoseph Koshy.It SVR4/GNU
293*3860fcc7SKai WangIn the SVR4/GNU archive format, the archive symbol table starts with a
294*3860fcc7SKai Wang4-byte binary value containing the number of entries contained in the
295*3860fcc7SKai Wangarchive symbol table.
296*3860fcc7SKai WangThis count of entries is stored most significant byte first.
297*3860fcc7SKai Wang.Pp
298*3860fcc7SKai WangNext, there are
299*3860fcc7SKai Wang.Ar count
300*3860fcc7SKai Wang4-byte numbers, each stored most significant byte first.
301*3860fcc7SKai WangEach number is a binary offset to the archive header for the member in
302*3860fcc7SKai Wangthe archive file for the corresponding symbol table entry.
303*3860fcc7SKai Wang.Pp
304*3860fcc7SKai WangAfter the binary offset values, there are
305*3860fcc7SKai Wang.Ar count
306*3860fcc7SKai WangNUL-terminated strings in sequence, holding the symbol names for
307*3860fcc7SKai Wangthe corresponding symbol table entries.
30812d64ed1SJoseph Koshy.El
309*3860fcc7SKai Wang.Sh STANDARDS COMPLIANCE
310*3860fcc7SKai WangThe
31112d64ed1SJoseph Koshy.Xr ar 1
312*3860fcc7SKai Wangarchive format is not currently specified by a standard.
313*3860fcc7SKai Wang.Pp
314*3860fcc7SKai WangThis manual page documents the
315*3860fcc7SKai Wang.Xr ar 1
316*3860fcc7SKai Wangarchive formats used by the
317*3860fcc7SKai Wang.Bx 4.4
318*3860fcc7SKai Wangand
319*3860fcc7SKai Wang.Ux SVR4
320*3860fcc7SKai Wangoperating system releases.
32112d64ed1SJoseph Koshy.Sh SEE ALSO
32212d64ed1SJoseph Koshy.Xr ar 1 ,
323*3860fcc7SKai Wang.Xr ld 1 ,
32412d64ed1SJoseph Koshy.Xr ranlib 1 ,
32512d64ed1SJoseph Koshy.Xr elf 3 ,
326*3860fcc7SKai Wang.Xr elf_getarsym 3 ,
327*3860fcc7SKai Wang.Xr elf_rand 3
328