riidefi / mkw

Decompilation of Mario Kart Wii
311 stars 32 forks source link

No-link object file validation #42

Open riidefi opened 3 years ago

riidefi commented 3 years ago

Currently, we need to link an entire .dol/.rel executable to verify a function matches. Introducing a .o validator will enable faster iteration for both humans and computers ;)

wait-wtf commented 3 years ago

Sounds easy enough :) Will take a look at this with the help of wii-symbols/match-symbols.py, which can match relocatable/object code to binary blobs: https://github.com/terorie/wii-symbols/blob/master/scripts/match_symbols.py (the person who wrote this must have a massive brain and amazing code style :P)

Logic will be as follows:

Inputs: obj_syms: Set<Symbol>, bin_syms: Set<Symbol>
Output: bool
Algorithm:

known_syms = intersect(obj_syms, bin_syms)
for (obj_sym, bin_sym) in known_syms:
    if not obj_sym.match(bin_sym):
        return false
return true
riptl commented 3 years ago

We decided to use an explicit approach instead. Rather than trying to derive which symbols get stripped through symbols.txt, we'll embed information into the object file. We do this like with the BINARY_BLOB macro by writing debug information into a custom section that gets stripped from the DOL/REL.

Like this:

DEAD_STRIPPED(my_function);
void my_function() { ... }