diff options
author | Zachary Turner <zturner@google.com> | 2017-12-06 18:58:48 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2017-12-06 18:58:48 +0000 |
commit | 8b348680b2bd89c8e06f3e53c7ae8d90d835e6f2 (patch) | |
tree | e607362e13fb6964269eab43ba269e91ab3c680c /lib/ObjectYAML | |
parent | ee79c38757ad8ad12cdb5e7661dcdb78913599fc (diff) |
Update obj2yaml and yaml2obj for .debug$H section.
Differential Revision: https://reviews.llvm.org/D40842
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319925 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ObjectYAML')
-rw-r--r-- | lib/ObjectYAML/CMakeLists.txt | 5 | ||||
-rw-r--r-- | lib/ObjectYAML/COFFYAML.cpp | 8 | ||||
-rw-r--r-- | lib/ObjectYAML/CodeViewYAMLTypeHashing.cpp | 84 |
3 files changed, 92 insertions, 5 deletions
diff --git a/lib/ObjectYAML/CMakeLists.txt b/lib/ObjectYAML/CMakeLists.txt index 7af0b9c194e..d24f879836f 100644 --- a/lib/ObjectYAML/CMakeLists.txt +++ b/lib/ObjectYAML/CMakeLists.txt @@ -1,7 +1,8 @@ add_llvm_library(LLVMObjectYAML - CodeViewYAMLTypes.cpp - CodeViewYAMLSymbols.cpp CodeViewYAMLDebugSections.cpp + CodeViewYAMLSymbols.cpp + CodeViewYAMLTypeHashing.cpp + CodeViewYAMLTypes.cpp COFFYAML.cpp DWARFEmitter.cpp DWARFVisitor.cpp diff --git a/lib/ObjectYAML/COFFYAML.cpp b/lib/ObjectYAML/COFFYAML.cpp index 056a1aa3ca1..937b8dc029f 100644 --- a/lib/ObjectYAML/COFFYAML.cpp +++ b/lib/ObjectYAML/COFFYAML.cpp @@ -562,14 +562,16 @@ void MappingTraits<COFFYAML::Section>::mapping(IO &IO, COFFYAML::Section &Sec) { IO.mapOptional("VirtualSize", Sec.Header.VirtualSize, 0U); IO.mapOptional("Alignment", Sec.Alignment, 0U); - // If this is a .debug$S or .debug$T section parse the semantic representation - // of the symbols/types. If it is any other kind of section, just deal in raw - // bytes. + // If this is a .debug$S .debug$T, or .debug$H section parse the semantic + // representation of the symbols/types. If it is any other kind of section, + // just deal in raw bytes. IO.mapOptional("SectionData", Sec.SectionData); if (Sec.Name == ".debug$S") IO.mapOptional("Subsections", Sec.DebugS); else if (Sec.Name == ".debug$T") IO.mapOptional("Types", Sec.DebugT); + else if (Sec.Name == ".debug$H") + IO.mapOptional("GlobalHashes", Sec.DebugH); IO.mapOptional("Relocations", Sec.Relocations); } diff --git a/lib/ObjectYAML/CodeViewYAMLTypeHashing.cpp b/lib/ObjectYAML/CodeViewYAMLTypeHashing.cpp new file mode 100644 index 00000000000..b35e8ab05ad --- /dev/null +++ b/lib/ObjectYAML/CodeViewYAMLTypeHashing.cpp @@ -0,0 +1,84 @@ +//===- CodeViewYAMLTypeHashing.cpp - CodeView YAMLIO type hashing ---------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines classes for handling the YAML representation of CodeView +// Debug Info. +// +//===----------------------------------------------------------------------===// + +#include "llvm/ObjectYAML/CodeViewYAMLTypeHashing.h" +#include "llvm/Support/BinaryByteStream.h" +#include "llvm/Support/BinaryStreamReader.h" +#include "llvm/Support/BinaryStreamWriter.h" + +using namespace llvm; +using namespace llvm::codeview; +using namespace llvm::CodeViewYAML; +using namespace llvm::yaml; + +namespace llvm { +namespace yaml { + +void MappingTraits<DebugHSection>::mapping(IO &io, DebugHSection &DebugH) { + io.mapRequired("Version", DebugH.Version); + io.mapRequired("HashAlgorithm", DebugH.HashAlgorithm); + io.mapOptional("HashValues", DebugH.Hashes); +} + +void ScalarTraits<GlobalHash>::output(const GlobalHash &GH, void *Ctx, + raw_ostream &OS) { + ScalarTraits<BinaryRef>::output(GH.Hash, Ctx, OS); +} + +StringRef ScalarTraits<GlobalHash>::input(StringRef Scalar, void *Ctx, + GlobalHash &GH) { + return ScalarTraits<BinaryRef>::input(Scalar, Ctx, GH.Hash); +} + +} // end namespace yaml +} // end namespace llvm + +DebugHSection llvm::CodeViewYAML::fromDebugH(ArrayRef<uint8_t> DebugT) { + assert(DebugT.size() >= 8); + assert((DebugT.size() - 8) % 20 == 0); + + BinaryStreamReader Reader(DebugT, llvm::support::little); + DebugHSection DHS; + cantFail(Reader.readInteger(DHS.Magic)); + cantFail(Reader.readInteger(DHS.Version)); + cantFail(Reader.readInteger(DHS.HashAlgorithm)); + while (Reader.bytesRemaining() != 0) { + ArrayRef<uint8_t> S; + cantFail(Reader.readBytes(S, 20)); + DHS.Hashes.emplace_back(S); + } + assert(Reader.bytesRemaining() == 0); + return DHS; +} + +ArrayRef<uint8_t> llvm::CodeViewYAML::toDebugH(const DebugHSection &DebugH, + BumpPtrAllocator &Alloc) { + uint32_t Size = 8 + 20 * DebugH.Hashes.size(); + uint8_t *Data = Alloc.Allocate<uint8_t>(Size); + MutableArrayRef<uint8_t> Buffer(Data, Size); + BinaryStreamWriter Writer(Buffer, llvm::support::little); + cantFail(Writer.writeInteger(DebugH.Magic)); + cantFail(Writer.writeInteger(DebugH.Version)); + cantFail(Writer.writeInteger(DebugH.HashAlgorithm)); + SmallString<20> Hash; + for (const auto &H : DebugH.Hashes) { + Hash.clear(); + raw_svector_ostream OS(Hash); + H.Hash.writeAsBinary(OS); + assert((Hash.size() == 20) && "Invalid hash size!"); + cantFail(Writer.writeFixedString(Hash)); + } + assert(Writer.bytesRemaining() == 0); + return Buffer; +} |