GP-164 Added ELF ARM relocation R_ARM_PREL31 and corrected issue with

R_ARM_ABS32 relocation.
Fixes #2261, Fixes #2276
This commit is contained in:
ghidra1 2020-09-16 12:48:40 -04:00
parent da92b68bcd
commit f3b4e6de16

View file

@ -83,8 +83,10 @@ public class ARM_ElfRelocationHandler extends ElfRelocationHandler {
break;
}
case ARM_ElfRelocationConstants.R_ARM_ABS32: { // Target class: Data
int oldValue = memory.getInt(relocationAddress);
newValue = (int) (symbolValue + addend + oldValue);
if (elfRelocationContext.extractAddend()) {
addend = memory.getInt(relocationAddress);
}
newValue = (int) (symbolValue + addend);
if (isThumb) {
newValue |= 1;
}
@ -92,8 +94,10 @@ public class ARM_ElfRelocationHandler extends ElfRelocationHandler {
break;
}
case ARM_ElfRelocationConstants.R_ARM_REL32: { // Target class: Data
int oldValue = memory.getInt(relocationAddress);
newValue = (int) (symbolValue + addend + oldValue);
if (elfRelocationContext.extractAddend()) {
addend = memory.getInt(relocationAddress);
}
newValue = (int) (symbolValue + addend);
newValue -= offset; // PC relative
if (isThumb) {
newValue |= 1;
@ -101,6 +105,20 @@ public class ARM_ElfRelocationHandler extends ElfRelocationHandler {
memory.setInt(relocationAddress, newValue);
break;
}
case ARM_ElfRelocationConstants.R_ARM_PREL31: { // Target class: Data
int oldValue = memory.getInt(relocationAddress);
if (elfRelocationContext.extractAddend()) {
addend = (oldValue << 1) >> 1;
}
newValue = (int) (symbolValue + addend);
newValue -= offset; // PC relative
if (isThumb) {
newValue |= 1;
}
newValue = (newValue & 0x7fffffff) + (oldValue & 0x80000000);
memory.setInt(relocationAddress, newValue);
break;
}
case ARM_ElfRelocationConstants.R_ARM_LDR_PC_G0: { // Target class: ARM Instruction
int oldValue = memory.getInt(relocationAddress, instructionBigEndian);
newValue = (int) (symbolValue + addend);