Introduction
The header starts at offset 0 and every number is a big-endian 32-bit value except the four one-byte section indexes. Later versions add fields at the end, so the
header is 0x40 bytes in version 1, 0x48 in version 2 and 0x4C in version 3. The layout follows the Mario Kart Wii wiki
“REL (File Format)”, read through a page summary (our words). The page gives the three end offsets and the “version 2 and later” and “version 3 only” notes; the
mapping of end offset to version is read from those notes.
Fields
| Offset | Size | Field | Meaning |
|---|---|---|---|
0x00 | 4 | Module id | Must be nonzero and unique among a game’s modules. 0 names the main program in the import table. |
0x04 | 4 | Next | Filled in by the loader at run time (the link of the module list). |
0x08 | 4 | Previous | Filled in by the loader at run time. |
0x0C | 4 | Section count | The number of entries in the section table. |
0x10 | 4 | Section table offset | Where the section table is. |
0x14 | 4 | Name offset | The offset of the module’s path string, relative to a separate name file (the .str file), not to this one. |
0x18 | 4 | Name size | The length of that path. |
0x1C | 4 | Version | The format version: 1, 2 or 3. |
0x20 | 4 | BSS size | The size of the zero-filled area. |
0x24 | 4 | Relocation offset | Where the first relocation list is; the same as the first import entry’s offset. |
0x28 | 4 | Import table offset | Where the import table is. |
0x2C | 4 | Import table size | Its size in bytes (8 per entry). |
0x30 | 1 | Prolog section | The index of the section holding _prolog; 0 means skip. |
0x31 | 1 | Epilog section | The section holding _epilog; 0 means skip. |
0x32 | 1 | Unresolved section | The section holding _unresolved; 0 means skip. |
0x33 | 1 | BSS section | Filled in at run time. |
0x34 | 4 | Prolog offset | The offset of _prolog inside its section. |
0x38 | 4 | Epilog offset | The offset of _epilog inside its section. |
0x3C | 4 | Unresolved offset | The offset of _unresolved inside its section. |
0x40 | 4 | Alignment | Version 2 and later: the alignment of the load address. The page says “as a power of 2”. |
0x44 | 4 | BSS alignment | Version 2 and later: the alignment of the BSS. |
0x48 | 4 | Fixed size | Version 3 only: space usable for other purposes when the module is linked with OSLinkFixed. |
The loader calls the three entry points by name: _prolog when the module is linked, _epilog when it is unlinked, and
_unresolved when the module calls a function that was not resolved.
What the viewer checks
These rules are the viewer’s own test for “is this a REL”. A file named .rel that breaks one is shown as not a valid REL.
- The version is 1, 2 or 3, and the file holds that version’s header.
- The module id is not 0, and the section count is from 1 to 255.
- The section table lies after the header, inside the file; its first entry is empty (the page says so); every section with an offset lies inside the file; no two overlap.
- The import table size is a multiple of 8 and the table is inside the file; the relocation offset is inside the file.
- The prolog, epilog and unresolved sections, when not 0, exist, are code, and their offsets are inside them.
- In version 2 and later the alignments are 0 or a power of two.
- Every import points inside the file, and its relocation list ends with the end marker (type 203) before the end of the file.
Not checked: that the next and previous links are zero (they are run-time fields, and a file saved from memory may hold values).
Not described
Known, not yet covered
- Reference: whether the alignment is a byte count or an exponent (the page says “as a power of 2”; the viewer accepts a power-of-two byte count and 0), the name file’s layout, and how
OSLinkFixeduses the fixed size. - Viewer: only built modules were checked.
Unknown
- Whether any module has a section count above 255 or a version other than 1 to 3: none is accepted.
Links
Reference
- Mario Kart Wii wiki: REL (File Format) – the header fields and versions
- WiiBrew: REL – a stub that names the format and the loading function