[MCJIT] Fix some more RuntimeDyld debugging output format specifiers.
[oota-llvm.git] / lib / ExecutionEngine / RuntimeDyld / RuntimeDyld.cpp
index 06359b7f02be68588a28d0bb6b10b0cbef0a7dd5..65110752e6c2b6fdab8d585dc614edee4390a6dd 100644 (file)
@@ -50,11 +50,11 @@ static void dumpSectionMemory(const SectionEntry &S, StringRef State) {
   uint8_t *DataAddr = S.Address;
   uint64_t LoadAddr = S.LoadAddress;
 
-  unsigned StartPadding = LoadAddr & 7;
+  unsigned StartPadding = LoadAddr & (ColsPerRow - 1);
   unsigned BytesRemaining = S.Size;
 
   if (StartPadding) {
-    dbgs() << "\n" << format("0x%08x", LoadAddr & ~(ColsPerRow - 1)) << ":";
+    dbgs() << "\n" << format("0x%016" PRIx64, LoadAddr & ~(ColsPerRow - 1)) << ":";
     while (StartPadding--)
       dbgs() << "   ";
   }
@@ -398,32 +398,30 @@ unsigned RuntimeDyldImpl::computeSectionStubBufSize(ObjectImage &Obj,
 uint64_t RuntimeDyldImpl::readBytesUnaligned(uint8_t *Src,
                                              unsigned Size) const {
   uint64_t Result = 0;
-  uint8_t *Dst = reinterpret_cast<uint8_t*>(&Result);
-
-  if (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++;
-  }
+  if (IsTargetLittleEndian) {
+    Src += Size - 1;
+    while (Size--)
+      Result = (Result << 8) | *Src--;
+  } else
+    while (Size--)
+      Result = (Result << 8) | *Src++;
 
   return Result;
 }
 
 void RuntimeDyldImpl::writeBytesUnaligned(uint64_t Value, uint8_t *Dst,
                                           unsigned Size) const {
-  uint8_t *Src = reinterpret_cast<uint8_t*>(&Value);
-  if (IsTargetLittleEndian == sys::IsLittleEndianHost) {
-    if (!sys::IsLittleEndianHost)
-      Src += sizeof(Value) - Size;
-    memcpy(Dst, Src, Size);
+  if (IsTargetLittleEndian) {
+    while (Size--) {
+      *Dst++ = Value & 0xFF;
+      Value >>= 8;
+    }
   } else {
-    Src += Size - 1;
-    for (unsigned i = 0; i < Size; ++i)
-      *Dst++ = *Src--;
+    Dst += Size - 1;
+    while (Size--) {
+      *Dst-- = Value & 0xFF;
+      Value >>= 8;
+    }
   }
 }
 
@@ -697,8 +695,8 @@ void RuntimeDyldImpl::reassignSectionAddress(unsigned SectionID,
   // "big enough" type.
   DEBUG(dbgs() << "Reassigning address for section "
                << SectionID << " (" << Sections[SectionID].Name << "): "
-               << format("0x%016x", Sections[SectionID].LoadAddress) << " -> "
-               << format("0x%016x", Addr) << "\n");
+               << format("0x%016" PRIx64, Sections[SectionID].LoadAddress) << " -> "
+               << format("0x%016" PRIx64, Addr) << "\n");
   Sections[SectionID].LoadAddress = Addr;
 }