diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-05-08 17:12:57 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-05-08 17:12:57 +0000 |
commit | c46e6a5940c50058e00c0c5f9123fd82e338d29a (patch) | |
tree | 89a719d723035c54a190b1f81d329834f1f93336 /tools | |
parent | 148779df305667b6942fee7e758fdf81a6498f38 (diff) |
Notes
Diffstat (limited to 'tools')
-rw-r--r-- | tools/llvm-link/llvm-link.cpp | 2 | ||||
-rw-r--r-- | tools/llvm-lto/llvm-lto.cpp | 2 | ||||
-rw-r--r-- | tools/llvm-pdbdump/Analyze.cpp | 2 | ||||
-rw-r--r-- | tools/llvm-pdbdump/LLVMOutputStyle.cpp | 172 | ||||
-rw-r--r-- | tools/llvm-pdbdump/LLVMOutputStyle.h | 7 | ||||
-rw-r--r-- | tools/llvm-pdbdump/StreamUtil.cpp | 13 | ||||
-rw-r--r-- | tools/llvm-pdbdump/YAMLOutputStyle.cpp | 19 | ||||
-rw-r--r-- | tools/llvm-readobj/COFFDumper.cpp | 111 | ||||
-rw-r--r-- | tools/llvm-rtdyld/llvm-rtdyld.cpp | 23 | ||||
-rw-r--r-- | tools/obj2yaml/wasm2yaml.cpp | 19 | ||||
-rw-r--r-- | tools/yaml2obj/yaml2wasm.cpp | 46 |
11 files changed, 300 insertions, 116 deletions
diff --git a/tools/llvm-link/llvm-link.cpp b/tools/llvm-link/llvm-link.cpp index 27199d53538ec..568e5f8d2d585 100644 --- a/tools/llvm-link/llvm-link.cpp +++ b/tools/llvm-link/llvm-link.cpp @@ -300,7 +300,7 @@ static bool linkFiles(const char *argv0, LLVMContext &Context, Linker &L, // does not do the ThinLink that would normally determine what values to // promote. for (auto &I : *Index) { - for (auto &S : I.second) { + for (auto &S : I.second.SummaryList) { if (GlobalValue::isLocalLinkage(S->linkage())) S->setLinkage(GlobalValue::ExternalLinkage); } diff --git a/tools/llvm-lto/llvm-lto.cpp b/tools/llvm-lto/llvm-lto.cpp index 27e5c5e122c27..2458d3d123cac 100644 --- a/tools/llvm-lto/llvm-lto.cpp +++ b/tools/llvm-lto/llvm-lto.cpp @@ -284,7 +284,7 @@ void printIndexStats() { unsigned Calls = 0, Refs = 0, Functions = 0, Alias = 0, Globals = 0; for (auto &Summaries : *Index) { - for (auto &Summary : Summaries.second) { + for (auto &Summary : Summaries.second.SummaryList) { Refs += Summary->refs().size(); if (auto *FuncSummary = dyn_cast<FunctionSummary>(Summary.get())) { Functions++; diff --git a/tools/llvm-pdbdump/Analyze.cpp b/tools/llvm-pdbdump/Analyze.cpp index b65dd40d25ff1..f7d6ec53b030f 100644 --- a/tools/llvm-pdbdump/Analyze.cpp +++ b/tools/llvm-pdbdump/Analyze.cpp @@ -74,7 +74,7 @@ Error AnalysisStyle::dump() { if (!Tpi) return Tpi.takeError(); - TypeDatabase TypeDB; + TypeDatabase TypeDB(Tpi->getNumTypeRecords()); TypeDatabaseVisitor DBV(TypeDB); TypeDeserializer Deserializer; TypeVisitorCallbackPipeline Pipeline; diff --git a/tools/llvm-pdbdump/LLVMOutputStyle.cpp b/tools/llvm-pdbdump/LLVMOutputStyle.cpp index ec1325ff23356..2dd4ef0fb30de 100644 --- a/tools/llvm-pdbdump/LLVMOutputStyle.cpp +++ b/tools/llvm-pdbdump/LLVMOutputStyle.cpp @@ -39,6 +39,7 @@ #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/PublicsStream.h" #include "llvm/DebugInfo/PDB/Native/RawError.h" +#include "llvm/DebugInfo/PDB/Native/TpiHashing.h" #include "llvm/DebugInfo/PDB/Native/TpiStream.h" #include "llvm/DebugInfo/PDB/PDBExtras.h" #include "llvm/Object/COFF.h" @@ -609,11 +610,8 @@ Error LLVMOutputStyle::dumpTpiStream(uint32_t StreamIdx) { VerLabel = "IPI Version"; } - bool IsSilentDatabaseBuild = !DumpRecordBytes && !DumpRecords && !DumpTpiHash; - if (IsSilentDatabaseBuild) { - outs().flush(); - errs() << "Building Type Information For " << Label << "\n"; - } + if (!DumpRecordBytes && !DumpRecords && !DumpTpiHash) + return Error::success(); auto Tpi = (StreamIdx == StreamTPI) ? File.getPDBTpiStream() : File.getPDBIpiStream(); @@ -623,38 +621,43 @@ Error LLVMOutputStyle::dumpTpiStream(uint32_t StreamIdx) { std::unique_ptr<DictScope> StreamScope; std::unique_ptr<ListScope> RecordScope; - if (!IsSilentDatabaseBuild) { - StreamScope = llvm::make_unique<DictScope>(P, Label); - P.printNumber(VerLabel, Tpi->getTpiVersion()); - P.printNumber("Record count", Tpi->NumTypeRecords()); - } - - TypeDatabase &StreamDB = (StreamIdx == StreamTPI) ? TypeDB : ItemDB; + StreamScope = llvm::make_unique<DictScope>(P, Label); + P.printNumber(VerLabel, Tpi->getTpiVersion()); + P.printNumber("Record count", Tpi->getNumTypeRecords()); - TypeDatabaseVisitor DBV(StreamDB); - CompactTypeDumpVisitor CTDV(StreamDB, &P); - TypeDumpVisitor TDV(TypeDB, &P, false); - if (StreamIdx == StreamIPI) - TDV.setItemDB(ItemDB); - RecordBytesVisitor RBV(P); - TypeDeserializer Deserializer; + Optional<TypeDatabase> &StreamDB = (StreamIdx == StreamTPI) ? TypeDB : ItemDB; - // We always need to deserialize and add it to the type database. This is - // true if even if we're not dumping anything, because we could need the - // type database for the purposes of dumping symbols. - TypeVisitorCallbackPipeline Pipeline; - Pipeline.addCallbackToPipeline(Deserializer); - Pipeline.addCallbackToPipeline(DBV); + std::vector<std::unique_ptr<TypeVisitorCallbacks>> Visitors; + Visitors.push_back(make_unique<TypeDeserializer>()); + if (!StreamDB.hasValue()) { + StreamDB.emplace(Tpi->getNumTypeRecords()); + Visitors.push_back(make_unique<TypeDatabaseVisitor>(*StreamDB)); + } // If we're in dump mode, add a dumper with the appropriate detail level. if (DumpRecords) { + std::unique_ptr<TypeVisitorCallbacks> Dumper; if (opts::raw::CompactRecords) - Pipeline.addCallbackToPipeline(CTDV); - else - Pipeline.addCallbackToPipeline(TDV); + Dumper = make_unique<CompactTypeDumpVisitor>(*StreamDB, &P); + else { + assert(TypeDB.hasValue()); + + auto X = make_unique<TypeDumpVisitor>(*TypeDB, &P, false); + if (StreamIdx == StreamIPI) + X->setItemDB(*ItemDB); + Dumper = std::move(X); + } + Visitors.push_back(std::move(Dumper)); } if (DumpRecordBytes) - Pipeline.addCallbackToPipeline(RBV); + Visitors.push_back(make_unique<RecordBytesVisitor>(P)); + + // We always need to deserialize and add it to the type database. This is + // true if even if we're not dumping anything, because we could need the + // type database for the purposes of dumping symbols. + TypeVisitorCallbackPipeline Pipeline; + for (const auto &V : Visitors) + Pipeline.addCallbackToPipeline(*V); CVTypeVisitor Visitor(Pipeline); @@ -680,7 +683,7 @@ Error LLVMOutputStyle::dumpTpiStream(uint32_t StreamIdx) { if (DumpTpiHash) { DictScope DD(P, "Hash"); - P.printNumber("Number of Hash Buckets", Tpi->NumHashBuckets()); + P.printNumber("Number of Hash Buckets", Tpi->getNumHashBuckets()); P.printNumber("Hash Key Size", Tpi->getHashKeySize()); P.printList("Values", Tpi->getHashValues()); @@ -700,19 +703,51 @@ Error LLVMOutputStyle::dumpTpiStream(uint32_t StreamIdx) { } } - if (!IsSilentDatabaseBuild) { - ListScope L(P, "TypeIndexOffsets"); - for (const auto &IO : Tpi->getTypeIndexOffsets()) { - P.printString(formatv("Index: {0:x}, Offset: {1:N}", IO.Type.getIndex(), - (uint32_t)IO.Offset) - .str()); - } + ListScope L(P, "TypeIndexOffsets"); + for (const auto &IO : Tpi->getTypeIndexOffsets()) { + P.printString(formatv("Index: {0:x}, Offset: {1:N}", IO.Type.getIndex(), + (uint32_t)IO.Offset) + .str()); } P.flush(); return Error::success(); } +Error LLVMOutputStyle::buildTypeDatabase(uint32_t SN) { + assert(SN == StreamIPI || SN == StreamTPI); + + auto &DB = (SN == StreamIPI) ? ItemDB : TypeDB; + + if (DB.hasValue()) + return Error::success(); + + auto Tpi = + (SN == StreamTPI) ? File.getPDBTpiStream() : File.getPDBIpiStream(); + + if (!Tpi) + return Tpi.takeError(); + + DB.emplace(Tpi->getNumTypeRecords()); + + TypeVisitorCallbackPipeline Pipeline; + TypeDeserializer Deserializer; + TypeDatabaseVisitor DBV(*DB); + Pipeline.addCallbackToPipeline(Deserializer); + Pipeline.addCallbackToPipeline(DBV); + + auto HashValues = Tpi->getHashValues(); + std::unique_ptr<TpiHashVerifier> HashVerifier; + if (!HashValues.empty()) { + HashVerifier = + make_unique<TpiHashVerifier>(HashValues, Tpi->getNumHashBuckets()); + Pipeline.addCallbackToPipeline(*HashVerifier); + } + + CVTypeVisitor Visitor(Pipeline); + return Visitor.visitTypeStream(Tpi->types(nullptr)); +} + Error LLVMOutputStyle::dumpDbiStream() { bool DumpModules = opts::raw::DumpModules || opts::raw::DumpModuleSyms || opts::raw::DumpModuleFiles || opts::raw::DumpLineInfo; @@ -750,43 +785,46 @@ Error LLVMOutputStyle::dumpDbiStream() { if (DumpModules) { ListScope L(P, "Modules"); - for (auto &Modi : DS->modules()) { + const DbiModuleList &Modules = DS->modules(); + for (uint32_t I = 0; I < Modules.getModuleCount(); ++I) { + const DbiModuleDescriptor &Modi = Modules.getModuleDescriptor(I); DictScope DD(P); - P.printString("Name", Modi.Info.getModuleName().str()); - P.printNumber("Debug Stream Index", Modi.Info.getModuleStreamIndex()); - P.printString("Object File Name", Modi.Info.getObjFileName().str()); - P.printNumber("Num Files", Modi.Info.getNumberOfFiles()); - P.printNumber("Source File Name Idx", Modi.Info.getSourceFileNameIndex()); - P.printNumber("Pdb File Name Idx", Modi.Info.getPdbFilePathNameIndex()); - P.printNumber("Line Info Byte Size", Modi.Info.getC11LineInfoByteSize()); - P.printNumber("C13 Line Info Byte Size", - Modi.Info.getC13LineInfoByteSize()); - P.printNumber("Symbol Byte Size", Modi.Info.getSymbolDebugInfoByteSize()); - P.printNumber("Type Server Index", Modi.Info.getTypeServerIndex()); - P.printBoolean("Has EC Info", Modi.Info.hasECInfo()); + P.printString("Name", Modi.getModuleName().str()); + P.printNumber("Debug Stream Index", Modi.getModuleStreamIndex()); + P.printString("Object File Name", Modi.getObjFileName().str()); + P.printNumber("Num Files", Modi.getNumberOfFiles()); + P.printNumber("Source File Name Idx", Modi.getSourceFileNameIndex()); + P.printNumber("Pdb File Name Idx", Modi.getPdbFilePathNameIndex()); + P.printNumber("Line Info Byte Size", Modi.getC11LineInfoByteSize()); + P.printNumber("C13 Line Info Byte Size", Modi.getC13LineInfoByteSize()); + P.printNumber("Symbol Byte Size", Modi.getSymbolDebugInfoByteSize()); + P.printNumber("Type Server Index", Modi.getTypeServerIndex()); + P.printBoolean("Has EC Info", Modi.hasECInfo()); if (opts::raw::DumpModuleFiles) { - std::string FileListName = - to_string(Modi.SourceFiles.size()) + " Contributing Source Files"; + std::string FileListName = to_string(Modules.getSourceFileCount(I)) + + " Contributing Source Files"; ListScope LL(P, FileListName); - for (auto File : Modi.SourceFiles) - P.printString(File.str()); + for (auto File : Modules.source_files(I)) + P.printString(File); } - bool HasModuleDI = - (Modi.Info.getModuleStreamIndex() < File.getNumStreams()); + bool HasModuleDI = (Modi.getModuleStreamIndex() < File.getNumStreams()); bool ShouldDumpSymbols = (opts::raw::DumpModuleSyms || opts::raw::DumpSymRecordBytes); if (HasModuleDI && (ShouldDumpSymbols || opts::raw::DumpLineInfo)) { auto ModStreamData = MappedBlockStream::createIndexedStream( File.getMsfLayout(), File.getMsfBuffer(), - Modi.Info.getModuleStreamIndex()); + Modi.getModuleStreamIndex()); - ModuleDebugStreamRef ModS(Modi.Info, std::move(ModStreamData)); + ModuleDebugStreamRef ModS(Modi, std::move(ModStreamData)); if (auto EC = ModS.reload()) return EC; if (ShouldDumpSymbols) { + if (auto EC = buildTypeDatabase(StreamTPI)) + return EC; + ListScope SS(P, "Symbols"); - codeview::CVSymbolDumper SD(P, TypeDB, nullptr, false); + codeview::CVSymbolDumper SD(P, *TypeDB, nullptr, false); bool HadError = false; for (auto S : ModS.symbols(&HadError)) { DictScope LL(P, ""); @@ -807,8 +845,10 @@ Error LLVMOutputStyle::dumpDbiStream() { } if (opts::raw::DumpLineInfo) { ListScope SS(P, "LineInfo"); + if (auto EC = buildTypeDatabase(StreamIPI)) + return EC; - C13RawVisitor V(P, File, ItemDB); + C13RawVisitor V(P, File, *ItemDB); if (auto EC = codeview::visitModuleDebugFragments( ModS.linesAndChecksums(), V)) return EC; @@ -846,9 +886,10 @@ Error LLVMOutputStyle::dumpSectionContribs() { { DictScope DD(P, "Module"); P.printNumber("Index", SC.Imod); - auto M = DS.modules(); - if (M.size() > SC.Imod) { - P.printString("Name", M[SC.Imod].Info.getModuleName()); + const DbiModuleList &Modules = DS.modules(); + if (Modules.getModuleCount() > SC.Imod) { + P.printString("Name", + Modules.getModuleDescriptor(SC.Imod).getModuleName()); } } P.printNumber("Data CRC", SC.DataCrc); @@ -925,7 +966,10 @@ Error LLVMOutputStyle::dumpPublicsStream() { P.printList("Section Offsets", Publics->getSectionOffsets(), printSectionOffset); ListScope L(P, "Symbols"); - codeview::CVSymbolDumper SD(P, TypeDB, nullptr, false); + if (auto EC = buildTypeDatabase(StreamTPI)) + return EC; + + codeview::CVSymbolDumper SD(P, *TypeDB, nullptr, false); bool HadError = false; for (auto S : Publics->getSymbols(&HadError)) { DictScope DD(P, ""); diff --git a/tools/llvm-pdbdump/LLVMOutputStyle.h b/tools/llvm-pdbdump/LLVMOutputStyle.h index bfff3b8308db9..b0e7e3406b369 100644 --- a/tools/llvm-pdbdump/LLVMOutputStyle.h +++ b/tools/llvm-pdbdump/LLVMOutputStyle.h @@ -12,6 +12,7 @@ #include "OutputStyle.h" +#include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallVector.h" #include "llvm/DebugInfo/CodeView/TypeDatabase.h" #include "llvm/Support/ScopedPrinter.h" @@ -28,6 +29,8 @@ public: Error dump() override; private: + Error buildTypeDatabase(uint32_t SN); + Error dumpFileHeaders(); Error dumpStreamSummary(); Error dumpFreePageMap(); @@ -51,8 +54,8 @@ private: PDBFile &File; ScopedPrinter P; - codeview::TypeDatabase TypeDB; - codeview::TypeDatabase ItemDB; + Optional<codeview::TypeDatabase> TypeDB; + Optional<codeview::TypeDatabase> ItemDB; SmallVector<std::string, 32> StreamPurposes; }; } diff --git a/tools/llvm-pdbdump/StreamUtil.cpp b/tools/llvm-pdbdump/StreamUtil.cpp index 6577702adac88..81aa256b5002d 100644 --- a/tools/llvm-pdbdump/StreamUtil.cpp +++ b/tools/llvm-pdbdump/StreamUtil.cpp @@ -12,6 +12,7 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMapInfo.h" #include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h" +#include "llvm/DebugInfo/PDB/Native/DbiModuleList.h" #include "llvm/DebugInfo/PDB/Native/DbiStream.h" #include "llvm/DebugInfo/PDB/Native/InfoStream.h" #include "llvm/DebugInfo/PDB/Native/PDBFile.h" @@ -30,14 +31,16 @@ void discoverStreamPurposes(PDBFile &File, auto Info = File.getPDBInfoStream(); uint32_t StreamCount = File.getNumStreams(); - DenseMap<uint16_t, const ModuleInfoEx *> ModStreams; + DenseMap<uint16_t, DbiModuleDescriptor> ModStreams; DenseMap<uint16_t, std::string> NamedStreams; if (Dbi) { - for (auto &ModI : Dbi->modules()) { - uint16_t SN = ModI.Info.getModuleStreamIndex(); + const DbiModuleList &Modules = Dbi->modules(); + for (uint32_t I = 0; I < Modules.getModuleCount(); ++I) { + DbiModuleDescriptor Descriptor = Modules.getModuleDescriptor(I); + uint16_t SN = Descriptor.getModuleStreamIndex(); if (SN != kInvalidStreamIndex) - ModStreams[SN] = &ModI; + ModStreams[SN] = Descriptor; } } if (Info) { @@ -109,7 +112,7 @@ void discoverStreamPurposes(PDBFile &File, auto NSIter = NamedStreams.find(StreamIdx); if (ModIter != ModStreams.end()) { Value = "Module \""; - Value += ModIter->second->Info.getModuleName().str(); + Value += ModIter->second.getModuleName(); Value += "\""; } else if (NSIter != NamedStreams.end()) { Value = "Named Stream \""; diff --git a/tools/llvm-pdbdump/YAMLOutputStyle.cpp b/tools/llvm-pdbdump/YAMLOutputStyle.cpp index b94b5a4abf37c..0573b23cdc761 100644 --- a/tools/llvm-pdbdump/YAMLOutputStyle.cpp +++ b/tools/llvm-pdbdump/YAMLOutputStyle.cpp @@ -305,23 +305,28 @@ Error YAMLOutputStyle::dumpDbiStream() { Obj.DbiStream->PdbDllVersion = DS.getPdbDllVersion(); Obj.DbiStream->VerHeader = DS.getDbiVersion(); if (opts::pdb2yaml::DbiModuleInfo) { - for (const auto &MI : DS.modules()) { + const auto &Modules = DS.modules(); + for (uint32_t I = 0; I < Modules.getModuleCount(); ++I) { + DbiModuleDescriptor MI = Modules.getModuleDescriptor(I); + Obj.DbiStream->ModInfos.emplace_back(); yaml::PdbDbiModuleInfo &DMI = Obj.DbiStream->ModInfos.back(); - DMI.Mod = MI.Info.getModuleName(); - DMI.Obj = MI.Info.getObjFileName(); - if (opts::pdb2yaml::DbiModuleSourceFileInfo) - DMI.SourceFiles = MI.SourceFiles; + DMI.Mod = MI.getModuleName(); + DMI.Obj = MI.getObjFileName(); + if (opts::pdb2yaml::DbiModuleSourceFileInfo) { + auto Files = Modules.source_files(I); + DMI.SourceFiles.assign(Files.begin(), Files.end()); + } - uint16_t ModiStream = MI.Info.getModuleStreamIndex(); + uint16_t ModiStream = MI.getModuleStreamIndex(); if (ModiStream == kInvalidStreamIndex) continue; auto ModStreamData = msf::MappedBlockStream::createIndexedStream( File.getMsfLayout(), File.getMsfBuffer(), ModiStream); - pdb::ModuleDebugStreamRef ModS(MI.Info, std::move(ModStreamData)); + pdb::ModuleDebugStreamRef ModS(MI, std::move(ModStreamData)); if (auto EC = ModS.reload()) return EC; diff --git a/tools/llvm-readobj/COFFDumper.cpp b/tools/llvm-readobj/COFFDumper.cpp index 04386875b95ad..049af2c4f076d 100644 --- a/tools/llvm-readobj/COFFDumper.cpp +++ b/tools/llvm-readobj/COFFDumper.cpp @@ -44,6 +44,7 @@ #include "llvm/Support/BinaryByteStream.h" #include "llvm/Support/BinaryStreamReader.h" #include "llvm/Support/COFF.h" +#include "llvm/Support/ConvertUTF.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/DataExtractor.h" @@ -70,7 +71,7 @@ class COFFDumper : public ObjDumper { public: friend class COFFObjectDumpDelegate; COFFDumper(const llvm::object::COFFObjectFile *Obj, ScopedPrinter &Writer) - : ObjDumper(Writer), Obj(Obj), Writer(Writer) {} + : ObjDumper(Writer), Obj(Obj), Writer(Writer), TypeDB(100) {} void printFileHeaders() override; void printSections() override; @@ -121,6 +122,10 @@ private: uint32_t RelocOffset, uint32_t Offset, StringRef *RelocSym = nullptr); + void printResourceDirectoryTable(ResourceSectionRef RSF, + const coff_resource_dir_table &Table, + StringRef Level); + void printBinaryBlockWithRelocs(StringRef Label, const SectionRef &Sec, StringRef SectionContents, StringRef Block); @@ -140,6 +145,9 @@ private: void printDelayImportedSymbols( const DelayImportDirectoryEntryRef &I, iterator_range<imported_symbol_iterator> Range); + ErrorOr<const coff_resource_dir_entry &> + getResourceDirectoryTableEntry(const coff_resource_dir_table &Table, + uint32_t Index); typedef DenseMap<const coff_section*, std::vector<RelocationRef> > RelocMapTy; @@ -534,6 +542,29 @@ static const EnumEntry<uint8_t> FileChecksumKindNames[] = { LLVM_READOBJ_ENUM_CLASS_ENT(FileChecksumKind, SHA256), }; +static const EnumEntry<COFF::ResourceTypeID> ResourceTypeNames[]{ + {"kRT_CURSOR (ID 1)", COFF::RID_Cursor}, + {"kRT_BITMAP (ID 2)", COFF::RID_Bitmap}, + {"kRT_ICON (ID 3)", COFF::RID_Icon}, + {"kRT_MENU (ID 4)", COFF::RID_Menu}, + {"kRT_DIALOG (ID 5)", COFF::RID_Dialog}, + {"kRT_STRING (ID 6)", COFF::RID_String}, + {"kRT_FONTDIR (ID 7)", COFF::RID_FontDir}, + {"kRT_FONT (ID 8)", COFF::RID_Font}, + {"kRT_ACCELERATOR (ID 9)", COFF::RID_Accelerator}, + {"kRT_RCDATA (ID 10)", COFF::RID_RCData}, + {"kRT_MESSAGETABLE (ID 11)", COFF::RID_MessageTable}, + {"kRT_GROUP_CURSOR (ID 12)", COFF::RID_Group_Cursor}, + {"kRT_GROUP_ICON (ID 14)", COFF::RID_Group_Icon}, + {"kRT_VERSION (ID 16)", COFF::RID_Version}, + {"kRT_DLGINCLUDE (ID 17)", COFF::RID_DLGInclude}, + {"kRT_PLUGPLAY (ID 19)", COFF::RID_PlugPlay}, + {"kRT_VXD (ID 20)", COFF::RID_VXD}, + {"kRT_ANICURSOR (ID 21)", COFF::RID_AniCursor}, + {"kRT_ANIICON (ID 22)", COFF::RID_AniIcon}, + {"kRT_HTML (ID 23)", COFF::RID_HTML}, + {"kRT_MANIFEST (ID 24)", COFF::RID_Manifest}}; + template <typename T> static std::error_code getSymbolAuxData(const COFFObjectFile *Obj, COFFSymbolRef Symbol, @@ -1503,18 +1534,76 @@ void COFFDumper::printCOFFResources() { error(S.getContents(Ref)); if ((Name == ".rsrc") || (Name == ".rsrc$01")) { - auto Table = - reinterpret_cast<const coff_resource_dir_table *>(Ref.data()); - char FormattedTime[20]; - time_t TDS = time_t(Table->TimeDateStamp); - strftime(FormattedTime, sizeof(FormattedTime), "%Y-%m-%d %H:%M:%S", - gmtime(&TDS)); - W.printHex("Time/Date Stamp", FormattedTime, Table->TimeDateStamp); + ResourceSectionRef RSF(Ref); + auto &BaseTable = unwrapOrError(RSF.getBaseTable()); + printResourceDirectoryTable(RSF, BaseTable, "Type"); + } + if (opts::SectionData) + W.printBinaryBlock(Name.str() + " Data", Ref); + } +} + +void COFFDumper::printResourceDirectoryTable( + ResourceSectionRef RSF, const coff_resource_dir_table &Table, + StringRef Level) { + W.printNumber("String Name Entries", Table.NumberOfNameEntries); + W.printNumber("ID Entries", Table.NumberOfIDEntries); + + char FormattedTime[20] = {}; + time_t TDS = time_t(Table.TimeDateStamp); + strftime(FormattedTime, 20, "%Y-%m-%d %H:%M:%S", gmtime(&TDS)); + + // Iterate through level in resource directory tree. + for (int i = 0; i < Table.NumberOfNameEntries + Table.NumberOfIDEntries; + i++) { + auto Entry = unwrapOrError(getResourceDirectoryTableEntry(Table, i)); + StringRef Name; + SmallString<20> IDStr; + raw_svector_ostream OS(IDStr); + if (i < Table.NumberOfNameEntries) { + ArrayRef<UTF16> RawEntryNameString = unwrapOrError(RSF.getEntryNameString(Entry)); + std::string EntryNameString; + if (!llvm::convertUTF16ToUTF8String(RawEntryNameString, EntryNameString)) + error(object_error::parse_failed); + OS << ": "; + OS << EntryNameString; + } else { + if (Level == "Type") { + ScopedPrinter Printer(OS); + Printer.printEnum("", Entry.Identifier.ID, + makeArrayRef(ResourceTypeNames)); + IDStr = IDStr.slice(0, IDStr.find_first_of(")", 0) + 1); + } else { + OS << ": (ID " << Entry.Identifier.ID << ")"; + } + } + Name = StringRef(IDStr); + ListScope ResourceType(W, Level.str() + Name.str()); + if (Entry.Offset.isSubDir()) { + StringRef NextLevel; + if (Level == "Name") + NextLevel = "Language"; + else + NextLevel = "Name"; + auto &NextTable = unwrapOrError(RSF.getEntrySubDir(Entry)); + printResourceDirectoryTable(RSF, NextTable, NextLevel); + } else { + W.printHex("Time/Date Stamp", FormattedTime, Table.TimeDateStamp); + W.printNumber("Major Version", Table.MajorVersion); + W.printNumber("Minor Version", Table.MinorVersion); } - W.printBinaryBlock(Name.str() + " Data", Ref); } } +ErrorOr<const coff_resource_dir_entry &> +COFFDumper::getResourceDirectoryTableEntry(const coff_resource_dir_table &Table, + uint32_t Index) { + if (Index >= (uint32_t)(Table.NumberOfNameEntries + Table.NumberOfIDEntries)) + return object_error::parse_failed; + auto TablePtr = reinterpret_cast<const coff_resource_dir_entry *>(&Table + 1); + return TablePtr[Index]; +} + void COFFDumper::printStackMap() const { object::SectionRef StackMapSection; for (auto Sec : Obj->sections()) { @@ -1553,7 +1642,7 @@ void llvm::dumpCodeViewMergedTypes(ScopedPrinter &Writer, TypeBuf.append(Record.begin(), Record.end()); }); - TypeDatabase TypeDB; + TypeDatabase TypeDB(CVTypes.records().size()); { ListScope S(Writer, "MergedTypeStream"); CVTypeDumper CVTD(TypeDB); @@ -1574,7 +1663,7 @@ void llvm::dumpCodeViewMergedTypes(ScopedPrinter &Writer, { ListScope S(Writer, "MergedIDStream"); - TypeDatabase IDDB; + TypeDatabase IDDB(IDTable.records().size()); CVTypeDumper CVTD(IDDB); TypeDumpVisitor TDV(TypeDB, &Writer, opts::CodeViewSubsectionBytes); TDV.setItemDB(IDDB); diff --git a/tools/llvm-rtdyld/llvm-rtdyld.cpp b/tools/llvm-rtdyld/llvm-rtdyld.cpp index 4e1caa0400f1e..75345de502803 100644 --- a/tools/llvm-rtdyld/llvm-rtdyld.cpp +++ b/tools/llvm-rtdyld/llvm-rtdyld.cpp @@ -486,10 +486,7 @@ static int checkAllExpressions(RuntimeDyldChecker &Checker) { return 0; } -static std::map<void *, uint64_t> -applySpecificSectionMappings(RuntimeDyldChecker &Checker) { - - std::map<void*, uint64_t> SpecificMappings; +void applySpecificSectionMappings(RuntimeDyldChecker &Checker) { for (StringRef Mapping : SpecificSectionMappings) { @@ -522,10 +519,7 @@ applySpecificSectionMappings(RuntimeDyldChecker &Checker) { "'."); Checker.getRTDyld().mapSectionAddress(OldAddr, NewAddr); - SpecificMappings[OldAddr] = NewAddr; } - - return SpecificMappings; } // Scatter sections in all directions! @@ -554,8 +548,7 @@ static void remapSectionsAndSymbols(const llvm::Triple &TargetTriple, // Apply any section-specific mappings that were requested on the command // line. - typedef std::map<void*, uint64_t> AppliedMappingsT; - AppliedMappingsT AppliedMappings = applySpecificSectionMappings(Checker); + applySpecificSectionMappings(Checker); // Keep an "already allocated" mapping of section target addresses to sizes. // Sections whose address mappings aren't specified on the command line will @@ -563,15 +556,19 @@ static void remapSectionsAndSymbols(const llvm::Triple &TargetTriple, // minimum separation. std::map<uint64_t, uint64_t> AlreadyAllocated; - // Move the previously applied mappings into the already-allocated map. + // Move the previously applied mappings (whether explicitly specified on the + // command line, or implicitly set by RuntimeDyld) into the already-allocated + // map. for (WorklistT::iterator I = Worklist.begin(), E = Worklist.end(); I != E;) { WorklistT::iterator Tmp = I; ++I; - AppliedMappingsT::iterator AI = AppliedMappings.find(Tmp->first); + auto LoadAddr = Checker.getSectionLoadAddress(Tmp->first); - if (AI != AppliedMappings.end()) { - AlreadyAllocated[AI->second] = Tmp->second; + if (LoadAddr && + *LoadAddr != static_cast<uint64_t>( + reinterpret_cast<uintptr_t>(Tmp->first))) { + AlreadyAllocated[*LoadAddr] = Tmp->second; Worklist.erase(Tmp); } } diff --git a/tools/obj2yaml/wasm2yaml.cpp b/tools/obj2yaml/wasm2yaml.cpp index f6b530c41969d..cc04b995f667a 100644 --- a/tools/obj2yaml/wasm2yaml.cpp +++ b/tools/obj2yaml/wasm2yaml.cpp @@ -44,7 +44,24 @@ ErrorOr<WasmYAML::Object *> WasmDumper::dump() { } auto CustomSec = make_unique<WasmYAML::CustomSection>(); CustomSec->Name = WasmSec.Name; - CustomSec->Payload = yaml::BinaryRef(WasmSec.Content); + if (CustomSec->Name == "name") { + for (const object::SymbolRef& Sym: Obj.symbols()) { + uint32_t Flags = Sym.getFlags(); + // Skip over symbols that come from imports or exports + if (Flags & + (object::SymbolRef::SF_Global | object::SymbolRef::SF_Undefined)) + continue; + Expected<StringRef> NameOrError = Sym.getName(); + if (!NameOrError) + continue; + WasmYAML::NameEntry NameEntry; + NameEntry.Name = *NameOrError; + NameEntry.Index = Sym.getValue(); + CustomSec->FunctionNames.push_back(NameEntry); + } + } else { + CustomSec->Payload = yaml::BinaryRef(WasmSec.Content); + } S = std::move(CustomSec); break; } diff --git a/tools/yaml2obj/yaml2wasm.cpp b/tools/yaml2obj/yaml2wasm.cpp index 55267ce0392d9..eed9f2c4039b2 100644 --- a/tools/yaml2obj/yaml2wasm.cpp +++ b/tools/yaml2obj/yaml2wasm.cpp @@ -27,6 +27,8 @@ public: WasmWriter(WasmYAML::Object &Obj) : Obj(Obj) {} int writeWasm(raw_ostream &OS); int writeRelocSection(raw_ostream &OS, WasmYAML::Section &Sec); + int writeNameSection(raw_ostream &OS, WasmYAML::CustomSection &Section); + int writeSectionContent(raw_ostream &OS, WasmYAML::CustomSection &Section); int writeSectionContent(raw_ostream &OS, WasmYAML::TypeSection &Section); int writeSectionContent(raw_ostream &OS, WasmYAML::ImportSection &Section); @@ -65,13 +67,13 @@ static int writeUint8(raw_ostream &OS, uint8_t Value) { return 0; } -static int writeStringRef(StringRef &Str, raw_ostream &OS) { +static int writeStringRef(const StringRef &Str, raw_ostream &OS) { encodeULEB128(Str.size(), OS); OS << Str; return 0; } -static int writeLimits(WasmYAML::Limits Lim, raw_ostream &OS) { +static int writeLimits(const WasmYAML::Limits &Lim, raw_ostream &OS) { encodeULEB128(Lim.Flags, OS); encodeULEB128(Lim.Initial, OS); if (Lim.Flags & wasm::WASM_LIMITS_FLAG_HAS_MAX) @@ -79,7 +81,7 @@ static int writeLimits(WasmYAML::Limits Lim, raw_ostream &OS) { return 0; } -static int writeInitExpr(wasm::WasmInitExpr InitExpr, raw_ostream &OS) { +static int writeInitExpr(const wasm::WasmInitExpr &InitExpr, raw_ostream &OS) { writeUint8(OS, InitExpr.Opcode); switch (InitExpr.Opcode) { case wasm::WASM_OPCODE_I32_CONST: @@ -105,18 +107,42 @@ static int writeInitExpr(wasm::WasmInitExpr InitExpr, raw_ostream &OS) { return 0; } +int WasmWriter::writeNameSection(raw_ostream &OS, + WasmYAML::CustomSection &Section) { + writeStringRef(Section.Name, OS); + if (Section.FunctionNames.size()) { + encodeULEB128(wasm::WASM_NAMES_FUNCTION, OS); + + std::string OutString; + raw_string_ostream StringStream(OutString); + + encodeULEB128(Section.FunctionNames.size(), StringStream); + for (const WasmYAML::NameEntry &NameEntry : Section.FunctionNames) { + encodeULEB128(NameEntry.Index, StringStream); + writeStringRef(NameEntry.Name, StringStream); + } + + StringStream.flush(); + encodeULEB128(OutString.size(), OS); + OS << OutString; + } + return 0; +} + int WasmWriter::writeSectionContent(raw_ostream &OS, WasmYAML::CustomSection &Section) { - // writeStringRef(Section.Name, OS); - // encodeULEB128(Section.Payload.binary_size(), OS); - Section.Payload.writeAsBinary(OS); + if (Section.Name == "name") { + writeNameSection(OS, Section); + } else { + Section.Payload.writeAsBinary(OS); + } return 0; } int WasmWriter::writeSectionContent(raw_ostream &OS, WasmYAML::TypeSection &Section) { encodeULEB128(Section.Signatures.size(), OS); - for (auto &Sig : Section.Signatures) { + for (const WasmYAML::Signature &Sig : Section.Signatures) { encodeSLEB128(Sig.Form, OS); encodeULEB128(Sig.ParamTypes.size(), OS); for (auto ParamType : Sig.ParamTypes) @@ -134,7 +160,7 @@ int WasmWriter::writeSectionContent(raw_ostream &OS, int WasmWriter::writeSectionContent(raw_ostream &OS, WasmYAML::ImportSection &Section) { encodeULEB128(Section.Imports.size(), OS); - for (auto &Import : Section.Imports) { + for (const WasmYAML::Import &Import : Section.Imports) { writeStringRef(Import.Module, OS); writeStringRef(Import.Field, OS); encodeULEB128(Import.Kind, OS); @@ -166,7 +192,7 @@ int WasmWriter::writeSectionContent(raw_ostream &OS, int WasmWriter::writeSectionContent(raw_ostream &OS, WasmYAML::ExportSection &Section) { encodeULEB128(Section.Exports.size(), OS); - for (auto &Export : Section.Exports) { + for (const WasmYAML::Export &Export : Section.Exports) { writeStringRef(Export.Name, OS); encodeULEB128(Export.Kind, OS); encodeULEB128(Export.Index, OS); @@ -193,7 +219,7 @@ int WasmWriter::writeSectionContent(raw_ostream &OS, int WasmWriter::writeSectionContent(raw_ostream &OS, WasmYAML::MemorySection &Section) { encodeULEB128(Section.Memories.size(), OS); - for (auto &Mem : Section.Memories) { + for (const WasmYAML::Limits &Mem : Section.Memories) { writeLimits(Mem, OS); } return 0; |