[PATCH] [MC] [MachO] Check for overflow of scattered relocations on ARM

Jevin Sweval jevinsweval at gmail.com
Fri Apr 25 13:13:30 PDT 2014


MachO scattered relocations can only store 24 bits (16 MB) of offset.
If a section is over 16 MB, there is simply no way to represent a
scattered relocation. i386 already checked for this but ARM didn't. It
led to a difficult bug where ld64 applied an overflowed relocation to
ldr/blx instructions, corrupting the instructions and confusing ld64.

This patch adds the same check that i386 does to ARM. It provides test
cases for ARM and i386 (not tested prior) and changes the i386 error
reporting to use Twine::utohexstr instead of format()ing into a char[]
buffer.

The error check for ARM is more conservative than the one for i386. In
i386, the code seems to indicate that the overflow may not be an issue
but also that it could still confuse ld.

X86MachObjectWritter.cpp:427
    // If the offset is more than 24-bits, it won't fit in a scattered
    // relocation offset field, so we fall back to using a non-scattered
    // relocation. This is a bit risky, as if the offset reaches out of
    // the block and the linker is doing scattered loading on this
    // symbol, things can go badly.
    //
    // Required for 'as' compatibility.
    if (FixupOffset > 0xffffff) {
      FixedValue = OriginalFixedValue;
      return false;
    }

Should LLVM emit potentially invalid i386 MachO files or should that
condition error as well?

I don't have commit access, if this LGTEveryone, can someone please
commit on my behalf?

Cheers,
Jevin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: macho-scattered-reloc-overflow.patch
Type: application/octet-stream
Size: 5425 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140425/82b41dd7/attachment.obj>


More information about the llvm-commits mailing list