Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GPREL16 references emitted by PS2 GCC #176

Open
1superchip opened this issue Nov 16, 2024 · 0 comments
Open

Fix GPREL16 references emitted by PS2 GCC #176

1superchip opened this issue Nov 16, 2024 · 0 comments

Comments

@1superchip
Copy link
Collaborator

PS2 GCC emits R_MIPS_GPREL16 relocations for data that can be referenced by gp. The compiler emits an addend to all instructions that have the R_MIPS_GPREL16 relocation. Replacing the relocation of .sbss+0x4000-addend to the symbol that it points to would improve the diff for PS2 GCC objects.

image
image

objdump output of the object:

00000008 <CBuffGetStr__Fi>:
   8:   04800005        bltz    a0,20 <CBuffGetStr__Fi+0x18>
   c:   00000000        nop
  10:   8f82c000        lw      v0,-16384(gp)
                        10: R_MIPS_GPREL16      .sbss+0x4000
  14:   0082102a        slt     v0,a0,v0
  18:   54400003        bnezl   v0,28 <CBuffGetStr__Fi+0x20>
  1c:   8f82c004        lw      v0,-16380(gp)
                        1c: R_MIPS_GPREL16      .sbss+0x4000
  20:   03e00008        jr      ra
  24:   0000102d        move    v0,zero
  28:   8f83c00c        lw      v1,-16372(gp)
                        28: R_MIPS_GPREL16      .sbss+0x4000
  2c:   00441018        mult    v0,v0,a0
  30:   03e00008        jr      ra
  34:   00621021        addu    v0,v1,v0

Relocations in the object:

RELOCATION RECORDS FOR [.text]:
OFFSET   TYPE              VALUE
00000010 R_MIPS_GPREL16    .sbss+0x00004000
0000001c R_MIPS_GPREL16    .sbss+0x00004000
00000028 R_MIPS_GPREL16    .sbss+0x00004000

Relevant symbols in the object:

00000000 l       .sbss  00000000 CBuffNum
00000004 l       .sbss  00000000 CBuffMaxLen
0000000c l       .sbss  00000000 CBuffStr
00000008 l       .sbss  00000000 CBuffMaxNum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant