# Library File Format

For library files, the first part of each chunk's name is "LIB_"; for object libraries, the names of the additional two chunks begin with "OFL_".

Each piece of a library file is stored in a separate, identifiable chunk, named as follows:

    --------------------------------------------------------
    Chunk        |Chunk Name
    --------------------------------------------------------
    Directory    |LIB_DIRY
    --------------------------------------------------------
    Time stamp   |LIB_TIME
    --------------------------------------------------------
    Version      |LIB_VSRN
    --------------------------------------------------------
    Data         |LIB_DATA
    --------------------------------------------------------
    Symbol table |OFL_SYMT (object code libraries only)
    --------------------------------------------------------
    Time stamp   |OFL_TIME(object code libraries only)
    --------------------------------------------------------

There may be many LIB_DATA chunks in a library, one for each library member. In all chunks, word values are stored with the same byte order as the target system; strings are stored in ascending address order, which is independent of target byte order.

## LIB_DIRY

The LIB_DIRY chunk contains a directory of the modules in the library, each of which is stored in a LIB_DATA chunk. The directory size is fixed when the library is created. The directory consists of a sequence of variable length entries, each an integral number of words long. The number of directory entries is determined by the size of the LIB_DIRY chunk. Pictorially:

    -----------------------------------------------------
    ChunkIndex           |
    -----------------------------------------------------
    EntryLength          |the size of this LIB_DIRY chunk
                         |(an integral number of words)
    -----------------------------------------------------
    DataLength           |the size of the Data (an
                         |integral number of words)
    -----------------------------------------------------
    Data                 |
    -----------------------------------------------------

ChunkIndex is a word containing the 0-origin index within the chunk file header of the corresponding LIB_DATA chunk. Conventionally, the first 3 chunks of an OFL file are LIB_DIRY, LIB_TIME and LIB_VSRN, so ChunkIndex is at least 3. A ChunkIndex of 0 means the directory entry is unused.

The corresponding LIB_DATA chunk entry gives the offset and size of the library module in the library file.

EntryLength is a word containing the number of bytes in this LIB_DIRY entry, always a multiple of 4.

DataLength is a word containing the number of bytes used in the data section of this LIB_DIRY entry, also a multiple of 4.

The Data section consists of, in order:

- a 0-terminated string (the name of the library member);
- any other information relevant to the library module (often empty);
- a 2-word, word-aligned time stamp.

Strings should contain only ISO-8859 non-control characters (codes [0-31], 127 and 128+[0-31] are excluded).

The string field is the name used to identify this library module. Typically it is the name of the file from which the library member was created.

The format of the time stamp is described in Time stamps. Its value is an encoded version of the last-modified time of the file from which the library member was created.

To ensure maximum robustness with respect to earlier, now obsolete, versions of the ARM object library format:

- Applications which create libraries or library members should ensure that the LIB_DIRY entries they create contain valid time stamps.

- Applications which read LIB_DIRY entries should not rely on any data beyond the end of the name string being present, unless the difference between the DataLength field and the name-string length allows for it. Even then, the contents of a time stamp should be treated cautiously and not assumed to be sensible.

Applications which write LIB_DIRY or OFL_SYMT entries should ensure that padding is done with NUL (0) bytes; applications which read LIB_DIRY or OFL_SYMT entries should make no assumptions about the values of padding bytes beyond the first, string-terminating NUL byte.

## Time stamps

A library time stamp is a pair of words encoding the following:

- a 6-byte count of centi-seconds since the start of the 20th century;
- a 2-byte count of microseconds since the last centi-second (usually 0).

The first word stores the most significant 4 bytes of the 6-byte count; the least significant 2 bytes of the count are in the most significant half of the second word.

The least significant half of the second word contains the microsecond count and is usually 0.

Time stamp words are stored in target system byte order: they must have the same endianness as the containing chunk file.

## LIB_TIME

The LIB_TIME chunk contains a 2-word time stamp recording when the library was last modified. It is, hence, 8 bytes long.

## LIB_VSRN

The version chunk contains a single word whose value is 1.

## LIB_DATA

A LIB_DATA chunk contains one of the library members indexed by the LIB_DIRY chunk. The endian-ness or byte order of this data is, by assumption, the same as the byte order of the containing library/chunk file.

No other interpretation is placed on the contents of a member by the library management tools. A member could itself be a file in chunk file format or even another library.