Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update obj2yaml and yaml2obj for .debug$H section.
Differential Revision: https://reviews.llvm.org/D40842 llvm-svn: 319925
- Loading branch information
Zachary Turner
committed
Dec 6, 2017
1 parent
c8dfde2
commit c221dc7
Showing
10 changed files
with
274 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
//==- CodeViewYAMLTypeHashing.h - CodeView YAMLIO Type hashing ----*- C++-*-==// | ||
// | ||
// 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. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_OBJECTYAML_CODEVIEWYAMLTYPEHASHING_H | ||
#define LLVM_OBJECTYAML_CODEVIEWYAMLTYPEHASHING_H | ||
|
||
#include "llvm/ADT/ArrayRef.h" | ||
#include "llvm/DebugInfo/CodeView/TypeHashing.h" | ||
#include "llvm/ObjectYAML/YAML.h" | ||
#include "llvm/Support/Allocator.h" | ||
#include "llvm/Support/Error.h" | ||
#include "llvm/Support/YAMLTraits.h" | ||
#include <cstdint> | ||
#include <memory> | ||
#include <vector> | ||
|
||
namespace llvm { | ||
|
||
namespace CodeViewYAML { | ||
|
||
struct GlobalHash { | ||
GlobalHash() = default; | ||
explicit GlobalHash(StringRef S) : Hash(S) { | ||
assert(S.size() == 20 && "Invalid hash size!"); | ||
} | ||
explicit GlobalHash(ArrayRef<uint8_t> S) : Hash(S) { | ||
assert(S.size() == 20 && "Invalid hash size!"); | ||
} | ||
yaml::BinaryRef Hash; | ||
}; | ||
|
||
struct DebugHSection { | ||
uint32_t Magic; | ||
uint16_t Version; | ||
uint16_t HashAlgorithm; | ||
std::vector<GlobalHash> Hashes; | ||
}; | ||
|
||
DebugHSection fromDebugH(ArrayRef<uint8_t> DebugT); | ||
ArrayRef<uint8_t> toDebugH(const DebugHSection &DebugH, | ||
BumpPtrAllocator &Alloc); | ||
|
||
} // end namespace CodeViewYAML | ||
|
||
} // end namespace llvm | ||
|
||
LLVM_YAML_DECLARE_MAPPING_TRAITS(CodeViewYAML::DebugHSection) | ||
LLVM_YAML_DECLARE_SCALAR_TRAITS(CodeViewYAML::GlobalHash, false) | ||
LLVM_YAML_IS_SEQUENCE_VECTOR(CodeViewYAML::GlobalHash) | ||
|
||
#endif // LLVM_OBJECTYAML_CODEVIEWYAMLTYPES_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# RUN: yaml2obj %s > %t.obj | ||
# RUN: obj2yaml %t.obj | FileCheck --check-prefix=CHECK %s | ||
# RUN: llvm-objdump -section-headers %t.obj | FileCheck --check-prefix=HEADERS %s | ||
|
||
--- !COFF | ||
header: | ||
Machine: IMAGE_FILE_MACHINE_AMD64 | ||
Characteristics: [ ] | ||
sections: | ||
- Name: '.debug$T' | ||
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ] | ||
Alignment: 1 | ||
Types: | ||
- Kind: LF_TYPESERVER2 | ||
TypeServer2: | ||
Guid: '{01DF191B-22BF-6B42-96CE-5258B8329FE5}' | ||
Age: 24 | ||
Name: 'C:\src\llvm-project\build\vc140.pdb' | ||
- Name: '.debug$H' | ||
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ] | ||
Alignment: 4 | ||
GlobalHashes: | ||
Version: 0 | ||
HashAlgorithm: 0 | ||
HashValues: | ||
- 1522A98D88FAF71B618D97BCAC2B89A424EC4805 | ||
- 8B2BA87CC27BF9D290A31A6070FA296AAA577E53 | ||
- EC11CE9F78D6BF61F8D913A9E2C98293782A7EB4 | ||
- 1088AD64CEBC88D9E015058A159516AF20B79286 | ||
- 457ABCB8AB70407594B5D72BF471B6BDECC99BC9 | ||
symbols: | ||
- Name: '.debug$T' | ||
Value: 0 | ||
SectionNumber: 1 | ||
SimpleType: IMAGE_SYM_TYPE_NULL | ||
ComplexType: IMAGE_SYM_DTYPE_NULL | ||
StorageClass: IMAGE_SYM_CLASS_STATIC | ||
SectionDefinition: | ||
Length: 64 | ||
NumberOfRelocations: 0 | ||
NumberOfLinenumbers: 0 | ||
CheckSum: 0 | ||
Number: 0 | ||
- Name: '.debug$H' | ||
Value: 0 | ||
SectionNumber: 2 | ||
SimpleType: IMAGE_SYM_TYPE_NULL | ||
ComplexType: IMAGE_SYM_DTYPE_NULL | ||
StorageClass: IMAGE_SYM_CLASS_STATIC | ||
SectionDefinition: | ||
Length: 108 | ||
NumberOfRelocations: 0 | ||
NumberOfLinenumbers: 0 | ||
CheckSum: 2189213922 | ||
Number: 1 | ||
... | ||
|
||
# CHECK: --- !COFF | ||
# CHECK: header: | ||
# CHECK: Machine: IMAGE_FILE_MACHINE_AMD64 | ||
# CHECK: Characteristics: [ ] | ||
# CHECK: sections: | ||
# CHECK: - Name: '.debug$T' | ||
# CHECK: Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ] | ||
# CHECK: Alignment: 1 | ||
# CHECK: Types: | ||
# CHECK: - Kind: LF_TYPESERVER2 | ||
# CHECK: TypeServer2: | ||
# CHECK: Guid: '{01DF191B-22BF-6B42-96CE-5258B8329FE5}' | ||
# CHECK: Age: 24 | ||
# CHECK: Name: 'C:\src\llvm-project\build\vc140.pdb' | ||
# CHECK: - Name: '.debug$H' | ||
# CHECK: Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ] | ||
# CHECK: Alignment: 4 | ||
# CHECK: GlobalHashes: | ||
# CHECK: Version: 0 | ||
# CHECK: HashAlgorithm: 0 | ||
# CHECK: HashValues: | ||
# CHECK: - 1522A98D88FAF71B618D97BCAC2B89A424EC4805 | ||
# CHECK: - 8B2BA87CC27BF9D290A31A6070FA296AAA577E53 | ||
# CHECK: - EC11CE9F78D6BF61F8D913A9E2C98293782A7EB4 | ||
# CHECK: - 1088AD64CEBC88D9E015058A159516AF20B79286 | ||
# CHECK: - 457ABCB8AB70407594B5D72BF471B6BDECC99BC9 | ||
# CHECK: symbols: | ||
# CHECK: - Name: '.debug$T' | ||
# CHECK: Value: 0 | ||
# CHECK: SectionNumber: 1 | ||
# CHECK: SimpleType: IMAGE_SYM_TYPE_NULL | ||
# CHECK: ComplexType: IMAGE_SYM_DTYPE_NULL | ||
# CHECK: StorageClass: IMAGE_SYM_CLASS_STATIC | ||
# CHECK: SectionDefinition: | ||
# CHECK: Length: 64 | ||
# CHECK: NumberOfRelocations: 0 | ||
# CHECK: NumberOfLinenumbers: 0 | ||
# CHECK: CheckSum: 0 | ||
# CHECK: Number: 0 | ||
# CHECK: - Name: '.debug$H' | ||
# CHECK: Value: 0 | ||
# CHECK: SectionNumber: 2 | ||
# CHECK: SimpleType: IMAGE_SYM_TYPE_NULL | ||
# CHECK: ComplexType: IMAGE_SYM_DTYPE_NULL | ||
# CHECK: StorageClass: IMAGE_SYM_CLASS_STATIC | ||
# CHECK: SectionDefinition: | ||
# CHECK: Length: 108 | ||
# CHECK: NumberOfRelocations: 0 | ||
# CHECK: NumberOfLinenumbers: 0 | ||
# CHECK: CheckSum: 2189213922 | ||
# CHECK: Number: 1 | ||
# CHECK: ... | ||
|
||
# HEADERS: 0 .debug$T 00000040 0000000000000000 DATA | ||
# HEADERS: 1 .debug$H 0000006c 0000000000000000 DATA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters