[llvm-bugs] [Bug 38620] New: ARM: Incorrect COFF relocation type for thumb bl instruction

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Aug 17 16:35:19 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=38620

            Bug ID: 38620
           Summary: ARM: Incorrect COFF relocation type for thumb bl
                    instruction
           Product: libraries
           Version: 6.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: ARM
          Assignee: unassignedbugs at nondot.org
          Reporter: jordanrh at microsoft.com
                CC: llvm-bugs at lists.llvm.org

LLVM generates incorrect relocation entry for thumb BL instruction, which
causes the instruction to be overwritten by a BLX instruction at load time.

In lib/Target/ARM/MCTargetDesc/ARMWinCOFFObjectWriter.cpp :
ARMWinCOFFObjectWriter::getRelocType(),

  case ARM::fixup_t2_condbranch:
    return COFF::IMAGE_REL_ARM_BRANCH20T;
  case ARM::fixup_t2_uncondbranch:
    return COFF::IMAGE_REL_ARM_BRANCH24T;
  case ARM::fixup_arm_thumb_bl:   <--- BLX23T is wrong relocation type for this
instruction
  case ARM::fixup_arm_thumb_blx:
    return COFF::IMAGE_REL_ARM_BLX23T;

fixup_arm_thumb_bl should return COFF::IMAGE_REL_ARM_BRANCH24T.

Here are the descriptions of the relocation types from
https://docs.microsoft.com/en-us/windows/desktop/debug/pe-format#arm-processors.

IMAGE_REL_THUMB_BRANCH24
0x0014
The instruction is fixed up with the 25-bit relative displacement to the 2-byte
aligned target. The least significant bit of the displacement is zero and is
not stored.This relocation corresponds to a Thumb-2 B instruction. 

IMAGE_REL_THUMB_BLX23 
0x0015
The instruction is fixed up with the 25-bit relative displacement to the 4-byte
aligned target. The low 2 bits of the displacement are zero and are not stored. 
This relocation corresponds to a Thumb-2 BLX instruction.

This bug manifested when porting the rust compiler to thumbv7a-pc-windows-msvc.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180817/62a4dae2/attachment.html>


More information about the llvm-bugs mailing list