REL (File Format)

From Wexos's Wiki
Revision as of 16:29, 15 July 2025 by Wexos (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

REL is a executable file format containing relocatable objects. It is similar to RSO, however, RSO files are relocated using symbol names while REL files are relocated using static memory addresses.

File Format

Header

The file starts with the following structure:

Offset Type Description
0x00 UInt32 Module ID. Must be a unique non-zero integer amongst all loaded REL files.
0x04 UInt32 Next module pointer. Always 0, filled at runtime.
0x08 UInt32 Previous module pointer. Always 0, filled at runtime.
0x0C UInt32 Number of sections stored in the file.
0x10 UInt32 Section info table offset.
0x14 UInt32 Name offset.
0x18 UInt32 Name size.
0x1C UInt32 Version number of the REL format.
0x20 UInt32 .bss size in bytes.
0x24 UInt32 Relocation table offset.
0x28 UInt32 Import table offset.
0x2C UInt32 Import table size in bytes.
0x30 Byte Prolog section index.
0x31 Byte Epilog section index.
0x32 Byte Unresolved section index.
0x33 Byte .bss section index. Always 0, filled at runtime.
0x34 UInt32 Prolog offset into the section specified above.
0x38 UInt32 Epilog offset into the section specified above.
0x3C UInt32 Unresolved offset into the section specified above.
If version ≥ 2
0x40 UInt32 REL load alignment constraint, as a power of 2.
0x44 UInt32 .bss section alignment constraint, as a power of 2.
If version ≥ 3
0x48 UInt32 Fix size. If a REL is linked with OSLinkFixed, the space after this address can be used for other purposes such as .bss.

Section Info Table

The section info table points to the data for each section. The header specifies the number of sections. Each section has the following structure:

Offset Type Description
0x00 UInt32 Section data offset, relative to the start of the file. If the offset is zero, the section is allocated and initialized at runtime (like .bss). The least significant bit specifies whether the section is executable (1) or just data (0).
0x04 UInt32 Section data size in bytes.

Relocation Table

The relocation table is used to relocate section data to a different memory address. Each relocation entry has the following structure:

Offset Type Description
0x00 UInt16 Data offset, relative to the previous relocation table entry. For the first relocation entry this is relative to the section start.
0x02 Byte Relocation type.
0x03 Byte Section index.
0x04 Byte Add end. Offset in bytes of the symbol to relocate against, relative to the start of its section. For relocations against main.dol, this is instead a virtual memory address.

Import Table

The import table specify information used for relocation. It specifies relocation data for each module. Each entry has the following structure:

Offset Type Description
0x00 UInt32 Module ID which the relocation refers to. 0 means the relocations are for main.dol.
0x04 UInt32 Relocation table offset, relative to the start of the file.

Tools

The following tools can handle REL files: