From: Eli Bendersky Date: Sun, 5 Jan 2014 23:53:46 +0000 (-0800) Subject: Issue #20: don't fail on relocations creating out-of-bounds values. X-Git-Tag: v0.22~11 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=af0d723b84995d62821a020f6568968ba59e0eae;p=pyelftools.git 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? --- 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: