[llvm] r216567 - [MCJIT] More endianness fixes for RuntimeDyldMachO.
Lang Hames
lhames at gmail.com
Wed Aug 27 10:41:06 PDT 2014
Author: lhames
Date: Wed Aug 27 12:41:06 2014
New Revision: 216567
URL: http://llvm.org/viewvc/llvm-project?rev=216567&view=rev
Log:
[MCJIT] More endianness fixes for RuntimeDyldMachO.
http://llvm.org/PR20640
Modified:
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp?rev=216567&r1=216566&r2=216567&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp Wed Aug 27 12:41:06 2014
@@ -703,15 +703,18 @@ uint64_t RuntimeDyldCheckerImpl::readMem
unsigned Size) const {
uintptr_t PtrSizedAddr = static_cast<uintptr_t>(SrcAddr);
assert(PtrSizedAddr == SrcAddr && "Linker memory pointer out-of-range.");
- uint8_t *Src = reinterpret_cast<uint8_t *>(PtrSizedAddr);
uint64_t Result = 0;
+ uint8_t *Src = reinterpret_cast<uint8_t*>(PtrSizedAddr);
+ uint8_t *Dst = reinterpret_cast<uint8_t*>(&Result);
// If host and target endianness match use memcpy, otherwise copy in reverse
// order.
- if (getRTDyld().IsTargetLittleEndian == sys::IsLittleEndianHost)
- memcpy(&Result, Src, Size);
- else {
- uint8_t *Dst = reinterpret_cast<uint8_t*>(&Result) + Size - 1;
+ if (getRTDyld().IsTargetLittleEndian == sys::IsLittleEndianHost) {
+ if (!sys::IsLittleEndianHost)
+ Dst += sizeof(Result) - Size;
+ memcpy(Dst, Src, Size);
+ } else {
+ Dst += Size - 1;
for (unsigned i = 0; i < Size; ++i)
*Dst-- = *Src++;
}
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp?rev=216567&r1=216566&r2=216567&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp Wed Aug 27 12:41:06 2014
@@ -29,10 +29,21 @@ namespace llvm {
int64_t RuntimeDyldMachO::memcpyAddend(const RelocationEntry &RE) const {
const SectionEntry &Section = Sections[RE.SectionID];
- uint8_t *LocalAddress = Section.Address + RE.Offset;
unsigned NumBytes = 1 << RE.Size;
int64_t Addend = 0;
- memcpy(&Addend, LocalAddress, NumBytes);
+ uint8_t *LocalAddress = Section.Address + RE.Offset;
+ uint8_t *Dst = reinterpret_cast<uint8_t*>(&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;
}
@@ -113,13 +124,15 @@ void RuntimeDyldMachO::dumpRelocationToR
bool RuntimeDyldMachO::writeBytesUnaligned(uint8_t *Dst, uint64_t Value,
unsigned Size) {
-
+ uint8_t *Src = reinterpret_cast<uint8_t*>(&Value);
// If host and target endianness match use memcpy, otherwise copy in reverse
// order.
- if (IsTargetLittleEndian == sys::IsLittleEndianHost)
- memcpy(Dst, &Value, Size);
- else {
- uint8_t *Src = reinterpret_cast<uint8_t*>(&Value) + Size - 1;
+ 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--;
}
More information about the llvm-commits
mailing list