[llvm] r180767 - Collect the Addend for external relocs.

Rafael Espindola rafael.espindola at gmail.com
Mon Apr 29 18:29:58 PDT 2013


Author: rafael
Date: Mon Apr 29 20:29:57 2013
New Revision: 180767

URL: http://llvm.org/viewvc/llvm-project?rev=180767&view=rev
Log:
Collect the Addend for external relocs.

This fixes 2013-04-04-RelocAddend.ll. We don't have a testcase for non external
relocs with an Addend. I will try to write one.

Modified:
    llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp
    llvm/trunk/test/ExecutionEngine/MCJIT/2013-04-04-RelocAddend.ll

Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp?rev=180767&r1=180766&r2=180767&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp Mon Apr 29 20:29:57 2013
@@ -230,7 +230,14 @@ void RuntimeDyldMachO::processRelocation
   bool isExtern = MachO->getPlainRelocationExternal(RE);
   bool IsPCRel = MachO->getAnyRelocationPCRel(RE);
   unsigned Size = MachO->getAnyRelocationLength(RE);
+  uint64_t Offset;
+  RelI.getOffset(Offset);
   if (isExtern) {
+    uint8_t *LocalAddress = Section.Address + Offset;
+    unsigned NumBytes = 1 << Size;
+    uint64_t Addend = 0;
+    memcpy(&Addend, LocalAddress, NumBytes);
+
     // Obtain the symbol name which is referenced in the relocation
     SymbolRef Symbol;
     RelI.getSymbol(Symbol);
@@ -240,15 +247,17 @@ void RuntimeDyldMachO::processRelocation
     SymbolTableMap::const_iterator lsi = Symbols.find(TargetName.data());
     if (lsi != Symbols.end()) {
       Value.SectionID = lsi->second.first;
-      Value.Addend = lsi->second.second;
+      Value.Addend = lsi->second.second + Addend;
     } else {
       // Search for the symbol in the global symbol table
       SymbolTableMap::const_iterator gsi = GlobalSymbolTable.find(TargetName.data());
       if (gsi != GlobalSymbolTable.end()) {
         Value.SectionID = gsi->second.first;
-        Value.Addend = gsi->second.second;
-      } else
+        Value.Addend = gsi->second.second + Addend;
+      } else {
         Value.SymbolName = TargetName.data();
+        Value.Addend = Addend;
+      }
     }
   } else {
     error_code err;
@@ -276,8 +285,6 @@ void RuntimeDyldMachO::processRelocation
     }
   }
 
-  uint64_t Offset;
-  RelI.getOffset(Offset);
   if (Arch == Triple::arm && (RelType & 0xf) == macho::RIT_ARM_Branch24Bit) {
     // This is an ARM branch relocation, need to use a stub function.
 

Modified: llvm/trunk/test/ExecutionEngine/MCJIT/2013-04-04-RelocAddend.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/MCJIT/2013-04-04-RelocAddend.ll?rev=180767&r1=180766&r2=180767&view=diff
==============================================================================
--- llvm/trunk/test/ExecutionEngine/MCJIT/2013-04-04-RelocAddend.ll (original)
+++ llvm/trunk/test/ExecutionEngine/MCJIT/2013-04-04-RelocAddend.ll Mon Apr 29 20:29:57 2013
@@ -1,5 +1,4 @@
 ; RUN: %lli_mcjit %s
-; XFAIL: darwin
 ;
 ; Verify relocations to global symbols with addend work correctly.
 ;





More information about the llvm-commits mailing list