1ar.h(3HEAD) Headers ar.h(3HEAD)
2
3
4
6 ar.h, ar - archive file format
7
9 #include <ar.h>
10
11
13 The archive command ar is used to combine several files into one. Ar‐
14 chives are used mainly as libraries to be searched by the link editor
15 ld.
16
17
18 Each archive begins with the archive magic string.
19
20 #define ARMAG "!<arch>\n" /* magic string */
21 #define SARMAG 8 /* length of magic string */
22
23
24
25 Following the archive magic string are the archive file members. Each
26 file member is preceded by a file member header which is of the follow‐
27 ing format:
28
29 #define ARFMAG "`\n" /* header trailer string */
30
31 struct ar_hdr /* file member header */
32 {
33 char ar_name[16]; /* '/' terminated file member name */
34 char ar_date[12]; /* file member date */
35 char ar_uid[6] /* file member user identification */
36 char ar_gid[6] /* file member group identification */
37 char ar_mode[8] /* file member mode (octal) */
38 char ar_size[10]; /* file member size */
39 char ar_fmag[2]; /* header trailer string */
40 };
41
42
43
44 All information in the file member headers is in printable ASCII. The
45 numeric information contained in the headers is stored as decimal num‐
46 bers (except for ar_mode which is in octal). Thus, if the archive con‐
47 tains printable files, the archive itself is printable.
48
49
50 If the file member name fits, the ar_name field contains the name
51 directly, and is terminated by a slash (/) and padded with blanks on
52 the right. If the member's name does not fit, ar_name contains a slash
53 (/) followed by a decimal representation of the name's offset in the
54 archive string table described below.
55
56
57 The ar_date field is the modification date of the file at the time of
58 its insertion into the archive. Common format archives can be moved
59 from system to system as long as the portable archive command ar is
60 used.
61
62
63 Each archive file member begins on an even byte boundary; a newline is
64 inserted between files if necessary. Nevertheless, the size given
65 reflects the actual size of the file exclusive of padding.
66
67
68 Notice there is no provision for empty areas in an archive file.
69
70
71 Each archive that contains object files (see a.out(4)) includes an ar‐
72 chive symbol table. This symbol table is used by the link editor ld to
73 determine which archive members must be loaded during the link edit
74 process. The archive symbol table (if it exists) is always the first
75 file in the archive (but is never listed) and is automatically created
76 and/or updated by ar.
77
78
79 The archive symbol table has a zero length name (that is, ar_name[0]
80 is '/'), ar_name[1]==' ', etc.). All ``words'' in this symbol table
81 have four bytes, using the machine-independent encoding shown below.
82 All machines use the encoding described here for the symbol table, even
83 if the machine's ``natural'' byte order is different.
84
85 0 1 2 3
86 0x01020304 01 02 03 04
87
88
89
90 The contents of this file are as follows:
91
92 1. The number of symbols. Length: 4 bytes.
93
94 2. The array of offsets into the archive file. Length: 4 bytes
95 * ``the number of symbols''.
96
97 3. The name string table. Length: ar_size - 4 bytes * (``the
98 number of symbols'' + 1).
99
100
101 As an example, the following symbol table defines 4 symbols. The ar‐
102 chive member at file offset 114 defines name. The archive member at
103 file offset 122 defines object. The archive member at file offset 426
104 defines function and the archive member at file offset 434 defines
105 name2.
106
107 Example Symbol Table
108 Offset +0 +1 +2 +3
109 ___________________
110 0 | 4 | 4 offset entries
111 |___________________|
112 4 | 114 | name
113 |___________________|
114 8 | 122 | object
115 |___________________|
116 12 | 426 | function
117 |___________________|
118 16 | 434 | name2
119 |___________________|
120 20 | n | a | m | e |
121 |____|____|____|____|
122 24 | \0 | o | b | j |
123 |____|____|____|____|
124 28 | e | c | t | \0 |
125 |____|____|____|____|
126 32 | f | u | n | c |
127 |____|____|____|____|
128 36 | t | i | o | n |
129 |____|____|____|____|
130 40 | \0 | n | a | m |
131 |____|____|____|____|
132 44 | e | 2 | \0 | |
133 |____|____|____|____|
134
135
136
137 The string table contains exactly as many null terminated strings as
138 there are elements in the offsets array. Each offset from the array is
139 associated with the corresponding name from the string table (in
140 order). The names in the string table are all the defined global sym‐
141 bols found in the common object files in the archive. Each offset is
142 the location of the archive header for the associated symbol.
143
144
145 If some archive member's name is more than 15 bytes long, a special ar‐
146 chive member contains a table of file names, each followed by a slash
147 and a new-line. This string table member, if present, will precede all
148 ``normal'' archive members. The special archive symbol table is not a
149 ``normal'' member, and must be first if it exists. The ar_name entry of
150 the string table's member header holds a zero length name
151 ar_name[0]=='/', followed by one trailing slash (ar_name[1]=='/'), fol‐
152 lowed by blanks (ar_name[2]==' ', etc.). Offsets into the string table
153 begin at zero. Example ar_name values for short and long file names
154 appear below.
155
156 Offset +0 +1 +2 +3 +4 +5 +6 +7 +8 +9
157 __________________________________________________
158 0 | f | i | l | e | _ | n | a | m | e | _ |
159 |____|____|____|____|____|____|____|____|____|____|
160 10 | s | a | m | p | l | e | / | \n | l | o |
161 |____|____|____|____|____|____|____|____|____|____|
162 20 | n | g | e | r | f | i | l | e | n | a |
163 |____|____|____|____|____|____|____|____|____|____|
164 30 | m | e | x | a | m | p | l | e | / | \n |
165 |____|____|____|____|____|____|____|____|____|____|
166
167
168 Member Name ar_name
169 _______________________________________________________________
170 short-name | short-name/ | Not in string table
171 | |
172 file_name_sample | /0 | Offset 0 in string table
173 | |
174 longerfilenamexample | /18 | Offset 18 in string table
175 _____________________|______________|___________________________
176
177
179 ar(1), ld(1), strip(1), a.out(4)
180
182 The strip utility will remove all archive symbol entries from the
183 header. The archive symbol entries must be restored with the -ts
184 options of the ar command before the archive can be used with the link
185 editor ld.
186
187
188
189SunOS 5.11 1 Jul 1998 ar.h(3HEAD)