diff --git a/llvm/tools/llvm-vtabledump/llvm-vtabledump.cpp b/llvm/tools/llvm-vtabledump/llvm-vtabledump.cpp index 95803a370829..5b96d8070576 100644 --- a/llvm/tools/llvm-vtabledump/llvm-vtabledump.cpp +++ b/llvm/tools/llvm-vtabledump/llvm-vtabledump.cpp @@ -107,23 +107,23 @@ static bool collectRelocationOffsets( static void dumpVTables(const ObjectFile *Obj) { struct CompleteObjectLocator { StringRef Symbols[2]; - ArrayRef Data; + ArrayRef Data; }; struct ClassHierarchyDescriptor { StringRef Symbols[1]; - ArrayRef Data; + ArrayRef Data; }; struct BaseClassDescriptor { StringRef Symbols[2]; - ArrayRef Data; + ArrayRef Data; }; struct TypeDescriptor { StringRef Symbols[1]; - ArrayRef Data; + uint64_t AlwaysZero; StringRef MangledName; }; std::map, StringRef> VFTableEntries; - std::map> VBTables; + std::map> VBTables; std::map COLs; std::map CHDs; std::map, StringRef> BCAEntries; @@ -158,9 +158,9 @@ static void dumpVTables(const ObjectFile *Obj) { if (error(SecI->getContents(SecContents))) return; - ArrayRef VBTableData( - reinterpret_cast(SecContents.data()), - SecContents.size() / sizeof(aligned_little32_t)); + ArrayRef VBTableData( + reinterpret_cast(SecContents.data()), + SecContents.size() / sizeof(little32_t)); VBTables[SymName] = VBTableData; } // Complete object locators in the MS-ABI start with '??_R4' @@ -172,8 +172,8 @@ static void dumpVTables(const ObjectFile *Obj) { if (error(SecI->getContents(SecContents))) return; CompleteObjectLocator COL; - COL.Data = ArrayRef( - reinterpret_cast(SecContents.data()), 3); + COL.Data = ArrayRef( + reinterpret_cast(SecContents.data()), 3); StringRef *I = std::begin(COL.Symbols), *E = std::end(COL.Symbols); if (collectRelocatedSymbols(Obj, SecI, I, E)) return; @@ -188,8 +188,8 @@ static void dumpVTables(const ObjectFile *Obj) { if (error(SecI->getContents(SecContents))) return; ClassHierarchyDescriptor CHD; - CHD.Data = ArrayRef( - reinterpret_cast(SecContents.data()), 3); + CHD.Data = ArrayRef( + reinterpret_cast(SecContents.data()), 3); StringRef *I = std::begin(CHD.Symbols), *E = std::end(CHD.Symbols); if (collectRelocatedSymbols(Obj, SecI, I, E)) return; @@ -215,8 +215,8 @@ static void dumpVTables(const ObjectFile *Obj) { if (error(SecI->getContents(SecContents))) return; BaseClassDescriptor BCD; - BCD.Data = ArrayRef( - reinterpret_cast(SecContents.data()) + 1, + BCD.Data = ArrayRef( + reinterpret_cast(SecContents.data()) + 1, 5); StringRef *I = std::begin(BCD.Symbols), *E = std::end(BCD.Symbols); if (collectRelocatedSymbols(Obj, SecI, I, E)) @@ -231,11 +231,14 @@ static void dumpVTables(const ObjectFile *Obj) { StringRef SecContents; if (error(SecI->getContents(SecContents))) return; + uint8_t BytesInAddress = Obj->getBytesInAddress(); + const char *DataPtr = + SecContents.drop_front(Obj->getBytesInAddress()).data(); TypeDescriptor TD; - TD.Data = makeArrayRef( - reinterpret_cast( - SecContents.drop_front(Obj->getBytesInAddress()).data()), - Obj->getBytesInAddress() / sizeof(aligned_little32_t)); + if (BytesInAddress == 8) + TD.AlwaysZero = *reinterpret_cast(DataPtr); + else + TD.AlwaysZero = *reinterpret_cast(DataPtr); TD.MangledName = SecContents.drop_front(Obj->getBytesInAddress() * 2); StringRef *I = std::begin(TD.Symbols), *E = std::end(TD.Symbols); if (collectRelocatedSymbols(Obj, SecI, I, E)) @@ -250,11 +253,11 @@ static void dumpVTables(const ObjectFile *Obj) { StringRef SymName = VFTableEntry.second; outs() << VFTableName << '[' << Offset << "]: " << SymName << '\n'; } - for (const std::pair> &VBTable : + for (const std::pair> &VBTable : VBTables) { StringRef VBTableName = VBTable.first; uint32_t Idx = 0; - for (aligned_little32_t Offset : VBTable.second) { + for (little32_t Offset : VBTable.second) { outs() << VBTableName << '[' << Idx << "]: " << Offset << '\n'; Idx += sizeof(Offset); } @@ -298,10 +301,7 @@ static void dumpVTables(const ObjectFile *Obj) { StringRef TDName = TDPair.first; const TypeDescriptor &TD = TDPair.second; outs() << TDName << "[VFPtr]: " << TD.Symbols[0] << '\n'; - uint32_t AlwaysZero = 0; - for (aligned_little32_t Data : TD.Data) - AlwaysZero |= Data; - outs() << TDName << "[AlwaysZero]: " << AlwaysZero << '\n'; + outs() << TDName << "[AlwaysZero]: " << TD.AlwaysZero << '\n'; outs() << TDName << "[MangledName]: "; outs().write_escaped(TD.MangledName.rtrim(StringRef("\0", 1)), /*UseHexEscapes=*/true)