diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-04-30 01:29:57 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-04-30 01:29:57 +0000 |
commit | 8e6e02a41bd21f8e919e812dbd7aa9ed5474bdbf (patch) | |
tree | cff3a02ed7a51de9ccc0634cccfec23a157b3fa5 | |
parent | 4fb224e3bd7655e25bc1f43d05a0922098aae4e0 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180767 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp | 17 | ||||
-rw-r--r-- | test/ExecutionEngine/MCJIT/2013-04-04-RelocAddend.ll | 1 |
2 files changed, 12 insertions, 6 deletions
diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp index ddac59fd36..6054b2ab79 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp @@ -230,7 +230,14 @@ void RuntimeDyldMachO::processRelocationRef(unsigned SectionID, 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::processRelocationRef(unsigned SectionID, 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::processRelocationRef(unsigned SectionID, } } - 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. diff --git a/test/ExecutionEngine/MCJIT/2013-04-04-RelocAddend.ll b/test/ExecutionEngine/MCJIT/2013-04-04-RelocAddend.ll index d2f31bb33c..3f402c5931 100644 --- a/test/ExecutionEngine/MCJIT/2013-04-04-RelocAddend.ll +++ b/test/ExecutionEngine/MCJIT/2013-04-04-RelocAddend.ll @@ -1,5 +1,4 @@ ; RUN: %lli_mcjit %s -; XFAIL: darwin ; ; Verify relocations to global symbols with addend work correctly. ; |