GP-2350 Corrected processing of ELF REL type relocations for

R_ARM_JUMP24, R_ARM_CALL and R_ARM_PLT32
This commit is contained in:
ghidra1 2022-07-20 21:40:37 -04:00
parent 7c004c1fae
commit 51255066a4
3 changed files with 10 additions and 5 deletions

View File

@ -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 */

View File

@ -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));

View File

@ -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: