grumpycoders / pcsx-redux

The PCSX-Redux project is a collection of tools, research, hardware design, and libraries aiming at development and reverse engineering on the PlayStation 1. The core product itself, PCSX-Redux, is yet another fork of the Playstation emulator, PCSX.
https://pcsx-redux.consoledev.net
GNU General Public License v2.0
663 stars 108 forks source link

psyq-obj-parser: fix HI16 relocations with large addends #1653

Closed boricj closed 6 months ago

boricj commented 6 months ago

There's a HI16/LO16 relocation pair with a large addend (>32767) inside the KanjiFntOpen() function within LIBGPU.LIB that isn't converted correctly by psyq-obj-parser, due to a bad serialization of the addend in the converted ELF object file.

Relocation with a large addend:

$ psyq-obj-parser KPRINTF.OBJ -o kprintf.o
    :: Generating relocation     HI16              .text::000001b8  .bss__base + 43024
      :: Skipped for this pass
    :: Generating relocation     LO16              .text::000001bc  .bss__base + 43024
      :: Skipped for this pass

Before fix:

$ mipsel-linux-gnu-objdump -dr kprintf.o
 1b8:   3c110100        lui     s1,0x100
                        1b8: R_MIPS_HI16        .bss
 1bc:   2631a810        addiu   s1,s1,-22512
                        1bc: R_MIPS_LO16        .bss

After fix:

$ mipsel-linux-gnu-objdump -dr kprintf.o
 1b8:   3c110001        lui     s1,0x1
                        1b8: R_MIPS_HI16        .bss
 1bc:   2631a810        addiu   s1,s1,-22512
                        1bc: R_MIPS_LO16        .bss
nicolasnoble commented 6 months ago

Sorry, only seeing it now, isn't the same as https://github.com/grumpycoders/pcsx-redux/pull/1557 ? I'll have a thorough look. I am behind on my fixes and stuff I need to do, sorry.

nicolasnoble commented 6 months ago

Hah, it is NOT the same fix at all. Great, I have two bugs around hi16. Thanks!