Skip to content

Commit 4fc507f

Browse files
committed
GT-3349 Corrected ELF relocation fixups for R_MIPS_REL32,
R_X86_64_RELATIVE and R_X86_64_RELATIVE64
1 parent 23fe661 commit 4fc507f

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

Ghidra/Processors/MIPS/src/main/java/ghidra/app/util/bin/format/elf/relocation/MIPS_ElfRelocationHandler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,9 @@ else if (MIPS_ElfExtension.MIPS_GP_GNU_LOCAL_SYMBOL_NAME.equals(symbolName)) {
402402
break;
403403

404404
case MIPS_ElfRelocationConstants.R_MIPS_REL32:
405-
// TODO: some guess-work was used here
405+
// TODO: unsure if reloc valid for symbolIndex != 0
406406
if (symbolIndex == 0) {
407-
// TODO: may need to use relocation section load address if applicable
408-
symbolValue = program.getImageBase().getOffset();
407+
symbolValue = mipsRelocationContext.getImageBaseWordAdjustmentOffset();
409408
}
410409
value = (int) symbolValue;
411410
value += mipsRelocationContext.extractAddend() ? oldValue : addend;

Ghidra/Processors/x86/src/main/java/ghidra/app/util/bin/format/elf/relocation/X86_64_ElfRelocationHandler.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public void relocate(ElfRelocationContext elfRelocationContext, ElfRelocation re
182182
value = symbolValue + dotgot + addend - offset;
183183
memory.setInt(relocationAddress, (int) value);
184184
break;
185-
185+
186186
case X86_64_ElfRelocationConstants.R_X86_64_RELATIVE:
187187
// word64 for LP64 and specifies word32 for ILP32,
188188
// we assume LP64 only. We probably need a hybrid
@@ -191,14 +191,13 @@ public void relocate(ElfRelocationContext elfRelocationContext, ElfRelocation re
191191
// dl_machine.h
192192
// value = (Elf64_64Addr) map->l_addr + reloc->r_addend
193193
appliedSymbol = false; // symbol not used, symbolIndex of 0 expected
194-
long base = program.getImageBase().getAddressableWordOffset();
194+
long imageBaseAdjustment = elfRelocationContext.getImageBaseWordAdjustmentOffset();
195195
if (elf.isPreLinked()) {
196196
// adjust prelinked value that is already in memory
197-
value = memory.getLong(relocationAddress) +
198-
elfRelocationContext.getImageBaseWordAdjustmentOffset();
197+
value = memory.getLong(relocationAddress) + imageBaseAdjustment;
199198
}
200199
else {
201-
value = base + addend;
200+
value = addend + imageBaseAdjustment;
202201
}
203202
memory.setLong(relocationAddress, value);
204203
break;

0 commit comments

Comments
 (0)