Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-5827 Corrected ELF MIPS 64-bit relocation processing error

ghidra1130b365e7c5c
diff --git a/Ghidra/Processors/MIPS/src/main/java/ghidra/app/util/bin/format/elf/relocation/MIPS_ElfRelocationContext.java b/Ghidra/Processors/MIPS/src/main/java/ghidra/app/util/bin/format/elf/relocation/MIPS_ElfRelocationContext.java
index 0fd09960ad..b0250ad0c2 100644
--- a/Ghidra/Processors/MIPS/src/main/java/ghidra/app/util/bin/format/elf/relocation/MIPS_ElfRelocationContext.java
+++ b/Ghidra/Processors/MIPS/src/main/java/ghidra/app/util/bin/format/elf/relocation/MIPS_ElfRelocationContext.java
@@ -72,8 +72,6 @@ class MIPS_ElfRelocationContext extends ElfRelocationContext<MIPS_ElfRelocationH
int typeId = relocation.getType();
int symbolIndex = relocation.getSymbolIndex();
- saveValueForNextReloc = nextRelocationHasSameOffset(relocation);
-
RelocationResult lastResult = RelocationResult.FAILURE;
if (getElfHeader().is64Bit()) {
@@ -99,7 +97,10 @@ class MIPS_ElfRelocationContext extends ElfRelocationContext<MIPS_ElfRelocationH
typeId >>= 8;
int nextRelocType = (n < 2) ? (typeId & 0xff) : 0;
if (nextRelocType == MIPS_ElfRelocationType.R_MIPS_NONE.typeId) {
- saveValueForNextReloc = false;
+ saveValueForNextReloc = nextRelocationHasSameOffset(relocation);
+ }
+ else {
+ saveValueForNextReloc = true;
}
RelocationResult result =
@@ -117,6 +118,8 @@ class MIPS_ElfRelocationContext extends ElfRelocationContext<MIPS_ElfRelocationH
return lastResult;
}
+ // 32-bit ELF
+ saveValueForNextReloc = nextRelocationHasSameOffset(relocation);
return doRelocate(relocation, relocationAddress, typeId, symbolIndex);
}
diff --git a/Ghidra/Processors/MIPS/src/main/java/ghidra/app/util/bin/format/elf/relocation/MIPS_ElfRelocationHandler.java b/Ghidra/Processors/MIPS/src/main/java/ghidra/app/util/bin/format/elf/relocation/MIPS_ElfRelocationHandler.java
index a307822410..1701c8fe0e 100644
--- a/Ghidra/Processors/MIPS/src/main/java/ghidra/app/util/bin/format/elf/relocation/MIPS_ElfRelocationHandler.java
+++ b/Ghidra/Processors/MIPS/src/main/java/ghidra/app/util/bin/format/elf/relocation/MIPS_ElfRelocationHandler.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -358,8 +358,7 @@ public class MIPS_ElfRelocationHandler
value = symbolValue;
if (elfRelocationContext.extractAddend()) {
// extract addend based upon pointer size
- addend = elf.is64Bit() ? (int) memory.getLong(relocationAddress)
- : memory.getInt(relocationAddress);
+ addend = memory.getInt(relocationAddress);
}
newValue = value + addend;