Library module file

This page describes the library module file format version 0.4

A library module file has informations about interfaces, implementations and functions, besides data and code relocation data.

The file is made of sections: header, strings, used functions, used functions relocation, read only data relocation, data relocation, code relocation and implemented interfaces.

Header

File's header resides at the beginning and has informations about size and position of each section, besides global module information. The format is:

SizeDescription
16 bytesFile's MD5 fingerprint/message-digest
4 bytesLM04 - ID (Library Module 0.4)
4 bytesModule code start
4 bytesModule code size
4 bytesModule read only data start
4 bytesModule read only data size
4 bytesModule data start
4 bytesModule data size
4 bytesModule uninitialized data size
4 bytesUsed functions section start
4 bytesUsed functions section size
4 bytesUsed functions relocation section start
4 bytesUsed functions relocation section size
4 bytesImplemented interfaces section start
4 bytesImplemented interfaces section size
4 bytesRead only data relocation section start
4 bytesRead only data relocation section size
4 bytesData relocation section start
4 bytesData relocation section size
4 bytesCode relocation section start
4 bytesCode relocation section size
4 bytesFile's strings section start
2 bytesFile's strings section size
2 bytesModule version
2 bytesModule properties
2 bytesComment index
4 bytesStart function start
4 bytesShutdown function start

If a section has 0 size it doesn't exist. So, if data section has 0 size, module has no data.

The MD5 member is used to validate the rest of the file.

Uninitialized data have 0 as initial value.

Module data area is composed in the following way: initialized data + uninitialized data.

The version member has the following meaning: the first byte (version >> 8) is the first version, next 4 bits (version & 0xf0) are another version and the last 4 bits (version & 0x0f) are the last version. For example: 0.1.0 or 20.15.10

The property member has no meaning yet.

If there is no start or shutdown function start must be 0xffffffff.

File's strings

This section holds all used strings. Strings end with a 0 byte. Is the same type of string used in C/C++.

The first string must be the empty string, that is, the first section's byte is 0.

Strings in this section must be unique.

Used functions

This section holds information about functions used by the module.

Each entry has this format:

SizeDescription
2 bytesInterface name index
2 bytesImplementation name index
3 bytesFunction number
1 byteFunction properties

The interface name and the implementation name can have at most 32 chars each including the terminating zero.

Properties can be:

Used functions relocation

This section holds information about location and type of relocation to apply to call interfaces functions.

This section must be sorted by the offset in crescent order.

Each entry has this format:

SizeDescription
4 bytesOffset inside code where the function is called
1 byteRelocation properties
3 bytesUsed function index

Properties can be:

SizePositionDescription
1 bitbit 01 - absolute relocation; 0 - relative relocation

In absolute relocation used function start address is put in the offset.

In relative relocation used function start address is subtracted of the offset. It's a call relative to the current address.

Implemented interfaces

This section holds all module's implemented interfaces.

The format is as follow: interface information, implementations informations, another interface information, more implementations, and so for.

It has the following format:

SizeDescription
2 bytesInterface name index
2 bytesNumber of functions in the interface
2 bytesNumber of implementations in the interface
4 bytesImplementation's functions start (relative to the beginning of the file)
2 bytesImplementation name index
......(more implementations from this interface)
......(more interfaces)

The interface name and the implementation name can have at most 32 chars each including the terminating zero.

Section with an implementation's functions has this format:

SizeDescription
4 bytesCode start (relative to the beginning of the module code)
2 bytesProperties
......(more functions)

The properties member has this format:

SizePositionDescription
1 bitbit 01 - function not implemented

Read only data relocation

This section has this format:

SizeDescription
4 bytesRead only data relocation block size
4 bytesData relocation block size
4 bytesCode relocation block size
as far as 4GB bytesRead only data relocation block
as far as 4GB bytesData relocation block
as far as 4GB bytesCode relocation block

Read only data relocation block has information about relocation to read only data (a variable wants the address of a variable in the read only data block).

Data relocation block has information about relocation to data (a variable wants the address of a variable in the data block).

Code relocation block has information about relocation to code (a variable wants the address of a code chunk).

Each entry in these blocks is an offset inside data block to the reference that must be changed. Each relocation is computed as follow: block start + 32 bits word in the offset to be changed.

Data relocation

This section has this format:

SizeDescription
4 bytesRead only data relocation block size
4 bytesData relocation block size
4 bytesCode relocation block size
as far as 4GB bytesRead only data relocation block
as far as 4GB bytesData relocation block
as far as 4GB bytesCode relocation block

Read only data relocation block has information about relocation to read only data (a variable wants the address of a variable in the read only data block).

Data relocation block has information about relocation to data (a variable wants the address of a variable in the data block).

Code relocation block has information about relocation to code (a variable wants the address of a code chunk).

Each entry in these blocks is an offset inside data block to the reference that must be changed. Each relocation is computed as follow: block start + 32 bits word in the offset to be changed.

Code relocation

This section has this format:

SizeDescription
4 bytesRead only data relocation block size
4 bytesData relocation block size
4 bytesCode relocation block size
as far as 4GB bytesRead only data relocation block
as far as 4GB bytesData relocation block
as far as 4GB bytesCode relocation block

Read only data relocation block has information about relocation to read only data (code wants the address of a variable in the read only data block).

Data relocation block has information about relocation to data (code wants the address of a variable in the data block).

Code relocation block has information about relocation to code (code wants the address of a code chunk).

Each entry in these blocks is an offset inside code block to the reference that must be changed. Each relocation is computed as follow: block start + 32 bits word in the offset to be changed.