Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-348 Added ELF RELR relocation related constants

ghidra16d56553d7219
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfDynamicType.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfDynamicType.java
index 849d391b70..024fd03057 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfDynamicType.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfDynamicType.java
@@ -94,6 +94,15 @@ public class ElfDynamicType {
public static ElfDynamicType DT_FLAGS = addDefaultDynamicType(30, "DT_FLAGS",
"Flags for the object being loaded", ElfDynamicValueType.VALUE);
+ // Experimental RELR relocation support
+ // - see proposal at https://groups.google.com/forum/#!topic/generic-abi/bX460iggiKg
+ public static ElfDynamicType DT_RELRSZ = addDefaultDynamicType(35, "DT_RELSZ",
+ "Total size of Relr relocs", ElfDynamicValueType.VALUE);
+ public static ElfDynamicType DT_RELR = addDefaultDynamicType(36, "DT_RELR",
+ "Address of Relr relocs", ElfDynamicValueType.ADDRESS);
+ public static ElfDynamicType DT_RELRENT = addDefaultDynamicType(37, "DT_RELSZ",
+ "Size of Relr relocation entry", ElfDynamicValueType.VALUE);
+
public static final int DF_ORIGIN = 0x1; // $ORIGIN processing required
public static final int DF_SYMBOLIC = 0x2; // Symbolic symbol resolution required
public static final int DF_TEXTREL = 0x4; // Text relocations exist
@@ -114,12 +123,18 @@ public class ElfDynamicType {
"DT_ANDROID_REL", "Address of Rel relocs", ElfDynamicValueType.ADDRESS);
public static ElfDynamicType DT_ANDROID_RELSZ = addDefaultDynamicType(0x60000010,
"DT_ANDROID_RELSZ", "Total size of Rel relocs", ElfDynamicValueType.VALUE);
-
public static ElfDynamicType DT_ANDROID_RELA = addDefaultDynamicType(0x60000011,
"DT_ANDROID_RELA", "Address of Rela relocs", ElfDynamicValueType.ADDRESS);
public static ElfDynamicType DT_ANDROID_RELASZ = addDefaultDynamicType(0x60000012,
"DT_ANDROID_RELASZ", "Total size of Rela relocs", ElfDynamicValueType.VALUE);
+ public static ElfDynamicType DT_ANDROID_RELR = addDefaultDynamicType(0x6FFFE000,
+ "DT_ANDROID_RELR", "Address of Relr relocs", ElfDynamicValueType.ADDRESS);
+ public static ElfDynamicType DT_ANDROID_RELRSZ = addDefaultDynamicType(0x6FFFE001,
+ "DT_ANDROID_RELSZ", "Total size of Relr relocs", ElfDynamicValueType.VALUE);
+ public static ElfDynamicType DT_ANDROID_RELRENT = addDefaultDynamicType(0x6FFFE003,
+ "DT_ANDROID_RELSZ", "Size of Relr relocation entry", ElfDynamicValueType.VALUE);
+
// Value Range (??): 0x6ffffd00 - 0x6ffffdff
public static ElfDynamicType DT_GNU_PRELINKED = addDefaultDynamicType(0x6ffffdf5,
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfHeader.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfHeader.java
index 9d1e2dc423..72cb9c1009 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfHeader.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfHeader.java
@@ -372,6 +372,13 @@ public class ElfHeader implements StructConverter, Writeable {
parseDynamicRelocTable(relocationTableList, ElfDynamicType.DT_ANDROID_RELA, null,
ElfDynamicType.DT_ANDROID_RELASZ, true);
+ // TODO:
+// parseDynamicRelocTable(relocationTableList, ElfDynamicType.DT_RELR,
+// ElfDynamicType.DT_RELRENT, ElfDynamicType.DT_RELRSZ, false);
+//
+// parseDynamicRelocTable(relocationTableList, ElfDynamicType.DT_ANDROID_RELR,
+// ElfDynamicType.DT_ANDROID_RELRENT, ElfDynamicType.DT_ANDROID_RELRSZ, false);
+
parseJMPRelocTable(relocationTableList);
// In general the above dynamic relocation tables should cover most cases, we will
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfRelocation.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfRelocation.java
index 0a403ce15d..634b9d7c49 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfRelocation.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfRelocation.java
@@ -38,29 +38,37 @@ import ghidra.util.exception.AssertException;
*
* REL entry:
*
- * typedef struct {
- * Elf32_Addr r_offset;
- * Elf32_Word r_info;
- * } Elf32_Rel;
+ * typedef struct {
+ * Elf32_Addr r_offset;
+ * Elf32_Word r_info;
+ * } Elf32_Rel;
*
- * typedef struct {
- * Elf64_Addr r_offset;
- * Elf64_Xword r_info;
- * } Elf64_Rel;
+ * typedef struct {
+ * Elf64_Addr r_offset;
+ * Elf64_Xword r_info;
+ * } Elf64_Rel;
*
* RELA entry with addend:
*
- * * typedef struct {
- * Elf32_Addr r_offset;
- * Elf32_Word r_info;
- * Elf32_Sword r_addend;
- * } Elf32_Rela;
+ * typedef struct {
+ * Elf32_Addr r_offset;
+ * Elf32_Word r_info;
+ * Elf32_Sword r_addend;
+ * } Elf32_Rela;
*
- * typedef struct {
- * Elf64_Addr r_offset; //Address
- * Elf64_Xword r_info; //Relocation type and symbol index
- * Elf64_Sxword r_addend; //Addend
- * } Elf64_Rela;
+ * typedef struct {
+ * Elf64_Addr r_offset; //Address
+ * Elf64_Xword r_info; //Relocation type and symbol index
+ * Elf64_Sxword r_addend; //Addend
+ * } Elf64_Rela;
+ *
+ * RELR entry (see SHT_RELR, DT_RELR):
+ * NOTE: Relocation type is implied as Relative with addend stored at relocation offset.
+ * The specific relocation type wil need to be obtained from processor extension.
+ *
+ * typedef Elf32_Word Elf32_Relr;
+ *
+ * typedef Elf64_Xword Elf64_Relr;
*
* </pre>
*/
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfSectionHeaderConstants.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfSectionHeaderConstants.java
index dc9507b934..7745852af8 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfSectionHeaderConstants.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfSectionHeaderConstants.java
@@ -108,6 +108,8 @@ public class ElfSectionHeaderConstants {
public static final int SHT_GROUP = 17;
/**Extended section indeces*/
public static final int SHT_SYMTAB_SHNDX = 18;
+ /**Experimental support - see proposal at https://groups.google.com/forum/#!topic/generic-abi/bX460iggiKg */
+ public static final int SHT_RELR = 19;
// OS Specific Section Types
@@ -116,6 +118,9 @@ public class ElfSectionHeaderConstants {
/**Android relocation entries with explicit addends*/
public static final int SHT_ANDROID_RELA = 0x60000002;
+ /**Android's experimental support for SHT_RELR sections (see above) */
+ public static final int SHT_ANDROID_RELR = 0x6fffff00;
+
/**Object attributes */
public static final int SHT_GNU_ATTRIBUTES = 0x6ffffff5;
/**GNU-style hash table */