AR(5) BSD Programmer's Manual AR(5)NAMEar - archive (library) file format
SYNOPSIS
#include <ar.h>
DESCRIPTION
The archive command ar combines several files into one. Archives are
mainly used as libraries of object files intended to be loaded using the
link-editor ld(1).
A file created with ar begins with the `magic' string `!<arch>\n'. The
rest of the archive is made up of objects, each of which is composed of a
header for a file and the file contents. The header is portable between
machine architectures, and, if the file contents are printable, the
archive is itself printable.
The header is made up of six ASCII fields, followed by a two character
trailer:
struct ar_hdr {
char ar_name[16];
char ar_date[12];
char ar_uid[6];
char ar_gid[6];
char ar_mode[8];
char ar_size[10];
char ar_fmag[2];
};
The fields are the object name ar_name, the file last modification time
ar_date, the user and group IDs ar_uid and ar_gid, the file mode ar_mode
and the file size ar_size. The trailing magic number field ar_fmag always
contains the two bytes ``\n'. All numeric fields are in decimal, except
for the file mode which is in octal.
Object names are file names without directory prefixes. If the object
name is 15 bytes long or less, the object name field contains the object
name and an appended `/' character, padded with spaces. If the object
name is longer than 15 bytes, then the object name field contains a
string consisting of an initial `/' character followed immediately by a
decimal number, padded with spaces. The decimal number is the byte off-
set of the full object name in the special long name dictionary object
(see below).
The modification time is the file st_mtime field, that is, seconds since
the epoch. The user and group id's are the file st_uid and st_gid
fields. The file mode is the file st_mode field. The file size is the
file st_size field. See stat(2) for details about these values.
Any unused characters in any of these fields are written as space charac-
ters. If any fields are their particular maximum number of characters in
length, there will be no separation between the fields.
Objects in the archive are always an even number of bytes long; files
which are an odd number of bytes long are padded with a newline (`\n')
character, although the size in the header does not reflect this.
Two special objects may appear in an archive. In an archive of relocat-
able binary files, the symbol cross-reference object contains a mapping
between symbol names and file offsets. The object consists of an array
of pairs of offsets, followed by a series of nul-terminated symbol names.
The first offset in each pair is the offset to a symbol name string,
while the second offset is the file offset of an object header that de-
scribes a relocatable binary file that defines the symbol. The object
name field for the cross-reference object contains a single `/' (padded
with spaces). The long name dictionary object contains a list of long
object names. Each name in the dictionary is a filename without a path
prefix, followed by a single `/' character and a newline. The object
name field for this object contains `//', padded with spaces.
SEE ALSOar(1), ld(1), ranlib(1), stat(2), a.out(5), elf(5)HISTORY
There have been at least five ar formats. The first was denoted by the
leading ``magic'' number 0177555 (stored as type int). These archives
were almost certainly created on a 16-bit machine, and contain headers
made up of five fields. The fields are the object name (8 characters),
the file last modification time (type long), the user id (type char), the
file mode (type char) and the file size (type unsigned int). Files were
padded to an even number of bytes.
The second was denoted by the leading ``magic'' number 0177545 (stored as
type int). These archives may have been created on either 16 or 32-bit
machines, and contain headers made up of six fields. The fields are the
object name (14 characters), the file last modification time (type long),
the user and group id's (each type char), the file mode (type int) and
the file size (type long). Files were padded to an even number of bytes.
The next archive format (without support for long character names and
names with embedded spaces) was introduced in 4.0BSD. The headers were
the same as the current format, with the exception that names longer than
16 characters were truncated, and names with embedded spaces (and often
trailing spaces) were not supported. It has been extended for these rea-
sons, as described above.
A format that supported long names appeared in 4.4BSD, but it was never
supported by the linker and archive tools, so it was discontinued.
The current archive format is believed to be identical to AT&T System V.4
UNIX.
BSDI BSD/OS December 16, 1997 2