From af0d723b84995d62821a020f6568968ba59e0eae Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Sun, 5 Jan 2014 15:53:46 -0800 Subject: [PATCH] Issue #20: don't fail on relocations creating out-of-bounds values. This came up with some very large object files. The solution (wrap around at value size) doesn't feel good, but it appears to be the way binutils does it too. Are there legitimate cases for this? --- elftools/elf/relocation.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/elftools/elf/relocation.py b/elftools/elf/relocation.py index 4ae73d7..176f7c5 100644 --- a/elftools/elf/relocation.py +++ b/elftools/elf/relocation.py @@ -178,6 +178,11 @@ class RelocationHandler(object): addend=reloc['r_addend'] if recipe.has_addend else 0) # 3. Write the relocated value back into the stream stream.seek(reloc['r_offset']) + + # Make sure the relocated value fits back by wrapping it around. This + # looks like a problem, but it seems to be the way this is done in + # binutils too. + relocated_value = relocated_value % (2 ** (recipe.bytesize * 8)) value_struct.build_stream(relocated_value, stream) # Relocations are represented by "recipes". Each recipe specifies: -- 2.30.2