mkw icon indicating copy to clipboard operation
mkw copied to clipboard

No-link object file validation

Open riidefi opened this issue 3 years ago • 2 comments

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 ;)

riidefi avatar Jul 22 '21 09:07 riidefi

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

wait-wtf avatar Jul 24 '21 13:07 wait-wtf

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() { ... }

riptl avatar Jul 31 '21 10:07 riptl