question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MIPS64: relocation issue

See original GitHub issue

Describe the bug MIPS64 relocation handler discards the old symbol value resulting in symbols having the EA as their value. This binary is built to load at 0x0, so basically all of my .rel.dyn relocations are NULL pointers.

For example readelf shows:

000000667788  000000001203 R_MIPS_REL32     
                    Type2: R_MIPS_64        
                    Type3: R_MIPS_NONE   

with file data of: 000000667788: 00 00 00 00 XX YY ZZ WW and ghidra loads: 000000667788: 00 00 00 00 00 00 00 00

R_MIPS_REL32 handling has saveValue true and symbolIndex 0x0, resulting in symbolValue 0x0 Fall through in R_MIPS_32 extractAddend() false

R_MIPS_64 handling has saveValue false, addend 0x0, and symbolValue 0x0 resulting in overwriting the previous value with 0x0

Environment (please complete the following information):

  • OS: 20.04
  • Java Version: 17.0.4
  • Ghidra Version: 10.2-DEV b88cf85d5cef4e766e6093223b6320ee5ae7a113
  • Ghidra Origin: eclipse

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ghidra1commented, Oct 6, 2022

I believe the intent of this relocation for symbolIndex==0 is:

R_MIPS_REL32
   value = imageBaseAdjustment + addend
   ***Assuming this is a REL type relocation, value should equal the original 
       bytes (32-bits) from the relocation address
   This value should be saved for use below
R_MIPS_64
   addend = value from above
   newValue = 0 + addend
   store value as 64-bit long

***Could the issue be caused by the R_MIPS_REL32 using the upper 32-bits instead of the lower 32-bits of the affected 64-bit location? It is using a 32-bit oldValue read from the relocation address. Since this code is shared for both 32-bit and 64-bit MIPS that oldValue read may be flawed for 64-bit MIPS and should have been a 64-bit read.

0reactions
ryanmkurtzcommented, Oct 27, 2022

Closed by 8c1fd57b72c84d99e8dca998ff0d1c22161bc4c4

Read more comments on GitHub >

github_iconTop Results From Across the Web

D80390 [mips] Support 64-bit relative relocations - LLVM
In case of 64-bit PC-relative relocation we need the following chain: R_MIPS_PC32 | R_MIPS_64. The first relocation calculates an offset, but ...
Read more >
How does a linker relocate branch instructions in MIPS?
1 Answer 1 ... My guess is that this linker does not handle branch instructions ( bne or beq ) to external labels....
Read more >
SYSTEM V APPLICATION BINARY INTERFACE
The MIPS ISA provides instruction encodings to move, load, and store values for up to four co-processors. Only co-processor 1 is specified in...
Read more >
MIPS relocatable kernel & KASLR - LWN.net
This series adds the ability for the MIPS kernel to relocate itself at runtime, optionally to an address determined at random each boot....
Read more >
[mips] Emit all three relocation operations for each relocation entry ...
GitLab Community Edition. ... [mips] Emit all three relocation operations for each relocation entry on Mips64 ... New Mips64 ABIs should provide enough....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found