[llvm] r215938 - [MCJIT] Respect target endianness in RuntimeDyldMachO and RuntimeDyldChecker.
Lang Hames
lhames at gmail.com
Mon Aug 18 14:43:17 PDT 2014
Author: lhames
Date: Mon Aug 18 16:43:16 2014
New Revision: 215938
URL: http://llvm.org/viewvc/llvm-project?rev=215938&view=rev
Log:
[MCJIT] Respect target endianness in RuntimeDyldMachO and RuntimeDyldChecker.
This patch may address some of the issues described in http://llvm.org/PR20640.
Modified:
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp?rev=215938&r1=215937&r2=215938&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp Mon Aug 18 16:43:16 2014
@@ -705,7 +705,16 @@ uint64_t RuntimeDyldCheckerImpl::readMem
assert(PtrSizedAddr == SrcAddr && "Linker memory pointer out-of-range.");
uint8_t *Src = reinterpret_cast<uint8_t *>(PtrSizedAddr);
uint64_t Result = 0;
- memcpy(&Result, Src, Size);
+
+ // 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;
+ for (unsigned i = 0; i < Size; ++i)
+ *Dst-- = *Src++;
+ }
return Result;
}
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp?rev=215938&r1=215937&r2=215938&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp Mon Aug 18 16:43:16 2014
@@ -110,11 +110,18 @@ void RuntimeDyldMachO::dumpRelocationToR
<< " 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;
+
+
+ // 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;
+ for (unsigned i = 0; i < Size; ++i)
+ *Dst++ = *Src--;
}
return false;
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h?rev=215938&r1=215937&r2=215938&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h Mon Aug 18 16:43:16 2014
@@ -119,7 +119,7 @@ public:
/// Write the least significant 'Size' bytes in 'Value' out at the address
/// pointed to by Addr. Check for overflow.
- bool writeBytesUnaligned(uint8_t *Addr, uint64_t Value, unsigned Size);
+ bool writeBytesUnaligned(uint8_t *Dst, uint64_t Value, unsigned Size);
SectionEntry &getSection(unsigned SectionID) { return Sections[SectionID]; }
More information about the llvm-commits
mailing list