AR(5) | MidnightBSD File Formats Manual | AR(5) |
#include
<ar.h>
ar(1) archives are created and managed by the ar(1) and ranlib(1) utilities. These archives are typically used during program development to hold libraries of program objects. An ar(1) archive is contained in a single operating system file.
This manual page documents two variants of the ar(1) archive format: the BSD archive format, and the SVR4/GNU archive format.
In both variants the archive file starts with an identifying byte
sequence of the seven ASCII characters
‘!<arch>
’ followed by a ASCII
linefeed character (see the constant “ARMAG” in the header
file <ar.h>
).
Archive members follow the initial identifying byte sequence. Each archive member is prefixed by a fixed size header describing the file attributes associated with the member.
An archive header describes the file attributes for the archive
member that follows it. The ar
format only supports
a limited number of attributes: the file name, the file creation time stamp,
the uid and gid of the creator, the file mode and the file size.
Archive headers are placed at an even byte offset in the archive file. If the data for an archive member ends at an odd byte offset, then a padding byte with value 0x0A is used to position the next archive header on an even byte offset.
An archive header comprises the following fixed sized fields:
Unused bytes in the fields of an archive header are set to the value 0x20.
The BSD and SVR4/GNU variants use different schemes for encoding file names for members.
As an example, if the file name for a member was “A
B” and its contents was the string “C D”, then the
ar_name field of the header would contain
“#1/3
”, the
ar_size field of the header would contain
“6
”, and the bytes immediately
following the header would be 0x41, 0x20, 0x42, 0x43, 0x20 and 0x44
(ASCII “A BC D”).
/
” character.
If the file name is larger than would fit in space for the
ar_name field, then the actual file name is kept
in the archive string table (see
Archive String Tables
below), and the decimal offset of the file name in the string table is
stored in the ar_name field, prefixed by a
“/
” character.
As an example, if the real file name has been stored at offset 768 in the archive string table, the ar_name field of the header will contain the string “/768”.
The following archive members are special.
/
”/
” denotes an archive symbol
table. If present, this member will be the very first member in the
archive.//
”//
” denotes the archive string
table. This special member is used to hold filenames that do not fit in
the file name field of the header (see
Representing File Names
above). If present, this member immediately follows the archive symbol
table if an archive symbol table is present, or is the first member
otherwise.__.SYMDEF
”An archive string table is used in the SVR4/GNU archive format to hold file names that are too large to fit into the constraints of the ar_name field of the archive header. An archive string table contains a sequence of file names. Each file name in the archive string table is terminated by the byte sequence 0x2F, 0x0A (the ASCII string “/\n”). No padding is used to separate adjacent file names.
Archive symbol tables are used to speed up link editing by providing a mapping between the program symbols defined in the archive and the corresponding archive members. Archive symbol tables are managed by the ranlib(1) utility.
The format of archive symbol tables is as follows:
The part containing struct ranlib descriptors begins with a field containing the size in bytes of the array of struct ranlib descriptors encoded as a C long value.
The array of struct ranlib descriptors follows the size field. Each struct ranlib descriptor describes one symbol.
A struct ranlib descriptor comprises two fields:
The part containing the symbol string table begins with a field containing the size in bytes of the string table, encoded as a C long value. This string table follows the size field, and contains NUL-terminated strings for the symbols in the symbol table.
Next, there are count 4-byte numbers, each stored most significant byte first. Each number is a binary offset to the archive header for the member in the archive file for the corresponding symbol table entry.
After the binary offset values, there are count NUL-terminated strings in sequence, holding the symbol names for the corresponding symbol table entries.
The ar(1) archive format is not currently specified by a standard.
This manual page documents the ar(1) archive formats used by the 4.4BSD and UNIX SVR4 operating system releases.
ar(1), ld(1), ranlib(1), elf(3), elf_getarsym(3), elf_rand(3)
November 28, 2010 | midnightbsd-3.1 |