OSDN Git Service

[SystemZ] Fix applyFixup for 12-bit fixups
authorUlrich Weigand <ulrich.weigand@de.ibm.com>
Thu, 1 Dec 2016 17:10:27 +0000 (17:10 +0000)
committerUlrich Weigand <ulrich.weigand@de.ibm.com>
Thu, 1 Dec 2016 17:10:27 +0000 (17:10 +0000)
Now that we have fixups that only fill parts of a byte, it turns
out we have to mask off the bits outside the fixup area when
applying them.  Failing to do so caused invalid object code to
be emitted for bprp with a negative 12-bit displacement.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288374 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmBackend.cpp

index 5a34095..1f3cdde 100644 (file)
@@ -94,12 +94,14 @@ void SystemZMCAsmBackend::applyFixup(const MCFixup &Fixup, char *Data,
                                      bool IsPCRel) const {
   MCFixupKind Kind = Fixup.getKind();
   unsigned Offset = Fixup.getOffset();
-  unsigned Size = (getFixupKindInfo(Kind).TargetSize + 7) / 8;
+  unsigned BitSize = getFixupKindInfo(Kind).TargetSize;
+  unsigned Size = (BitSize + 7) / 8;
 
   assert(Offset + Size <= DataSize && "Invalid fixup offset!");
 
   // Big-endian insertion of Size bytes.
   Value = extractBitsForFixup(Kind, Value);
+  Value &= ((uint64_t)1 << BitSize) - 1;
   unsigned ShiftValue = (Size * 8) - 8;
   for (unsigned I = 0; I != Size; ++I) {
     Data[Offset + I] |= uint8_t(Value >> ShiftValue);