riidefi / mkw

Decompilation of Mario Kart Wii
295 stars 30 forks source link

Inline asm linter #159

Open riptl opened 2 years ago

riptl commented 2 years ago

Background

The task of "splitting" consists of reconstructing translation units using C/C++ source files using inline assembly. The resulting object files should be relocatable.

To facilitate splitting, we use a set of scripts that auto-generate missing C files based on the global symbol table (symbols.txt).

Problem

The splitting script's outputs is dumb and emits direct data references to absolute addresses. This results in non-relocatable code that will crash when recompiling in a context that differs from the original game.

Examples of violating patterns.

Wrong:

  lis r3, 0x8021;
  addi r3, r3, -812;

Correct:

  lis r3, _my_symbol@ha;
  addi r3, r3, _my_symbol@l;

Wrong:

lwz r3, -0x5e70(r13);

Correct:

lwz r3, _my_smol_symbol;

Wrong:

lfs f0, -0x72c4(r2);

Correct:

lfs f0, 1.0f;

Work to be done

Create a script that scans through source files with violating patterns.

A bunch of regex is likely more than enough.

riidefi commented 2 years ago

We'll also need to be careful about unused data generated from coming from stripped functions. OGWS has some examples.

riptl commented 2 years ago

Unused data will be caught by the data symbol differ