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: [email protected]
          Reporter: [email protected]
                CC: [email protected]

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.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to