pret / pokediamond

Decompilation of Pokémon Diamond/Pearl
419 stars 77 forks source link

Fix asmproc: Fix broken branches and relocations #340

Closed abaresk closed 3 years ago

abaresk commented 3 years ago

There were two issues that broke branch instructions and relocations in the linked binary:

  1. The symbol table entry for the nonmatching function name was not updated after injection. Instead, it pointed to the first function in the file. As a result, calls to the nonmatching function actually called the first file function. This fix updates the symbol table entry to point to the correct .text section in the final object file.
  2. Most .rela.text sections were omitted from the final object file. The original algorithm did not inject relocations into any parts of a .text section that were overridden. This produces a bug for mwcc objects because the implementation assumed that object files would only contain a single .text section (mwcc produces multiple). This check has been disabled.

With this change, GLOBAL_ASM can be used on nonmatching functions and produce a matching binary.