diff --git a/Ghidra/Processors/ARM/src/main/java/ghidra/app/util/bin/format/elf/relocation/ARM_ElfRelocationConstants.java b/Ghidra/Processors/ARM/src/main/java/ghidra/app/util/bin/format/elf/relocation/ARM_ElfRelocationConstants.java index 74e5505ccf..7e79867c3e 100644 --- a/Ghidra/Processors/ARM/src/main/java/ghidra/app/util/bin/format/elf/relocation/ARM_ElfRelocationConstants.java +++ b/Ghidra/Processors/ARM/src/main/java/ghidra/app/util/bin/format/elf/relocation/ARM_ElfRelocationConstants.java @@ -71,7 +71,7 @@ public class ARM_ElfRelocationConstants { /** GOT(S) + A - GOT_ORG */ public static final int R_ARM_GOT_BREL = 26; /** ((S + A) | T) - P */ - public static final int R_ARM_GOT_PLT32 = 27; + public static final int R_ARM_PLT32 = 27; /** ((S + A) | T) - P */ public static final int R_ARM_CALL = 28; /** ((S + A) | T) - P */ diff --git a/Ghidra/Processors/ARM/src/main/java/ghidra/app/util/bin/format/elf/relocation/ARM_ElfRelocationHandler.java b/Ghidra/Processors/ARM/src/main/java/ghidra/app/util/bin/format/elf/relocation/ARM_ElfRelocationHandler.java index d52541f83a..9089b9a626 100644 --- a/Ghidra/Processors/ARM/src/main/java/ghidra/app/util/bin/format/elf/relocation/ARM_ElfRelocationHandler.java +++ b/Ghidra/Processors/ARM/src/main/java/ghidra/app/util/bin/format/elf/relocation/ARM_ElfRelocationHandler.java @@ -84,7 +84,7 @@ public class ARM_ElfRelocationHandler extends ElfRelocationHandler { case ARM_ElfRelocationConstants.R_ARM_PC24: { // Target class: ARM Instruction int oldValue = memory.getInt(relocationAddress, instructionBigEndian); if (elfRelocationContext.extractAddend()) { - addend = (oldValue << 8 >> 6); // extract addend and sign-extend with *4 factor + addend = (oldValue << 8) >> 6; // extract addend and sign-extend with *4 factor } newValue = (int) (symbolValue + addend); newValue -= (offset + elfRelocationContext.getPcBias(false)); @@ -217,7 +217,7 @@ public class ARM_ElfRelocationHandler extends ElfRelocationHandler { case ARM_ElfRelocationConstants.R_ARM_THM_PC8: { // Target class: Thumb16 Instruction short oldValue = memory.getShort(relocationAddress, instructionBigEndian); newValue = (int) (symbolValue + addend); - newValue -= (offset + 4); // PC relative, PC will be 4 bytes past inst start + newValue -= (offset + elfRelocationContext.getPcBias(true)); newValue = newValue >> 1; short sValue = (short) ((oldValue & 0xff00) | (newValue & 0x00ff)); memory.setShort(relocationAddress, sValue, instructionBigEndian); @@ -313,8 +313,11 @@ public class ARM_ElfRelocationHandler extends ElfRelocationHandler { case ARM_ElfRelocationConstants.R_ARM_JUMP24: // Target class: ARM Instruction case ARM_ElfRelocationConstants.R_ARM_CALL: - case ARM_ElfRelocationConstants.R_ARM_GOT_PLT32: + case ARM_ElfRelocationConstants.R_ARM_PLT32: int oldValue = memory.getInt(relocationAddress, instructionBigEndian); + if (elfRelocationContext.extractAddend()) { + addend = (oldValue << 8) >> 6; // extract addend and sign-extend with *4 factor + } newValue = (int) (symbolValue + addend); newValue -= (offset + elfRelocationContext.getPcBias(false)); diff --git a/Ghidra/Processors/ARM/src/main/java/ghidra/app/util/bin/format/elf/relocation/ElfArmRelocationFixupHandler.java b/Ghidra/Processors/ARM/src/main/java/ghidra/app/util/bin/format/elf/relocation/ElfArmRelocationFixupHandler.java index f2840e3067..d7481d13f5 100644 --- a/Ghidra/Processors/ARM/src/main/java/ghidra/app/util/bin/format/elf/relocation/ElfArmRelocationFixupHandler.java +++ b/Ghidra/Processors/ARM/src/main/java/ghidra/app/util/bin/format/elf/relocation/ElfArmRelocationFixupHandler.java @@ -32,13 +32,15 @@ public class ElfArmRelocationFixupHandler extends RelocationFixupHandler { Address newImageBase) throws MemoryAccessException, CodeUnitInsertionException { switch (relocation.getType()) { +// TODO: This over simplified relocation fixup is flawed and does not properly +// handle post-import image base change for supported relocations case ARM_ElfRelocationConstants.R_ARM_NONE: case ARM_ElfRelocationConstants.R_ARM_ABS32: case ARM_ElfRelocationConstants.R_ARM_REL32: case ARM_ElfRelocationConstants.R_ARM_GLOB_DAT: // case ARM_ElfRelocationConstants.R_ARM_JUMP_SLOT: case ARM_ElfRelocationConstants.R_ARM_RELATIVE: - case ARM_ElfRelocationConstants.R_ARM_GOT_PLT32: + case ARM_ElfRelocationConstants.R_ARM_PLT32: case ARM_ElfRelocationConstants.R_ARM_CALL: case ARM_ElfRelocationConstants.R_ARM_JUMP24: case ARM_ElfRelocationConstants.R_ARM_THM_JUMP24: