7 Archive (Library) File Format


The COFF archive format provides a standard mechanism for storing collections of object files. These collections are frequently referred to as "libraries" in programming documentation.

The first eight bytes of an archive consist of the file signature. The rest of the archive consists of a series of archive members, as follows:

  1. The first and second members are "linker members." Each of these members has its own format as described in Section 8.3. Typically, a linker places information into these archive members. The linker members contain the directory of the archive.

  2. The third member is the longnames member. This member consists of a series of null-terminated ASCII strings, in which each string is the name of another archive member.

  3. The rest of the archive consists of standard (object-file) members. Each of these members contains the contents of one object file in its entirety.

An archive member header precedes each member. The following illustration shows the general structure of an archive:

Figure A-4. Archive File Structure

graphics/ap01fig04.gif

7.1 Archive File Signature

The archive file signature identifies the file type. Any utility (for example, a linker) expecting an archive file as input can check the file type by reading this signature. The signature consists of the following ASCII characters, in which each character below is represented literally, except for the newline (\n) character:

 
 !<arch>\n 

7.2 Archive Member Headers

Each member (linker, longnames, or object-file member) is preceded by a header. An archive member header has the following format, in which each field is an ASCII text string that is left-justified and padded with spaces to the end of the field. There is no terminating null character in any of these fields.

Each member header starts on the first even address after the end of the previous archive member.

Offset

Size

Field

Description

0

16

Name

Name of archive member, with a slash (/) appended to terminate the name. If the first character is a slash, the name has a special interpretation, as described below.

16

12

Date

Date and time the archive member was created: ASCII decimal representation of the number of seconds since 1/1/1970 UCT.

28

6

User ID

ASCII decimal representation of the user ID.

34

6

Group ID

ASCII group representation of the group ID.

40

8

Mode

ASCII octal representation of the member's file mode.

48

10

Size

ASCII decimal representation of the total size of the archive member, not including the size of the header.

58

2

End of Header

The two bytes in the C string "'\n".

The Name field has one of the formats shown in the following table. As mentioned above, each of these strings is left justified and padded with trailing spaces within a field of 16 bytes:

Contents of Name Field

Description

name/

The field gives the name of the archive member directly.

/

The archive member is one of the two linker members. Both of the linker members have this name.

//

The archive member is the longname member, which consists of a series of null-terminated ASCII strings. The longnames member is the third archive member, and must always be present even if the contents are empty.

/n

The name of the archive member is located at offset n within the longnames member. The number n is the decimal representation of the offset. For example: "\26" indicates that the name of the archive member is located 26 bytes beyond the beginning of longnames member contents.

7.3 First Linker Member

The name of the first linker member is "\". The first linker member, included for backward compatibility, is not used by current linkers but its format must be correct. This linker member provides a directory of symbol names, as does the second linker member. For each symbol, the information indicates where to find the archive member that contains the symbol.

The first linker member has the following format. This information appears after the header:

Offset

Size

Field

Description

0

4

Number of Symbols

Unsigned long containing the number of symbols indexed. This number is stored in big-endian format. Each object-file member typically defines one or more external symbols.

4

4 * n

Offsets

Array of file offsets to archive member headers, in which n is equal to Number of Symbols. Each number in the array is an unsigned long stored in big-endian format. For each symbol named in the String Table, the corresponding element in the Offsets array gives the location of the archive member that contains the symbol.

*

*

String Table

Series of null-terminated strings that name all the symbols in the directory. Each string begins immediately after the null character in the previous string. The number of strings must be equal to the value of the Number of Symbols fields.

The elements in the Offsets array must be arranged in ascending order. This fact implies that the symbols listed in the String Table must be arranged according to the order of archive members. For example, all the symbols in the first object-file member would have to be listed before the symbols in the second object file.

7.4 Second Linker Member

The second linker member has the name "\" as does the first linker member. Although both the linker members provide a directory of symbols and archive members that contain them, the second linker member is used in preference to the first by all current linkers. The second linker member includes symbol names in lexical order, which enables faster searching by name.

The second linker member has the following format. This information appears after the header:

Offset

Size

Field

Description

0

4

Number of Members

Unsigned long containing the number of archive members.

4

4 * m

Offsets

Array of file offsets to archive member headers, arranged in ascending order. Each offset is an unsigned long. The number m is equal to the value of the Number of Members field.

*

4

Number of Symbols

Unsigned long containing the number of symbols indexed. Each object-file member typically defines one or more external symbols.

*

2 * n

Indices

Array of 1-based indices (unsigned short) which map symbol names to archive member offsets. The number n is equal to Number of Symbols. For each symbol named in the String Table, the corresponding element in the Indices array gives an index into the Offsets array. The Offsets array, in turn, gives the location of the archive member that contains the symbol.

*

*

String Table

Series of null-terminated strings that name all the symbols in the directory. Each string begins immediately after the null byte in the previous string. The number of strings must be equal to the value of the Number of Symbols fields. This table lists all the symbol names in ascending lexical order.

7.5 Longnames Member

The name of the longnames member is "\\". The longnames member is a series of strings of archive member names. A name appears here only when there is insufficient room in the Name field (16 bytes). The longnames member can be empty, though its header must appear.

The strings are null-terminated. Each string begins immediately after the null byte in the previous string.



The Common Language Infrastructure Annotated Standard (Microsoft. NET Development Series)
The Common Language Infrastructure Annotated Standard (Microsoft. NET Development Series)
ISBN: N/A
EAN: N/A
Year: 2002
Pages: 121

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net