1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
.\" Copyright (c) 2007 Joseph Koshy. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" This software is provided by Joseph Koshy ``as is'' and
.\" any express or implied warranties, including, but not limited to, the
.\" implied warranties of merchantability and fitness for a particular purpose
.\" are disclaimed. in no event shall Joseph Koshy be liable
.\" for any direct, indirect, incidental, special, exemplary, or consequential
.\" damages (including, but not limited to, procurement of substitute goods
.\" or services; loss of use, data, or profits; or business interruption)
.\" however caused and on any theory of liability, whether in contract, strict
.\" liability, or tort (including negligence or otherwise) arising in any way
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
.\" $FreeBSD$
.\"
.Dd September 07, 2007
.Os
.Dt AR 5
.Sh NAME
.Nm ar
.Nd format of archives managed by ar(1) and ranlib(1)
.Sh SYNOPSIS
.In ar.h
.Sh DESCRIPTION
An archive managed by the
.Xr ar 1
and
.Xr ranlib 1
utilities is a single file that stores the individual members of the
archive along with metadata for each member.
There are two major variants of the
.Xr ar 1
archive format, the BSD variant and the SVR4/GNU variant.
Both variants are described by this manual page.
.Pp
The header file
.In ar.h
defines constants and structures used to describe the layout
of these archives.
.Ss Archive Layout
.Xr ar 1
archives start with a string of magic bytes
.Qq !<arch>\en
(constant
.Dv ARMAG
in header
.In ar.h ) .
The content of the archive follows the magic bytes.
Each member stored in the archive is preceded by a fixed size
archive header that stores file permissions, last modification
time, the owner, and the group of the archived file.
.Pp
Archive headers start at an even byte offset in the archive
file.
If the length of the preceding archive member was odd, then an extra
newline character
.Dq "\en"
is used as padding.
.Pp
The archive header comprises six fixed-size ASCII strings followed
by a two character trailer (see
.Vt "struct ar_hdr"
in header file
.In ar.h Ns ):
.Bd -literal
struct ar_hdr {
char ar_name[16]; /* name */
char ar_date[12]; /* modification time */
char ar_uid[6]; /* user id */
char ar_gid[6]; /* group id */
char ar_mode[8]; /* octal file permissions */
char ar_size[10]; /* size in bytes */
char ar_fmag[2]; /* consistency check */
};
.Ed
.Pp
Unused characters in the header are filled with space (ASCII 20H)
characters.
Each field of the header abuts the next without additional padding.
.Pp
The members of the archive header are as follows:
.Bl -tag -width "Va ar_name" -compact
.It Va ar_date
This field holds the decimal representation of the
modification time, in seconds since the epoch, of the archive
member.
.It Va ar_fmag
This trailer field holds the two characters
.Qq `\en
(constant
.Dv ARFMAG
defined in header file
.In ar.h Ns ),
and is used for consistency checks.
.It Va ar_gid
This field holds the decimal representation of the numeric
user id of the creator of the member.
.It Va ar_mode
This field holds octal representation of the file permissions
for the member.
.It Va ar_name
This field holds the name of an archive member.
The usage of this field depends on the format variant:
.Bl -tag -width "SVR4/GNU" -compact
.It BSD
In the BSD variant, names that are shorter than 16 characters and
without embedded spaces are stored directly in this field.
If a name has an embedded space, or if it is longer than 16
characters, then the string
.Qq "#1/"
followed by the decimal representation of the length of the file name
is placed in this field.
The actual file name is stored immediately after the archive header.
The content of the archive member follows the file name.
The
.Va ar_size
field of the header (see below) will then hold the sum of the size of
the file name and the size of the member.
.It SVR4/GNU
In the SVR4/GNU variant, names up to 15 characters in length are
stored directly in this field, and are terminated by a
.Qq /
(ASCII 2FH) character.
Names larger than 15 characters in length are stored in a special
archive string table member (see
.Sx "Archive String Table"
below), and the
.Va ar_name
field holds the string
.Qq "/"
followed by the decimal representation of the offset in the archive
string table of the actual name.
.El
.It Va ar_size
In the SVR4/GNU variant, this field holds the decimal representation
of actual size in bytes of the archived file.
In the BSD variant, for member names that use the
.Va ar_name
field directly, this field holds the decimal representation of the
actual size in bytes of the archived member.
For member names that use the extension mechanism described above, the
field will hold the sum of the sizes, in bytes, of the filename and the
archive member.
.It Va ar_uid
This field holds the decimal representation of the numeric
group id of the creator of the member.
.El
.Ss Archive Symbol Table
An archive may additionally contain an archive symbol table
used by the link editor,
.Xr ld 1 .
This symbol table has the member name
.Qq __.SYMDEF
in the BSD variant of the archive format, and the name
.Qq /
in the SVR4/GNU variant.
.Pp
The format of the symbol table depends on the format variant:
.Bl -tag -width "SVR4/GNU" -compact
.It BSD
In the BSD variant, the symbol table has 4 parts encoded in
a machine dependent manner:
.Bl -enum -compact
.It
The first part is a binary value containing size in bytes of the
second part encoded as a C
.Dq long .
.It
The second part is a list of
.Vt struct ranlib
structures (see
.In ranlib.h Ns ).
Each ranlib structure describes one symbol and comprises of
two C
.Dq long
values.
The first
.Dq long
is a zero-based offset into the string table in the fourth part
for the symbol's name.
The second
.Dq long
is an offset from the beginning of the archive to the start
of the archive header for the member that defines the symbol.
.It
The third part is a binary value denoting the length of the
string table contained in the fourth part.
.It
The fourth part is a string table containing NUL-terminated
strings.
.El
.It SVR4/GNU
In the SVR4/GNU variant, the symbol table comprises of three parts
which follow each other without padding:
.Bl -enum -compact
.It
The first part comprises of a count of entries in the symbol table,
stored a 4 byte binary value in MSB first order.
.It
The next part is an array of 4 byte file offsets within the archive
to archive header for members that define the symbol in question.
Each offset in stored in MSB first order.
.It
The third part is a string table, that contains NUL-terminated
strings for the symbols in the symbol table.
.El
.El
.Ss Archive String Table
In the SVR4/GNU variant of the
.Xr ar 1
archive format, long file names are stored in a separate
archive string table and referenced from the archive header
for each member.
Each file name is terminated by the string
.Qq /\en .
The string table itself has a name of
.Qq // .
.Sh SEE ALSO
.Xr ar 1 ,
.Xr ranlib 1 ,
.Xr archive 3 ,
.Xr elf 3 ,
.Xr gelf 3 ,
.Xr elf 5
|