ar
Purpose
Describes common archive file format.
Synopsis
#include <ar.h>
Description
The ar (archive) command is used to combine several files
into one. The ar command creates an ar file. The ld
(link editor) searches archive files to resolve program
linkage.
Each archive begins with the archive magic string:
#define ARMAG "!<arch>\n" /* magic string */
#define SARMAG 8 /* length of magic string */
Each archive that contains common object files includes
an archive symbol table. See "a.out" for the format of
an object file. ld uses this symbol table to determine
the archive members to load during the link edit process.
The archive symbol table, if it exists, is always the
first file in the archive. It is never listed, but ar
automatically creates and updates it.
The archive file members follow the archive header and
symbol table. A file member follows each file member
header. The format of a file member header is:
#define ARFMAG "\n" /* header trailer string */
struct ar_hdr { /* file member header */
char ar_name[16]; /* file member name - terminated by '/'*/
char ar_date[12]; /* file member date */
char ar_uid[6]; /* file member user identification */
char ar_gid[6]; /* file member group identification */
char ar_mode[8]; /* file member mode */
char ar_size[10]; /* file member size */
char ar_fmag[2]; /* ARFMAG - string to end header */
};
All information in the file member header is in printable
ASCII. The numeric information contained in the headers
is stored as decimal numbers, except ar_mode, which is
stored in octal. Thus, if the archive contains printable
files, you can print the archive.
The ar_name field is blank-padded and terminated by a /
(slash). The ar_date field indicates the date the file
was last modified prior to archive. The ar command
allows archives to move from system to system.
Each archive file member begins on an even-byte boundary.
ar inserts null bytes for padding and a new-line char-
acter between files, if necessary. The ar_size field is
the size of the file without padding. An archive file
contains no empty areas.
If the archive symbol table exists, the first file in the
archive has a zero-length name, for example, ar_name[0]
== '/'. The contents of the symbol table are as follows:
The number of symbols. This is 4 bytes long.
The array of offsets into the archive file. The
length is determined by 4 bytes times the number of
symbols.
The name string table. The size is determined by
ar_size minus (4 bytes times (the number of symbols
plus 1)).
The sgetl and sputl functions manage the number of
symbols and the array of offsets. The string table con-
tains an equal number of null-terminated strings and ele-
ments in the offsets array. Each offset from the array
associates with the corresponding name from the string
table, in order. The string table names all the defined
global symbols found in the object files contained in the
archive. Each offset locates the archive header for the
associated symbol.
Related Information
In this book: "sgetl, sputl" and "a.out."
The ar, ld, and strip commands in AIX Operating System
Commands Reference.