X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FExecutionEngine%2FRuntimeDyld%2FRuntimeDyldMachO.cpp;h=9e4d3ac82afb3d21cd86cf60a244d572fc580b34;hb=34ea0a1de3dc93dd0e586c9d68db7ad400ce623e;hp=aba67f2e69e02da6661e2b60bd75cb9148259c7b;hpb=e8cfb5988ff42f7c03f1f722b8a8d018e978bcd0;p=oota-llvm.git diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp index aba67f2e69e..9e4d3ac82af 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp @@ -27,10 +27,23 @@ using namespace llvm::object; namespace llvm { -uint64_t RuntimeDyldMachO::decodeAddend(uint8_t *LocalAddress, unsigned NumBytes, - uint32_t RelType) const { - uint64_t Addend = 0; - memcpy(&Addend, LocalAddress, NumBytes); +int64_t RuntimeDyldMachO::memcpyAddend(const RelocationEntry &RE) const { + const SectionEntry &Section = Sections[RE.SectionID]; + unsigned NumBytes = 1 << RE.Size; + int64_t Addend = 0; + uint8_t *LocalAddress = Section.Address + RE.Offset; + uint8_t *Dst = reinterpret_cast(&Addend); + + if (IsTargetLittleEndian == sys::IsLittleEndianHost) { + if (!sys::IsLittleEndianHost) + Dst += sizeof(Addend) - NumBytes; + memcpy(Dst, LocalAddress, NumBytes); + } else { + Dst += NumBytes - 1; + for (unsigned i = 0; i < NumBytes; ++i) + *Dst-- = *LocalAddress++; + } + return Addend; } @@ -79,7 +92,8 @@ RelocationValueRef RuntimeDyldMachO::getRelocationValueRef( void RuntimeDyldMachO::makeValueAddendPCRel(RelocationValueRef &Value, ObjectImage &ObjImg, - const relocation_iterator &RI) { + const relocation_iterator &RI, + unsigned OffsetToNextPC) { const MachOObjectFile &Obj = static_cast(*ObjImg.getObjectFile()); MachO::any_relocation_info RelInfo = @@ -89,8 +103,7 @@ void RuntimeDyldMachO::makeValueAddendPCRel(RelocationValueRef &Value, if (IsPCRel) { uint64_t RelocAddr = 0; RI->getAddress(RelocAddr); - unsigned RelocSize = Obj.getAnyRelocationLength(RelInfo); - Value.Addend += RelocAddr + (1 << RelocSize); + Value.Addend += RelocAddr + OffsetToNextPC; } } @@ -102,17 +115,26 @@ void RuntimeDyldMachO::dumpRelocationToResolve(const RelocationEntry &RE, dbgs() << "resolveRelocation Section: " << RE.SectionID << " LocalAddress: " << format("%p", LocalAddress) - << " FinalAddress: " << format("%p", FinalAddress) - << " Value: " << format("%p", Value) << " Addend: " << RE.Addend + << " FinalAddress: " << format("0x%x", FinalAddress) + << " Value: " << format("0x%x", Value) << " Addend: " << RE.Addend << " isPCRel: " << RE.IsPCRel << " MachoType: " << RE.RelType << " Size: " << (1 << RE.Size) << "\n"; } -bool RuntimeDyldMachO::writeBytesUnaligned(uint8_t *Addr, uint64_t Value, +bool RuntimeDyldMachO::writeBytesUnaligned(uint8_t *Dst, uint64_t Value, unsigned Size) { - for (unsigned i = 0; i < Size; ++i) { - *Addr++ = (uint8_t)Value; - Value >>= 8; + + uint8_t *Src = reinterpret_cast(&Value); + // If host and target endianness match use memcpy, otherwise copy in reverse + // order. + if (IsTargetLittleEndian == sys::IsLittleEndianHost) { + if (!sys::IsLittleEndianHost) + Src += sizeof(Value) - Size; + memcpy(Dst, Src, Size); + } else { + Src += Size - 1; + for (unsigned i = 0; i < Size; ++i) + *Dst++ = *Src--; } return false; @@ -214,7 +236,7 @@ llvm::RuntimeDyldMachO::create(Triple::ArchType Arch, RTDyldMemoryManager *MM) { llvm_unreachable("Unsupported target for RuntimeDyldMachO."); break; case Triple::arm: return make_unique(MM); - case Triple::arm64: return make_unique(MM); + case Triple::aarch64: return make_unique(MM); case Triple::x86: return make_unique(MM); case Triple::x86_64: return make_unique(MM); }