Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-0 Minor revision to ELF relocation handlers

ghidra101087ba0a855
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/relocation/AbstractElfRelocationHandler.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/relocation/AbstractElfRelocationHandler.java
index af8e17c231..0065478489 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/relocation/AbstractElfRelocationHandler.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/relocation/AbstractElfRelocationHandler.java
@@ -155,6 +155,23 @@ abstract public class AbstractElfRelocationHandler<T extends ElfRelocationType,
return relocationType.name() + " (" + typeId + ", 0x" + Integer.toHexString(typeId) + ")";
}
+ /**
+ * Generate error log entry and bookmark at relocationAddress indicating an unspportable
+ * COPY relocation. A warning is produced for this COPY relocation failure.
+ * @param program program
+ * @param relocationAddress relocation address to be bookmarked
+ * @param relocationType relocation type
+ * @param symbolIndex associated symbol index within symbol table
+ * @param symbolName associated symbol name
+ * @param symbolSize number of bytes associated with symbol that failed to be copied
+ * @param log import log
+ */
+ protected void markAsUnsupportedCopy(Program program, Address relocationAddress,
+ T relocationType, String symbolName, int symbolIndex, long symbolSize, MessageLog log) {
+ markAsWarning(program, relocationAddress, relocationType, symbolName, symbolIndex,
+ "Runtime copy not supported (" + symbolSize + "-bytes)", log);
+ }
+
/**
* Generate error log entry and bookmark at relocationAddress indicating
* an unhandled relocation.
diff --git a/Ghidra/Processors/AARCH64/src/main/java/ghidra/app/util/bin/format/elf/relocation/AARCH64_ElfRelocationHandler.java b/Ghidra/Processors/AARCH64/src/main/java/ghidra/app/util/bin/format/elf/relocation/AARCH64_ElfRelocationHandler.java
index cb8ffb6d27..13a83c2641 100644
--- a/Ghidra/Processors/AARCH64/src/main/java/ghidra/app/util/bin/format/elf/relocation/AARCH64_ElfRelocationHandler.java
+++ b/Ghidra/Processors/AARCH64/src/main/java/ghidra/app/util/bin/format/elf/relocation/AARCH64_ElfRelocationHandler.java
@@ -359,8 +359,8 @@ public class AARCH64_ElfRelocationHandler
case R_AARCH64_P32_COPY:
case R_AARCH64_COPY: {
- markAsWarning(program, relocationAddress, type, symbolName, symbolIndex,
- "Runtime copy not supported", elfRelocationContext.getLog());
+ markAsUnsupportedCopy(program, relocationAddress, type, symbolName, symbolIndex,
+ sym.getSize(), elfRelocationContext.getLog());
return RelocationResult.UNSUPPORTED;
}
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 aead9bc021..de6e08cfd2 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
@@ -681,8 +681,8 @@ public class ARM_ElfRelocationHandler
*/
case R_ARM_COPY: {
- markAsWarning(program, relocationAddress, type, symbolName, symbolIndex,
- "Runtime copy not supported", elfRelocationContext.getLog());
+ markAsUnsupportedCopy(program, relocationAddress, type, symbolName, symbolIndex,
+ sym.getSize(), elfRelocationContext.getLog());
return RelocationResult.UNSUPPORTED;
}
diff --git a/Ghidra/Processors/Loongarch/src/main/java/ghidra/app/util/bin/format/elf/relocation/Loongarch_ElfRelocationHandler.java b/Ghidra/Processors/Loongarch/src/main/java/ghidra/app/util/bin/format/elf/relocation/Loongarch_ElfRelocationHandler.java
index c94cedb630..d8160c8924 100644
--- a/Ghidra/Processors/Loongarch/src/main/java/ghidra/app/util/bin/format/elf/relocation/Loongarch_ElfRelocationHandler.java
+++ b/Ghidra/Processors/Loongarch/src/main/java/ghidra/app/util/bin/format/elf/relocation/Loongarch_ElfRelocationHandler.java
@@ -38,6 +38,11 @@ public class Loongarch_ElfRelocationHandler
return elf.e_machine() == ElfConstants.EM_LOONGARCH;
}
+ @Override
+ public int getRelrRelocationType() {
+ return Loongarch_ElfRelocationType.R_LARCH_RELATIVE.typeId;
+ }
+
@Override
protected RelocationResult relocate(ElfRelocationContext<?> elfRelocationContext,
ElfRelocation relocation, Loongarch_ElfRelocationType type, Address relocationAddress,
@@ -106,8 +111,8 @@ public class Loongarch_ElfRelocationHandler
case R_LARCH_COPY:
// Runtime memory copy in executable memcpy (PC, RtAddr, sizeof (sym))
- markAsWarning(program, relocationAddress, type, symbolName, symbolIndex,
- "Runtime copy not supported", elfRelocationContext.getLog());
+ markAsUnsupportedCopy(program, relocationAddress, type, symbolName, symbolIndex,
+ sym.getSize(), elfRelocationContext.getLog());
return RelocationResult.UNSUPPORTED;
case R_LARCH_JUMP_SLOT:
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 a019967156..c4b8027732 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
@@ -608,8 +608,8 @@ public class MIPS_ElfRelocationHandler
case R_MIPS_COPY:
// TODO: Requires symbol lookup into dynamic library - not sure what we can do here
- markAsWarning(program, relocationAddress, type, symbolName, symbolIndex,
- "Runtime copy not supported", log);
+ markAsUnsupportedCopy(program, relocationAddress, type, symbolName, symbolIndex,
+ elfSymbol.getSize(), elfRelocationContext.getLog());
if (saveValue) {
elfRelocationContext.savedAddendHasError = true;
}
diff --git a/Ghidra/Processors/PowerPC/src/main/java/ghidra/app/util/bin/format/elf/relocation/PowerPC64_ElfRelocationHandler.java b/Ghidra/Processors/PowerPC/src/main/java/ghidra/app/util/bin/format/elf/relocation/PowerPC64_ElfRelocationHandler.java
index 8e6ef55707..e7bbf452b3 100644
--- a/Ghidra/Processors/PowerPC/src/main/java/ghidra/app/util/bin/format/elf/relocation/PowerPC64_ElfRelocationHandler.java
+++ b/Ghidra/Processors/PowerPC/src/main/java/ghidra/app/util/bin/format/elf/relocation/PowerPC64_ElfRelocationHandler.java
@@ -49,6 +49,11 @@ public class PowerPC64_ElfRelocationHandler
return elf.e_machine() == ElfConstants.EM_PPC64 && elf.is64Bit();
}
+ @Override
+ public int getRelrRelocationType() {
+ return PowerPC64_ElfRelocationType.R_PPC64_RELATIVE.typeId;
+ }
+
@Override
protected RelocationResult relocate(ElfRelocationContext<?> elfRelocationContext,
ElfRelocation relocation, PowerPC64_ElfRelocationType type, Address relocationAddress,
@@ -100,8 +105,8 @@ public class PowerPC64_ElfRelocationHandler
switch (type) {
case R_PPC64_COPY:
- markAsWarning(program, relocationAddress, type, symbolName, symbolIndex,
- "Runtime copy not supported", elfRelocationContext.getLog());
+ markAsUnsupportedCopy(program, relocationAddress, type, symbolName, symbolIndex,
+ sym.getSize(), elfRelocationContext.getLog());
return RelocationResult.UNSUPPORTED;
case R_PPC64_ADDR32:
newValue = (int) (symbolValue + addend);
diff --git a/Ghidra/Processors/PowerPC/src/main/java/ghidra/app/util/bin/format/elf/relocation/PowerPC_ElfRelocationHandler.java b/Ghidra/Processors/PowerPC/src/main/java/ghidra/app/util/bin/format/elf/relocation/PowerPC_ElfRelocationHandler.java
index e630d73484..0f1ccd29a1 100644
--- a/Ghidra/Processors/PowerPC/src/main/java/ghidra/app/util/bin/format/elf/relocation/PowerPC_ElfRelocationHandler.java
+++ b/Ghidra/Processors/PowerPC/src/main/java/ghidra/app/util/bin/format/elf/relocation/PowerPC_ElfRelocationHandler.java
@@ -53,6 +53,11 @@ public class PowerPC_ElfRelocationHandler extends
return new PowerPC_ElfRelocationContext(this, loadHelper, symbolMap);
}
+ @Override
+ public int getRelrRelocationType() {
+ return PowerPC_ElfRelocationType.R_PPC_RELATIVE.typeId;
+ }
+
@Override
protected RelocationResult relocate(PowerPC_ElfRelocationContext elfRelocationContext,
ElfRelocation relocation, PowerPC_ElfRelocationType type, Address relocationAddress,
@@ -87,9 +92,9 @@ public class PowerPC_ElfRelocationHandler extends
switch (type) {
case R_PPC_COPY:
- markAsWarning(program, relocationAddress, type, symbolName, symbolIndex,
- "Runtime copy not supported", elfRelocationContext.getLog());
- return RelocationResult.SKIPPED;
+ markAsUnsupportedCopy(program, relocationAddress, type, symbolName, symbolIndex,
+ sym.getSize(), elfRelocationContext.getLog());
+ return RelocationResult.UNSUPPORTED;
case R_PPC_ADDR32:
case R_PPC_UADDR32:
case R_PPC_GLOB_DAT:
diff --git a/Ghidra/Processors/RISCV/src/main/java/ghidra/app/util/bin/format/elf/relocation/RISCV_ElfRelocationHandler.java b/Ghidra/Processors/RISCV/src/main/java/ghidra/app/util/bin/format/elf/relocation/RISCV_ElfRelocationHandler.java
index 36193deaa3..064792e248 100644
--- a/Ghidra/Processors/RISCV/src/main/java/ghidra/app/util/bin/format/elf/relocation/RISCV_ElfRelocationHandler.java
+++ b/Ghidra/Processors/RISCV/src/main/java/ghidra/app/util/bin/format/elf/relocation/RISCV_ElfRelocationHandler.java
@@ -71,6 +71,11 @@ public class RISCV_ElfRelocationHandler
return new RISCV_ElfRelocationContext(this, loadHelper, symbolMap);
}
+ @Override
+ public int getRelrRelocationType() {
+ return RISCV_ElfRelocationType.R_RISCV_RELATIVE.typeId;
+ }
+
/**
* Get the adjusted 20 high bits of a 32 bit target. The lower 12 bits will
* be found in a later instruction, using a sign-extended signed addition. If those
@@ -201,8 +206,8 @@ public class RISCV_ElfRelocationHandler
case R_RISCV_COPY:
// Runtime relocation must be in executable. not allowed in shared library
- markAsWarning(program, relocationAddress, type, symbolName, symbolIndex,
- "Runtime copy not supported", elfRelocationContext.getLog());
+ markAsUnsupportedCopy(program, relocationAddress, type, symbolName, symbolIndex,
+ sym.getSize(), elfRelocationContext.getLog());
return RelocationResult.UNSUPPORTED;
case R_RISCV_JUMP_SLOT:
diff --git a/Ghidra/Processors/Sparc/src/main/java/ghidra/app/util/bin/format/elf/relocation/SPARC_ElfRelocationHandler.java b/Ghidra/Processors/Sparc/src/main/java/ghidra/app/util/bin/format/elf/relocation/SPARC_ElfRelocationHandler.java
index 76c414dc5e..4ead1c2f40 100644
--- a/Ghidra/Processors/Sparc/src/main/java/ghidra/app/util/bin/format/elf/relocation/SPARC_ElfRelocationHandler.java
+++ b/Ghidra/Processors/Sparc/src/main/java/ghidra/app/util/bin/format/elf/relocation/SPARC_ElfRelocationHandler.java
@@ -96,8 +96,8 @@ public class SPARC_ElfRelocationHandler
memory.setInt(relocationAddress, newValue);
break;
case R_SPARC_COPY:
- markAsWarning(program, relocationAddress, type, symbolName, symbolIndex,
- "Runtime copy not supported", elfRelocationContext.getLog());
+ markAsUnsupportedCopy(program, relocationAddress, type, symbolName, symbolIndex,
+ sym.getSize(), elfRelocationContext.getLog());
return RelocationResult.UNSUPPORTED;
default:
markAsUnhandled(program, relocationAddress, type, symbolIndex, symbolName,
diff --git a/Ghidra/Processors/SuperH4/src/main/java/ghidra/app/util/bin/format/elf/relocation/SH_ElfRelocationHandler.java b/Ghidra/Processors/SuperH4/src/main/java/ghidra/app/util/bin/format/elf/relocation/SH_ElfRelocationHandler.java
index a21927245e..37f3efdb71 100644
--- a/Ghidra/Processors/SuperH4/src/main/java/ghidra/app/util/bin/format/elf/relocation/SH_ElfRelocationHandler.java
+++ b/Ghidra/Processors/SuperH4/src/main/java/ghidra/app/util/bin/format/elf/relocation/SH_ElfRelocationHandler.java
@@ -124,8 +124,8 @@ public class SH_ElfRelocationHandler
break;
case R_SH_COPY:
- markAsWarning(program, relocationAddress, type, symbolName, symbolIndex,
- "Runtime copy not supported", elfRelocationContext.getLog());
+ markAsUnsupportedCopy(program, relocationAddress, type, symbolName, symbolIndex,
+ sym.getSize(), elfRelocationContext.getLog());
return RelocationResult.UNSUPPORTED;
case R_SH_RELATIVE:
diff --git a/Ghidra/Processors/tricore/src/main/java/ghidra/app/util/bin/format/elf/relocation/Tricore_ElfRelocationHandler.java b/Ghidra/Processors/tricore/src/main/java/ghidra/app/util/bin/format/elf/relocation/Tricore_ElfRelocationHandler.java
index dff740fe5c..c646bf42c9 100644
--- a/Ghidra/Processors/tricore/src/main/java/ghidra/app/util/bin/format/elf/relocation/Tricore_ElfRelocationHandler.java
+++ b/Ghidra/Processors/tricore/src/main/java/ghidra/app/util/bin/format/elf/relocation/Tricore_ElfRelocationHandler.java
@@ -15,33 +15,35 @@
*/
package ghidra.app.util.bin.format.elf.relocation;
-import ghidra.app.util.bin.format.elf.ElfConstants;
-import ghidra.app.util.bin.format.elf.ElfHeader;
-import ghidra.app.util.bin.format.elf.ElfRelocation;
-import ghidra.app.util.bin.format.elf.ElfSymbol;
+import ghidra.app.util.bin.format.elf.*;
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.Program;
import ghidra.program.model.mem.Memory;
import ghidra.program.model.mem.MemoryAccessException;
-import ghidra.program.model.reloc.RelocationResult;
import ghidra.program.model.reloc.Relocation.Status;
+import ghidra.program.model.reloc.RelocationResult;
import ghidra.util.exception.NotFoundException;
public class Tricore_ElfRelocationHandler
- extends AbstractElfRelocationHandler<Tricore_ElfRelocationType, ElfRelocationContext<?>> {
+ extends AbstractElfRelocationHandler<Tricore_ElfRelocationType, ElfRelocationContext<?>> {
/**
- * Constructor
- */
- public Tricore_ElfRelocationHandler() {
+ * Constructor
+ */
+ public Tricore_ElfRelocationHandler() {
super(Tricore_ElfRelocationType.class);
- }
+ }
- @Override
+ @Override
public boolean canRelocate(ElfHeader elf) {
return elf.e_machine() == ElfConstants.EM_TRICORE;
}
+ @Override
+ public int getRelrRelocationType() {
+ return Tricore_ElfRelocationType.R_TRICORE_RELATIVE.typeId;
+ }
+
@Override
protected RelocationResult relocate(ElfRelocationContext<?> elfRelocationContext,
ElfRelocation relocation, Tricore_ElfRelocationType type, Address relocationAddress,
@@ -51,7 +53,8 @@ public class Tricore_ElfRelocationHandler
Program program = elfRelocationContext.getProgram();
Memory memory = program.getMemory();
- long addend = relocation.hasAddend() ? relocation.getAddend() : memory.getInt(relocationAddress);
+ long addend =
+ relocation.hasAddend() ? relocation.getAddend() : memory.getInt(relocationAddress);
long offset = relocationAddress.getOffset();
int symbolIndex = relocation.getSymbolIndex();
@@ -66,236 +69,245 @@ public class Tricore_ElfRelocationHandler
* register A[0].
*/
switch (type) {
- case R_TRICORE_32REL: // word32 S + A - P
- rv = symbolValue + addend - offset;
- byteLength = relocate_word32(memory, relocationAddress, rv);
- break;
- case R_TRICORE_32ABS: // word32 S + A
- rv = symbolValue + addend;
- byteLength = relocate_word32(memory, relocationAddress, rv);
- break;
- case R_TRICORE_24REL: // relB S + A - P
- rv = symbolValue + addend - offset;
- byteLength = relocate_relB(memory, relocationAddress, rv);
- break;
- case R_TRICORE_24ABS: // absB S + A
- rv = symbolValue + addend;
- byteLength = relocate_absB(memory, relocationAddress, rv);
- break;
-
- /**
- case R_TRICORE_16SM: // BOL S + A - A[0]
- break;
- **/
-
- case R_TRICORE_HI: // RLC S + A + 8000H >> 16
- rv = (symbolValue + addend + 0x8000) >> 16;
- byteLength = relocate_RLC(memory, relocationAddress, rv);
- break;
- case R_TRICORE_LO: // RLC S + A & FFFFH
- rv = (symbolValue + addend) & 0xffff;
- byteLength = relocate_RLC(memory, relocationAddress, rv);
- break;
- case R_TRICORE_LO2: // BOL S + A & FFFFH
- rv = (symbolValue + addend) & 0xffff;
- byteLength = relocate_BOL(memory, relocationAddress, rv);
- break;
- case R_TRICORE_18ABS: // ABS S + A
- rv = symbolValue + addend;
- byteLength = relocate_ABS(memory, relocationAddress, rv);
- break;
-
- /**
- case R_TRICORE_10SM: // BO S + A - A[0]
- break;
- **/
-
- case R_TRICORE_15REL: // BR S + A - P
- rv = symbolValue + addend - offset;
- byteLength = relocate_BR(memory, relocationAddress, rv);
- break;
-
- /**
- case R_TRICORE_10LI: // BO S + A - A[1]
- break;
- case R_TRICORE_16LI: // BOL S + A - A[1]
- break;
- case R_TRICORE_10A8: // BO S + A - A[8]
- break;
- case R_TRICORE_16A8: // BOL S + A - A[8]
- break;
- case R_TRICORE_10A9: // BO S + A - A[9]
- break;
- case R_TRICORE_16A9: // BOL S + A - A[9]
- break;
- case R_TRICORE_10OFF:
- break;
- **/
-
- case R_TRICORE_16OFF:
- rv = symbolValue + addend;
- byteLength = relocate_BOL(memory, relocationAddress, rv);
- break;
-
- /**
- case R_TRICORE_8ABS:
- break;
- case R_TRICORE_16ABS:
- break;
- case R_TRICORE_16BIT:
- break;
- **/
-
- case R_TRICORE_3POS:
- rv = symbolValue + addend;
- byteLength = relocate_3POS(memory, relocationAddress, rv);
- break;
- case R_TRICORE_5POS:
- rv = symbolValue + addend;
- byteLength = relocate_5POS(memory, relocationAddress, rv);
- break;
- case R_TRICORE_PCPHI: // word16 S + A >> 16
- rv = (symbolValue + addend) >> 16;
- byteLength = relocate_word16(memory, relocationAddress, rv);
- break;
- case R_TRICORE_PCPLO: // word16 S + A & FFFFH
- rv = (symbolValue + addend) & 0xffff;
- byteLength = relocate_word16(memory, relocationAddress, rv);
- break;
- case R_TRICORE_PCPPAGE: // pcpPage S + A & FF00H
- rv = (symbolValue + addend) & 0xff00;
- byteLength = relocate_pcpPage(memory, relocationAddress, rv);
- break;
- case R_TRICORE_PCPOFF: // PI (S + A >> 2) & 3FH
- rv = ((symbolValue + addend) >> 2) & 0x3f;
- byteLength = relocate_PI(memory, relocationAddress, rv);
- break;
- case R_TRICORE_PCPTEXT: // word16 (S + A >> 1) & FFFFH
- rv = ((symbolValue + addend) >> 1) & 0xffff;
- byteLength = relocate_word16(memory, relocationAddress, rv);
- break;
- case R_TRICORE_5POS2:
- rv = (symbolValue + addend);
- byteLength = relocate_5POS2(memory, relocationAddress, rv);
- break;
-
- /**
- case R_TRICORE_BRCC:
- break;
- case R_TRICORE_BRCZ:
- break;
- case R_TRICORE_BRNN:
- break;
- case R_TRICORE_RRN:
- break;
- case R_TRICORE_4CONST:
- break;
- case R_TRICORE_4REL:
- break;
- case R_TRICORE_4REL2:
- break;
- case R_TRICORE_5POS3:
- break;
- case R_TRICORE_4OFF:
- break;
- case R_TRICORE_4OFF2:
- break;
- case R_TRICORE_4OFF4:
- break;
- case R_TRICORE_42OFF:
- break;
- case R_TRICORE_42OFF2:
- break;
- case R_TRICORE_42OFF4:
- break;
- case R_TRICORE_2OFF:
- break;
- case R_TRICORE_8CONST2:
- break;
- case R_TRICORE_4POS:
- break;
- case R_TRICORE_16SM2:
- break;
- case R_TRICORE_5REL:
- break;
- case R_TRICORE_VTENTRY:
- break;
- case R_TRICORE_VTINHERIT:
- break;
- case R_TRICORE_PCREL16:
- break;
- case R_TRICORE_PCREL8:
- break;
- case R_TRICORE_GOT:
- break;
- case R_TRICORE_GOT2:
- break;
- case R_TRICORE_GOTHI:
- break;
- case R_TRICORE_GOTLO:
- break;
- case R_TRICORE_GOTLO2:
- break;
- case R_TRICORE_GOTUP:
- break;
- case R_TRICORE_GOTOFF:
- break;
- case R_TRICORE_GOTOFF2:
- break;
- case R_TRICORE_GOTOFFHI:
- break;
- case R_TRICORE_GOTOFFLO:
- break;
- case R_TRICORE_GOTOFFLO2:
- break;
- case R_TRICORE_GOTOFFUP:
- break;
- case R_TRICORE_GOTPC:
- break;
- case R_TRICORE_GOTPC2:
- break;
- case R_TRICORE_GOTPCHI:
- break;
- case R_TRICORE_GOTPCLO:
- break;
- case R_TRICORE_GOTPCLO2:
- break;
- case R_TRICORE_GOTCPUP:
- break;
- case R_TRICORE_PLT:
- break;
- case R_TRICORE_COPY:
- break;
- case R_TRICORE_GLOB_DAT:
- break;
- case R_TRICORE_JMP_SLOT:
- break;
- case R_TRICORE_RELATIVE:
- break;
- **/
-
- case R_TRICORE_BITPOS:
- // This reads as a pseudo relocation, possibly do RelocationResult.PARTIAL instead?
- return RelocationResult.SKIPPED;
-
- /**
- case R_TRICORE_SBREG_S2:
- break;
- case R_TRICORE_SBREG_S1:
- break;
- case R_TRICORE_SBREG_D:
- break;
- **/
-
- default:
- break;
+ case R_TRICORE_32REL: // word32 S + A - P
+ rv = symbolValue + addend - offset;
+ byteLength = relocate_word32(memory, relocationAddress, rv);
+ break;
+ case R_TRICORE_32ABS: // word32 S + A
+ rv = symbolValue + addend;
+ byteLength = relocate_word32(memory, relocationAddress, rv);
+ break;
+ case R_TRICORE_24REL: // relB S + A - P
+ rv = symbolValue + addend - offset;
+ byteLength = relocate_relB(memory, relocationAddress, rv);
+ break;
+ case R_TRICORE_24ABS: // absB S + A
+ rv = symbolValue + addend;
+ byteLength = relocate_absB(memory, relocationAddress, rv);
+ break;
+
+ /**
+ case R_TRICORE_16SM: // BOL S + A - A[0]
+ break;
+ **/
+
+ case R_TRICORE_HI: // RLC S + A + 8000H >> 16
+ rv = (symbolValue + addend + 0x8000) >> 16;
+ byteLength = relocate_RLC(memory, relocationAddress, rv);
+ break;
+ case R_TRICORE_LO: // RLC S + A & FFFFH
+ rv = (symbolValue + addend) & 0xffff;
+ byteLength = relocate_RLC(memory, relocationAddress, rv);
+ break;
+ case R_TRICORE_LO2: // BOL S + A & FFFFH
+ rv = (symbolValue + addend) & 0xffff;
+ byteLength = relocate_BOL(memory, relocationAddress, rv);
+ break;
+ case R_TRICORE_18ABS: // ABS S + A
+ rv = symbolValue + addend;
+ byteLength = relocate_ABS(memory, relocationAddress, rv);
+ break;
+
+ /**
+ case R_TRICORE_10SM: // BO S + A - A[0]
+ break;
+ **/
+
+ case R_TRICORE_15REL: // BR S + A - P
+ rv = symbolValue + addend - offset;
+ byteLength = relocate_BR(memory, relocationAddress, rv);
+ break;
+
+ /**
+ case R_TRICORE_10LI: // BO S + A - A[1]
+ break;
+ case R_TRICORE_16LI: // BOL S + A - A[1]
+ break;
+ case R_TRICORE_10A8: // BO S + A - A[8]
+ break;
+ case R_TRICORE_16A8: // BOL S + A - A[8]
+ break;
+ case R_TRICORE_10A9: // BO S + A - A[9]
+ break;
+ case R_TRICORE_16A9: // BOL S + A - A[9]
+ break;
+ case R_TRICORE_10OFF:
+ break;
+ **/
+
+ case R_TRICORE_16OFF:
+ rv = symbolValue + addend;
+ byteLength = relocate_BOL(memory, relocationAddress, rv);
+ break;
+
+ /**
+ case R_TRICORE_8ABS:
+ break;
+ case R_TRICORE_16ABS:
+ break;
+ case R_TRICORE_16BIT:
+ break;
+ **/
+
+ case R_TRICORE_3POS:
+ rv = symbolValue + addend;
+ byteLength = relocate_3POS(memory, relocationAddress, rv);
+ break;
+ case R_TRICORE_5POS:
+ rv = symbolValue + addend;
+ byteLength = relocate_5POS(memory, relocationAddress, rv);
+ break;
+ case R_TRICORE_PCPHI: // word16 S + A >> 16
+ rv = (symbolValue + addend) >> 16;
+ byteLength = relocate_word16(memory, relocationAddress, rv);
+ break;
+ case R_TRICORE_PCPLO: // word16 S + A & FFFFH
+ rv = (symbolValue + addend) & 0xffff;
+ byteLength = relocate_word16(memory, relocationAddress, rv);
+ break;
+ case R_TRICORE_PCPPAGE: // pcpPage S + A & FF00H
+ rv = (symbolValue + addend) & 0xff00;
+ byteLength = relocate_pcpPage(memory, relocationAddress, rv);
+ break;
+ case R_TRICORE_PCPOFF: // PI (S + A >> 2) & 3FH
+ rv = ((symbolValue + addend) >> 2) & 0x3f;
+ byteLength = relocate_PI(memory, relocationAddress, rv);
+ break;
+ case R_TRICORE_PCPTEXT: // word16 (S + A >> 1) & FFFFH
+ rv = ((symbolValue + addend) >> 1) & 0xffff;
+ byteLength = relocate_word16(memory, relocationAddress, rv);
+ break;
+ case R_TRICORE_5POS2:
+ rv = (symbolValue + addend);
+ byteLength = relocate_5POS2(memory, relocationAddress, rv);
+ break;
+
+ /**
+ case R_TRICORE_BRCC:
+ break;
+ case R_TRICORE_BRCZ:
+ break;
+ case R_TRICORE_BRNN:
+ break;
+ case R_TRICORE_RRN:
+ break;
+ case R_TRICORE_4CONST:
+ break;
+ case R_TRICORE_4REL:
+ break;
+ case R_TRICORE_4REL2:
+ break;
+ case R_TRICORE_5POS3:
+ break;
+ case R_TRICORE_4OFF:
+ break;
+ case R_TRICORE_4OFF2:
+ break;
+ case R_TRICORE_4OFF4:
+ break;
+ case R_TRICORE_42OFF:
+ break;
+ case R_TRICORE_42OFF2:
+ break;
+ case R_TRICORE_42OFF4:
+ break;
+ case R_TRICORE_2OFF:
+ break;
+ case R_TRICORE_8CONST2:
+ break;
+ case R_TRICORE_4POS:
+ break;
+ case R_TRICORE_16SM2:
+ break;
+ case R_TRICORE_5REL:
+ break;
+ case R_TRICORE_VTENTRY:
+ break;
+ case R_TRICORE_VTINHERIT:
+ break;
+ case R_TRICORE_PCREL16:
+ break;
+ case R_TRICORE_PCREL8:
+ break;
+ case R_TRICORE_GOT:
+ break;
+ case R_TRICORE_GOT2:
+ break;
+ case R_TRICORE_GOTHI:
+ break;
+ case R_TRICORE_GOTLO:
+ break;
+ case R_TRICORE_GOTLO2:
+ break;
+ case R_TRICORE_GOTUP:
+ break;
+ case R_TRICORE_GOTOFF:
+ break;
+ case R_TRICORE_GOTOFF2:
+ break;
+ case R_TRICORE_GOTOFFHI:
+ break;
+ case R_TRICORE_GOTOFFLO:
+ break;
+ case R_TRICORE_GOTOFFLO2:
+ break;
+ case R_TRICORE_GOTOFFUP:
+ break;
+ case R_TRICORE_GOTPC:
+ break;
+ case R_TRICORE_GOTPC2:
+ break;
+ case R_TRICORE_GOTPCHI:
+ break;
+ case R_TRICORE_GOTPCLO:
+ break;
+ case R_TRICORE_GOTPCLO2:
+ break;
+ case R_TRICORE_GOTCPUP:
+ break;
+ case R_TRICORE_PLT:
+ break;
+ **/
+
+ case R_TRICORE_GLOB_DAT:
+ case R_TRICORE_JMP_SLOT:
+ memory.setInt(relocationAddress, (int) symbolValue);
+ break;
+
+ case R_TRICORE_RELATIVE:
+ long base = program.getImageBase().getOffset();
+ rv = (int) (base + addend);
+ byteLength = relocate_word32(memory, relocationAddress, rv);
+ break;
+
+ case R_TRICORE_COPY:
+ markAsUnsupportedCopy(program, relocationAddress, type, symbolName, symbolIndex,
+ sym.getSize(), elfRelocationContext.getLog());
+ return RelocationResult.UNSUPPORTED;
+
+ case R_TRICORE_BITPOS:
+ // This reads as a pseudo relocation, possibly do RelocationResult.PARTIAL instead?
+ return RelocationResult.SKIPPED;
+
+ /**
+ case R_TRICORE_SBREG_S2:
+ break;
+ case R_TRICORE_SBREG_S1:
+ break;
+ case R_TRICORE_SBREG_D:
+ break;
+ **/
+
+ default:
+ break;
}
-
+
if (byteLength <= 0) {
- markAsUnhandled(program, relocationAddress, type, symbolIndex, symbolName, elfRelocationContext.getLog());
+ markAsUnhandled(program, relocationAddress, type, symbolIndex, symbolName,
+ elfRelocationContext.getLog());
return RelocationResult.UNSUPPORTED;
}
-
+
return new RelocationResult(Status.APPLIED, byteLength);
}
@@ -309,7 +321,8 @@ public class Tricore_ElfRelocationHandler
* A 32-bit field occupying four bytes. This address is NOT required to be
* 4-byte aligned.
*/
- private int relocate_word32(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ private int relocate_word32(Memory memory, Address relocationAddress, long rv)
+ throws MemoryAccessException {
memory.setInt(relocationAddress, (int) rv);
return 4;
}
@@ -317,7 +330,8 @@ public class Tricore_ElfRelocationHandler
/**
* A 16-bit field occupying two bytes.
*/
- private int relocate_word16(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ private int relocate_word16(Memory memory, Address relocationAddress, long rv)
+ throws MemoryAccessException {
memory.setShort(relocationAddress, (short) rv);
return 2;
}
@@ -327,7 +341,8 @@ public class Tricore_ElfRelocationHandler
* the IW. - bits 17-24 of the RV go into bits 8-15 of the IW. - the RV must be
* in the range [-16777216,16777214]. bit 0 of the RV must be zero.
*/
- private int relocate_relB(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ private int relocate_relB(Memory memory, Address relocationAddress, long rv)
+ throws MemoryAccessException {
// TODO ff000000..00fffffe?
long mask = 0xfffffffeL;
long val = ~mask & rv;
@@ -344,7 +359,8 @@ public class Tricore_ElfRelocationHandler
* to 27 of the RV must be zero. - bits 28-31 of the RV go into bits 12-15 of
* the IW.
*/
- private int relocate_absB(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ private int relocate_absB(Memory memory, Address relocationAddress, long rv)
+ throws MemoryAccessException {
long mask = 0x0fe00001L;
long val = ~mask & rv;
int iw = memory.getInt(relocationAddress) & 0xff;
@@ -361,7 +377,8 @@ public class Tricore_ElfRelocationHandler
* the RV must be zero.
*/
@SuppressWarnings("unused")
- private int relocate_BO(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ private int relocate_BO(Memory memory, Address relocationAddress, long rv)
+ throws MemoryAccessException {
long mask = 0xfffffc00L;
long val = ~mask & rv;
int iw = memory.getInt(relocationAddress) & 0xfc0ffff;
@@ -376,7 +393,8 @@ public class Tricore_ElfRelocationHandler
* the IW. - bits 6-9 of the RV go into bits 28-31 of the IW. - bits 10-15 of
* the RV go into bits 22-27 of the IW. - bits 16-31 of the RV must be zero.
*/
- private int relocate_BOL(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ private int relocate_BOL(Memory memory, Address relocationAddress, long rv)
+ throws MemoryAccessException {
long mask = 0xffff0000L;
long val = ~mask & rv;
int iw = memory.getInt(relocationAddress) & 0xffff;
@@ -391,7 +409,8 @@ public class Tricore_ElfRelocationHandler
* A 32-bit instruction word, where: - bits 1-15 of the RV go into bits 16-30 of
* the IW. - bits 16-31 of the RV must be zero.
*/
- private int relocate_BR(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ private int relocate_BR(Memory memory, Address relocationAddress, long rv)
+ throws MemoryAccessException {
long mask = 0xffff0000L;
long val = ~mask & rv;
int iw = memory.getInt(relocationAddress) & 0x8000ffff;
@@ -404,7 +423,8 @@ public class Tricore_ElfRelocationHandler
* A 32-bit instruction word, where: - bits 0-15 of the RV go into bits 12-27 of
* the IW. - bits 16-31 of the RV must be zero.
*/
- private int relocate_RLC(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ private int relocate_RLC(Memory memory, Address relocationAddress, long rv)
+ throws MemoryAccessException {
long mask = 0xffff0000L;
long val = ~mask & rv;
int iw = memory.getInt(relocationAddress) & 0xf0000fff;
@@ -419,7 +439,8 @@ public class Tricore_ElfRelocationHandler
* the RV go into bits 22-25 of the IW. - bits 14-27 of the RV must be zero. -
* bits 28-31 of the RV go into bits 12-15 of the IW.
*/
- private int relocate_ABS(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ private int relocate_ABS(Memory memory, Address relocationAddress, long rv)
+ throws MemoryAccessException {
long mask = 0x0fffc000L;
long val = ~mask & rv;
int iw = memory.getInt(relocationAddress) & 0xc000fff;
@@ -449,7 +470,8 @@ public class Tricore_ElfRelocationHandler
* A 16-bit instruction word, where: - bits 8-15 of the RV go into bits 8-15 of
* the IW. - bits 0-7 and 16-31 of the RV must be zero.
*/
- private int relocate_pcpPage(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ private int relocate_pcpPage(Memory memory, Address relocationAddress, long rv)
+ throws MemoryAccessException {
long mask = 0xffff00ffL;
long val = ~mask & rv;
int iw = memory.getShort(relocationAddress) & 0xff;
@@ -462,7 +484,8 @@ public class Tricore_ElfRelocationHandler
* A 16-bit instruction word, where: - bits 0-5 of the RV go into bits 0-5 of
* the IW. - bits 6-15 of the RV must be zero.
*/
- private int relocate_PI(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ private int relocate_PI(Memory memory, Address relocationAddress, long rv)
+ throws MemoryAccessException {
long mask = 0xffffffc0L;
long val = ~mask & rv;
int iw = memory.getShort(relocationAddress) & 0xffc0;
@@ -470,11 +493,12 @@ public class Tricore_ElfRelocationHandler
memory.setShort(relocationAddress, (short) iw);
return 2;
}
-
+
/**
*
*/
- private int relocate_3POS(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ private int relocate_3POS(Memory memory, Address relocationAddress, long rv)
+ throws MemoryAccessException {
long mask = 0xfffffff8L;
long val = ~mask & rv;
int iw = memory.getInt(relocationAddress);
@@ -482,11 +506,12 @@ public class Tricore_ElfRelocationHandler
memory.setInt(relocationAddress, iw);
return 4;
}
-
+
/**
*
*/
- private int relocate_5POS(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ private int relocate_5POS(Memory memory, Address relocationAddress, long rv)
+ throws MemoryAccessException {
long mask = 0xffffffe0L;
long val = ~mask & rv;
int iw = memory.getInt(relocationAddress);
@@ -494,11 +519,12 @@ public class Tricore_ElfRelocationHandler
memory.setInt(relocationAddress, iw);
return 4;
}
-
+
/**
*
*/
- private int relocate_5POS2(Memory memory, Address relocationAddress, long rv) throws MemoryAccessException {
+ private int relocate_5POS2(Memory memory, Address relocationAddress, long rv)
+ throws MemoryAccessException {
long mask = 0xffffffe0L;
long val = ~mask & rv;
int iw = memory.getInt(relocationAddress);
diff --git a/Ghidra/Processors/x86/src/main/java/ghidra/app/util/bin/format/elf/relocation/X86_32_ElfRelocationHandler.java b/Ghidra/Processors/x86/src/main/java/ghidra/app/util/bin/format/elf/relocation/X86_32_ElfRelocationHandler.java
index f32082d802..89b77c40c9 100644
--- a/Ghidra/Processors/x86/src/main/java/ghidra/app/util/bin/format/elf/relocation/X86_32_ElfRelocationHandler.java
+++ b/Ghidra/Processors/x86/src/main/java/ghidra/app/util/bin/format/elf/relocation/X86_32_ElfRelocationHandler.java
@@ -99,12 +99,13 @@ public class X86_32_ElfRelocationHandler
catch (NotFoundException e) {
markAsError(program, relocationAddress, type, symbolName, symbolIndex,
e.getMessage(), elfRelocationContext.getLog());
+ return RelocationResult.FAILURE;
}
break;
case R_386_COPY:
- markAsWarning(program, relocationAddress, type, symbolName, symbolIndex,
- "Runtime copy not supported", elfRelocationContext.getLog());
- break;
+ markAsUnsupportedCopy(program, relocationAddress, type, symbolName, symbolIndex,
+ sym.getSize(), elfRelocationContext.getLog());
+ return RelocationResult.UNSUPPORTED;
// Thread Local Symbol relocations (unimplemented concept)
case R_386_TLS_DTPMOD32:
case R_386_TLS_DTPOFF32:
@@ -146,6 +147,7 @@ public class X86_32_ElfRelocationHandler
catch (NotFoundException e) {
markAsError(program, relocationAddress, type, symbolName, symbolIndex,
e.getMessage(), elfRelocationContext.getLog());
+ return RelocationResult.FAILURE;
}
break;
diff --git a/Ghidra/Processors/x86/src/main/java/ghidra/app/util/bin/format/elf/relocation/X86_64_ElfRelocationHandler.java b/Ghidra/Processors/x86/src/main/java/ghidra/app/util/bin/format/elf/relocation/X86_64_ElfRelocationHandler.java
index 71c966006b..f7a0809bb1 100644
--- a/Ghidra/Processors/x86/src/main/java/ghidra/app/util/bin/format/elf/relocation/X86_64_ElfRelocationHandler.java
+++ b/Ghidra/Processors/x86/src/main/java/ghidra/app/util/bin/format/elf/relocation/X86_64_ElfRelocationHandler.java
@@ -69,8 +69,8 @@ public class X86_64_ElfRelocationHandler extends
switch (type) {
case R_X86_64_COPY:
- markAsWarning(program, relocationAddress, type, symbolName, symbolIndex,
- "Runtime copy not supported", elfRelocationContext.getLog());
+ markAsUnsupportedCopy(program, relocationAddress, type, symbolName, symbolIndex,
+ sym.getSize(), elfRelocationContext.getLog());
return RelocationResult.UNSUPPORTED;
case R_X86_64_64:
value = symbolValue + addend;
@@ -135,6 +135,7 @@ public class X86_64_ElfRelocationHandler extends
catch (NotFoundException e) {
markAsError(program, relocationAddress, type, symbolName, symbolIndex,
e.getMessage(), elfRelocationContext.getLog());
+ return RelocationResult.FAILURE;
}
break;
case R_X86_64_32: // this one complains for unsigned overflow
@@ -176,6 +177,7 @@ public class X86_64_ElfRelocationHandler extends
catch (NotFoundException e) {
markAsError(program, relocationAddress, type, symbolName, symbolIndex,
e.getMessage(), elfRelocationContext.getLog());
+ return RelocationResult.FAILURE;
}
break;
@@ -239,7 +241,7 @@ public class X86_64_ElfRelocationHandler extends
if (symbolGotAddress == null) {
markAsError(program, relocationAddress, type, symbolName, symbolIndex,
"GOT allocation failure", elfRelocationContext.getLog());
- break;
+ return RelocationResult.FAILURE;
}
value = symbolGotAddress.getOffset() + addend - offset;
memory.setInt(relocationAddress, (int) value);
@@ -251,7 +253,7 @@ public class X86_64_ElfRelocationHandler extends
if (symbolGotAddress == null) {
markAsError(program, relocationAddress, type, symbolName, symbolIndex,
"GOT allocation failure", elfRelocationContext.getLog());
- break;
+ return RelocationResult.FAILURE;
}
value = symbolGotAddress.getOffset() + addend - offset;
memory.setLong(relocationAddress, value);