[RuntimeDyld] Fix MachO i386 SECTDIFF relocation to support non-zero addends.
authorLang Hames <lhames@gmail.com>
Wed, 27 May 2015 20:50:01 +0000 (20:50 +0000)
committerLang Hames <lhames@gmail.com>
Wed, 27 May 2015 20:50:01 +0000 (20:50 +0000)
Previously, relocations of the form 'A - B + C' would fail on i386 when C was
non-zero.

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

lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h
test/ExecutionEngine/RuntimeDyld/X86/MachO_i386_DynNoPIC_relocations.s

index 053f90c..dd454ae 100644 (file)
@@ -167,20 +167,19 @@ private:
     uint32_t SectionBID =
         findOrEmitSection(Obj, SectionB, IsCode, ObjSectionToID);
 
     uint32_t SectionBID =
         findOrEmitSection(Obj, SectionB, IsCode, ObjSectionToID);
 
-    if (Addend != AddrA - AddrB)
-      Error("Unexpected SECTDIFF relocation addend.");
+    // Compute the addend 'C' from the original expression 'A - B + C'.
+    Addend -= AddrA - AddrB;
 
     DEBUG(dbgs() << "Found SECTDIFF: AddrA: " << AddrA << ", AddrB: " << AddrB
                  << ", Addend: " << Addend << ", SectionA ID: " << SectionAID
                  << ", SectionAOffset: " << SectionAOffset
                  << ", SectionB ID: " << SectionBID
                  << ", SectionBOffset: " << SectionBOffset << "\n");
 
     DEBUG(dbgs() << "Found SECTDIFF: AddrA: " << AddrA << ", AddrB: " << AddrB
                  << ", Addend: " << Addend << ", SectionA ID: " << SectionAID
                  << ", SectionAOffset: " << SectionAOffset
                  << ", SectionB ID: " << SectionBID
                  << ", SectionBOffset: " << SectionBOffset << "\n");
-    RelocationEntry R(SectionID, Offset, RelocType, 0, SectionAID,
-                      SectionAOffset, SectionBID, SectionBOffset, IsPCRel,
-                      Size);
+    RelocationEntry R(SectionID, Offset, RelocType, Addend, SectionAID,
+                      SectionAOffset, SectionBID, SectionBOffset,
+                      IsPCRel, Size);
 
     addRelocationForSection(R, SectionAID);
 
     addRelocationForSection(R, SectionAID);
-    addRelocationForSection(R, SectionBID);
 
     return ++RelI;
   }
 
     return ++RelI;
   }
index f427b98..6b2fe95 100644 (file)
@@ -9,9 +9,9 @@ bar:
 tmp0$pb:
        popl    %eax
 # Test section difference relocation to non-lazy ptr section.
 tmp0$pb:
        popl    %eax
 # Test section difference relocation to non-lazy ptr section.
-# rtdyld-check: decode_operand(inst1, 4) = x$non_lazy_ptr - tmp0$pb
+# rtdyld-check: decode_operand(inst1, 4) = x$non_lazy_ptr - tmp0$pb + 8
 inst1:
 inst1:
-       movl    x$non_lazy_ptr-tmp0$pb(%eax), %eax
+       movl    (x$non_lazy_ptr-tmp0$pb)+8(%eax), %eax
         movl    (%eax), %ebx
 
 # Test VANILLA relocation to jump table.
         movl    (%eax), %ebx
 
 # Test VANILLA relocation to jump table.