REL (File Format)

The REL format is the file format for relocatable modules for GameCube games. This is essentially the GameCube's equivalent of a DLL file, allowing for code modules to be dynamically linked at runtime and unlinked when not in use to save memory.

Format
The REL format is split up into a number of different sections, just like an ELF file. Sections that were generated by the compiler but aren't used by the game (such as the sections for relocations or symbols) are nulled out and listed with an offset and size of 0.

Section Info Table
This data is pointed to by the Section Info Offset value in the header. It specifies the layout of the file. The structure loops once for each section in the file, as specified by the Section Count in the header. Any compiler-generated sections that are unused (such as the symbol table or the section name table) are nulled out and listed with a size/offset of 0. The first section is always null. The BSS section is listed with a valid size but an offset of 0 (as the BSS section is not included in the file, but instead has space allocated at runtime).

Import Table
This data is pointed to by the Import Table Offset value in the header. You can get the number of imports by dividing the Import Table Size value by 0x8 (the size of one import entry). An import is basically an offset into the relocation table, pointing to the relocations used for a specific module.

Relocation Table
This data is pointed to by the Relocation Table Offset value in the header. Since modules have space allocated at runtime and can therefore do not have a fixed memory address, the relocations table is needed to ensure all references to symbols within the REL have the correct address. When the module is linked in, the game uses the relocation table to iterate over all instructions and data values referring to REL symbols, and patch them to point to the correct address.

There are multiple distinct groups of relocations, with each one being pointed to by an entry in the import table. To read the relocations for a given module, you need to iterate over all relocation entries until you hit an R_DOLPHIN_END directive. Each relocation is 0x8 bytes.

These are the possible relocation types. The "used" column indicates whether this relocation type is used by any of the modules in any of Retro's games.