pyelftools icon indicating copy to clipboard operation
pyelftools copied to clipboard

ARM relocation seems incorrect & incomplete

Open denisbohm opened this issue 4 years ago • 1 comments

  1. R_ARM_ABS32 relocations were producing values more than double the correct value. I believe they should use _reloc_calc_identity rather than _reloc_calc_sym_plus_value.

  2. R_ARM_NONE is not handled and causes an exception.

I made the following modifications to a local copy and an getting correct values for R_ARM_ABS32 relocations now and no exceptions:


diff --git a/elftools/elf/relocation.py b/elftools/elf/relocation.py
index 8ca4ca1..6bf3389 100644
--- a/elftools/elf/relocation.py
+++ b/elftools/elf/relocation.py
@@ -245,9 +245,12 @@ class RelocationHandler(object):
         return sym_value // 4 + value - offset // 4
 
     _RELOCATION_RECIPES_ARM = {
+        ENUM_RELOC_TYPE_ARM['R_ARM_NONE']: _RELOCATION_RECIPE_TYPE(
+            bytesize=4, has_addend=False,
+            calc_func=_reloc_calc_identity),
         ENUM_RELOC_TYPE_ARM['R_ARM_ABS32']: _RELOCATION_RECIPE_TYPE(
             bytesize=4, has_addend=False,
-            calc_func=_reloc_calc_sym_plus_value),
+            calc_func=_reloc_calc_identity),
         ENUM_RELOC_TYPE_ARM['R_ARM_CALL']: _RELOCATION_RECIPE_TYPE(
             bytesize=4, has_addend=False,
             calc_func=_arm_reloc_calc_sym_plus_value_pcrel),

denisbohm avatar Jun 15 '21 17:06 denisbohm

Thanks. Could you create a PR for this? Please try to add a test that demonstrates the failures that are fixed by the change.

eliben avatar Jun 18 '21 14:06 eliben