Fixing some host==target assumptions in RuntimeDyld
authorAndrew Kaylor <andrew.kaylor@intel.com>
Tue, 15 Oct 2013 20:44:55 +0000 (20:44 +0000)
committerAndrew Kaylor <andrew.kaylor@intel.com>
Tue, 15 Oct 2013 20:44:55 +0000 (20:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@192732 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h

index 1b9e0bf035ff5e39fb3a9bc3e08b47318cf0e084..f04f8c29f666436e21387249df7670ec7017d389 100644 (file)
@@ -74,7 +74,9 @@ ObjectImage *RuntimeDyldImpl::loadObject(ObjectBuffer *InputBuffer) {
   if (!obj)
     report_fatal_error("Unable to create object image from memory buffer!");
 
+  // Save information about our target
   Arch = (Triple::ArchType)obj->getArch();
+  IsTargetLittleEndian = obj->getObjectFile()->isLittleEndian();
 
   // Symbols found in this object
   StringMap<SymbolLoc> LocalSymbols;
index 5796c7cd39f7f81b3ab755b752fdf1acf67cef21..b5f2991244f58c23db06f10048b1d6bf6c9412ab 100644 (file)
@@ -184,6 +184,7 @@ protected:
   typedef std::map<RelocationValueRef, uintptr_t> StubMap;
 
   Triple::ArchType Arch;
+  bool IsTargetLittleEndian;
 
   inline unsigned getMaxStubSize() {
     if (Arch == Triple::aarch64)
@@ -228,14 +229,14 @@ protected:
   }
 
   void writeInt16BE(uint8_t *Addr, uint16_t Value) {
-    if (sys::IsLittleEndianHost)
+    if (IsTargetLittleEndian)
       Value = sys::SwapByteOrder(Value);
     *Addr     = (Value >> 8) & 0xFF;
     *(Addr+1) = Value & 0xFF;
   }
 
   void writeInt32BE(uint8_t *Addr, uint32_t Value) {
-    if (sys::IsLittleEndianHost)
+    if (IsTargetLittleEndian)
       Value = sys::SwapByteOrder(Value);
     *Addr     = (Value >> 24) & 0xFF;
     *(Addr+1) = (Value >> 16) & 0xFF;
@@ -244,7 +245,7 @@ protected:
   }
 
   void writeInt64BE(uint8_t *Addr, uint64_t Value) {
-    if (sys::IsLittleEndianHost)
+    if (IsTargetLittleEndian)
       Value = sys::SwapByteOrder(Value);
     *Addr     = (Value >> 56) & 0xFF;
     *(Addr+1) = (Value >> 48) & 0xFF;