diff options
author | Lang Hames <lhames@gmail.com> | 2014-08-18 21:43:16 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2014-08-18 21:43:16 +0000 |
commit | 4f867bfada573f775e22c7564abe5502f1665a67 (patch) | |
tree | 9045c29307168c1eb7cc1712c10bfddd92feacef /llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp | |
parent | baac2afccf744a7274553a1ea0df5b40e1bcfa63 (diff) | |
download | bcm5719-llvm-4f867bfada573f775e22c7564abe5502f1665a67.tar.gz bcm5719-llvm-4f867bfada573f775e22c7564abe5502f1665a67.zip |
[MCJIT] Respect target endianness in RuntimeDyldMachO and RuntimeDyldChecker.
This patch may address some of the issues described in http://llvm.org/PR20640.
llvm-svn: 215938
Diffstat (limited to 'llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp')
-rw-r--r-- | llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp index 986daef8a90..3e27a8b8d55 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp @@ -110,11 +110,18 @@ void RuntimeDyldMachO::dumpRelocationToResolve(const RelocationEntry &RE, << " 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; |