llvm.org GIT mirror llvm / 8b34868
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 Zachary Turner 1 year, 9 months ago
10 changed file(s) with 274 addition(s) and 64 deletion(s). Raw diff Collapse all Expand all
706706
707707 enum CodeViewIdentifiers {
708708 DEBUG_SECTION_MAGIC = 0x4,
709 DEBUG_HASHES_SECTION_MAGIC = 0x133C9C5
709710 };
710711
711712 inline bool isReservedSectionNumber(int32_t SectionNumber) {
1717 #include "llvm/ADT/StringRef.h"
1818 #include "llvm/BinaryFormat/COFF.h"
1919 #include "llvm/ObjectYAML/CodeViewYAMLDebugSections.h"
20 #include "llvm/ObjectYAML/CodeViewYAMLTypeHashing.h"
2021 #include "llvm/ObjectYAML/CodeViewYAMLTypes.h"
2122 #include "llvm/ObjectYAML/YAML.h"
2223 #include
6566 yaml::BinaryRef SectionData;
6667 std::vector DebugS;
6768 std::vector DebugT;
69 Optional DebugH;
6870 std::vector Relocations;
6971 StringRef Name;
7072
0 //==- CodeViewYAMLTypeHashing.h - CodeView YAMLIO Type hashing ----*- C++-*-==//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines classes for handling the YAML representation of CodeView
10 // Debug Info.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_OBJECTYAML_CODEVIEWYAMLTYPEHASHING_H
15 #define LLVM_OBJECTYAML_CODEVIEWYAMLTYPEHASHING_H
16
17 #include "llvm/ADT/ArrayRef.h"
18 #include "llvm/DebugInfo/CodeView/TypeHashing.h"
19 #include "llvm/ObjectYAML/YAML.h"
20 #include "llvm/Support/Allocator.h"
21 #include "llvm/Support/Error.h"
22 #include "llvm/Support/YAMLTraits.h"
23 #include
24 #include
25 #include
26
27 namespace llvm {
28
29 namespace CodeViewYAML {
30
31 struct GlobalHash {
32 GlobalHash() = default;
33 explicit GlobalHash(StringRef S) : Hash(S) {
34 assert(S.size() == 20 && "Invalid hash size!");
35 }
36 explicit GlobalHash(ArrayRef S) : Hash(S) {
37 assert(S.size() == 20 && "Invalid hash size!");
38 }
39 yaml::BinaryRef Hash;
40 };
41
42 struct DebugHSection {
43 uint32_t Magic;
44 uint16_t Version;
45 uint16_t HashAlgorithm;
46 std::vector Hashes;
47 };
48
49 DebugHSection fromDebugH(ArrayRef DebugT);
50 ArrayRef toDebugH(const DebugHSection &DebugH,
51 BumpPtrAllocator &Alloc);
52
53 } // end namespace CodeViewYAML
54
55 } // end namespace llvm
56
57 LLVM_YAML_DECLARE_MAPPING_TRAITS(CodeViewYAML::DebugHSection)
58 LLVM_YAML_DECLARE_SCALAR_TRAITS(CodeViewYAML::GlobalHash, false)
59 LLVM_YAML_IS_SEQUENCE_VECTOR(CodeViewYAML::GlobalHash)
60
61 #endif // LLVM_OBJECTYAML_CODEVIEWYAMLTYPES_H
0 add_llvm_library(LLVMObjectYAML
1 CodeViewYAMLDebugSections.cpp
2 CodeViewYAMLSymbols.cpp
3 CodeViewYAMLTypeHashing.cpp
14 CodeViewYAMLTypes.cpp
2 CodeViewYAMLSymbols.cpp
3 CodeViewYAMLDebugSections.cpp
45 COFFYAML.cpp
56 DWARFEmitter.cpp
67 DWARFVisitor.cpp
561561 IO.mapOptional("VirtualSize", Sec.Header.VirtualSize, 0U);
562562 IO.mapOptional("Alignment", Sec.Alignment, 0U);
563563
564 // If this is a .debug$S or .debug$T section parse the semantic representation
565 // of the symbols/types. If it is any other kind of section, just deal in raw
566 // bytes.
564 // If this is a .debug$S .debug$T, or .debug$H section parse the semantic
565 // representation of the symbols/types. If it is any other kind of section,
566 // just deal in raw bytes.
567567 IO.mapOptional("SectionData", Sec.SectionData);
568568 if (Sec.Name == ".debug$S")
569569 IO.mapOptional("Subsections", Sec.DebugS);
570570 else if (Sec.Name == ".debug$T")
571571 IO.mapOptional("Types", Sec.DebugT);
572 else if (Sec.Name == ".debug$H")
573 IO.mapOptional("GlobalHashes", Sec.DebugH);
572574
573575 IO.mapOptional("Relocations", Sec.Relocations);
574576 }
0 //===- CodeViewYAMLTypeHashing.cpp - CodeView YAMLIO type hashing ---------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines classes for handling the YAML representation of CodeView
10 // Debug Info.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/ObjectYAML/CodeViewYAMLTypeHashing.h"
15 #include "llvm/Support/BinaryByteStream.h"
16 #include "llvm/Support/BinaryStreamReader.h"
17 #include "llvm/Support/BinaryStreamWriter.h"
18
19 using namespace llvm;
20 using namespace llvm::codeview;
21 using namespace llvm::CodeViewYAML;
22 using namespace llvm::yaml;
23
24 namespace llvm {
25 namespace yaml {
26
27 void MappingTraits::mapping(IO &io, DebugHSection &DebugH) {
28 io.mapRequired("Version", DebugH.Version);
29 io.mapRequired("HashAlgorithm", DebugH.HashAlgorithm);
30 io.mapOptional("HashValues", DebugH.Hashes);
31 }
32
33 void ScalarTraits::output(const GlobalHash &GH, void *Ctx,
34 raw_ostream &OS) {
35 ScalarTraits::output(GH.Hash, Ctx, OS);
36 }
37
38 StringRef ScalarTraits::input(StringRef Scalar, void *Ctx,
39 GlobalHash &GH) {
40 return ScalarTraits::input(Scalar, Ctx, GH.Hash);
41 }
42
43 } // end namespace yaml
44 } // end namespace llvm
45
46 DebugHSection llvm::CodeViewYAML::fromDebugH(ArrayRef DebugT) {
47 assert(DebugT.size() >= 8);
48 assert((DebugT.size() - 8) % 20 == 0);
49
50 BinaryStreamReader Reader(DebugT, llvm::support::little);
51 DebugHSection DHS;
52 cantFail(Reader.readInteger(DHS.Magic));
53 cantFail(Reader.readInteger(DHS.Version));
54 cantFail(Reader.readInteger(DHS.HashAlgorithm));
55 while (Reader.bytesRemaining() != 0) {
56 ArrayRef S;
57 cantFail(Reader.readBytes(S, 20));
58 DHS.Hashes.emplace_back(S);
59 }
60 assert(Reader.bytesRemaining() == 0);
61 return DHS;
62 }
63
64 ArrayRef llvm::CodeViewYAML::toDebugH(const DebugHSection &DebugH,
65 BumpPtrAllocator &Alloc) {
66 uint32_t Size = 8 + 20 * DebugH.Hashes.size();
67 uint8_t *Data = Alloc.Allocate(Size);
68 MutableArrayRef Buffer(Data, Size);
69 BinaryStreamWriter Writer(Buffer, llvm::support::little);
70 cantFail(Writer.writeInteger(DebugH.Magic));
71 cantFail(Writer.writeInteger(DebugH.Version));
72 cantFail(Writer.writeInteger(DebugH.HashAlgorithm));
73 SmallString<20> Hash;
74 for (const auto &H : DebugH.Hashes) {
75 Hash.clear();
76 raw_svector_ostream OS(Hash);
77 H.Hash.writeAsBinary(OS);
78 assert((Hash.size() == 20) && "Invalid hash size!");
79 cantFail(Writer.writeFixedString(Hash));
80 }
81 assert(Writer.bytesRemaining() == 0);
82 return Buffer;
83 }
+0
-59
test/ObjectYAML/CodeView/guid.yaml less more
None # RUN: yaml2obj %s | obj2yaml | FileCheck %s
1
2 --- !COFF
3 header:
4 Machine: IMAGE_FILE_MACHINE_AMD64
5 Characteristics: [ ]
6 sections:
7 - Name: '.debug$T'
8 Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
9 Alignment: 1
10 Types:
11 - Kind: LF_TYPESERVER2
12 TypeServer2:
13 Guid: '{01DF191B-22BF-6B42-96CE-5258B8329FE5}'
14 Age: 24
15 Name: 'C:\src\llvm-project\build\vc140.pdb'
16 symbols:
17 - Name: '.debug$T'
18 Value: 0
19 SectionNumber: 1
20 SimpleType: IMAGE_SYM_TYPE_NULL
21 ComplexType: IMAGE_SYM_DTYPE_NULL
22 StorageClass: IMAGE_SYM_CLASS_STATIC
23 SectionDefinition:
24 Length: 64
25 NumberOfRelocations: 0
26 NumberOfLinenumbers: 0
27 CheckSum: 0
28 Number: 0
29 ...
30
31 # CHECK: --- !COFF
32 # CHECK: header:
33 # CHECK: Machine: IMAGE_FILE_MACHINE_AMD64
34 # CHECK: Characteristics: [ ]
35 # CHECK: sections:
36 # CHECK: - Name: '.debug$T'
37 # CHECK: Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
38 # CHECK: Alignment: 1
39 # CHECK: Types:
40 # CHECK: - Kind: LF_TYPESERVER2
41 # CHECK: TypeServer2:
42 # CHECK: Guid: '{01DF191B-22BF-6B42-96CE-5258B8329FE5}'
43 # CHECK: Age: 24
44 # CHECK: Name: 'C:\src\llvm-project\build\vc140.pdb'
45 # CHECK: symbols:
46 # CHECK: - Name: '.debug$T'
47 # CHECK: Value: 0
48 # CHECK: SectionNumber: 1
49 # CHECK: SimpleType: IMAGE_SYM_TYPE_NULL
50 # CHECK: ComplexType: IMAGE_SYM_DTYPE_NULL
51 # CHECK: StorageClass: IMAGE_SYM_CLASS_STATIC
52 # CHECK: SectionDefinition:
53 # CHECK: Length: 64
54 # CHECK: NumberOfRelocations: 0
55 # CHECK: NumberOfLinenumbers: 0
56 # CHECK: CheckSum: 0
57 # CHECK: Number: 0
58 # CHECK: ...
0 # RUN: yaml2obj %s > %t.obj
1 # RUN: obj2yaml %t.obj | FileCheck --check-prefix=CHECK %s
2 # RUN: llvm-objdump -section-headers %t.obj | FileCheck --check-prefix=HEADERS %s
3
4 --- !COFF
5 header:
6 Machine: IMAGE_FILE_MACHINE_AMD64
7 Characteristics: [ ]
8 sections:
9 - Name: '.debug$T'
10 Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
11 Alignment: 1
12 Types:
13 - Kind: LF_TYPESERVER2
14 TypeServer2:
15 Guid: '{01DF191B-22BF-6B42-96CE-5258B8329FE5}'
16 Age: 24
17 Name: 'C:\src\llvm-project\build\vc140.pdb'
18 - Name: '.debug$H'
19 Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
20 Alignment: 4
21 GlobalHashes:
22 Version: 0
23 HashAlgorithm: 0
24 HashValues:
25 - 1522A98D88FAF71B618D97BCAC2B89A424EC4805
26 - 8B2BA87CC27BF9D290A31A6070FA296AAA577E53
27 - EC11CE9F78D6BF61F8D913A9E2C98293782A7EB4
28 - 1088AD64CEBC88D9E015058A159516AF20B79286
29 - 457ABCB8AB70407594B5D72BF471B6BDECC99BC9
30 symbols:
31 - Name: '.debug$T'
32 Value: 0
33 SectionNumber: 1
34 SimpleType: IMAGE_SYM_TYPE_NULL
35 ComplexType: IMAGE_SYM_DTYPE_NULL
36 StorageClass: IMAGE_SYM_CLASS_STATIC
37 SectionDefinition:
38 Length: 64
39 NumberOfRelocations: 0
40 NumberOfLinenumbers: 0
41 CheckSum: 0
42 Number: 0
43 - Name: '.debug$H'
44 Value: 0
45 SectionNumber: 2
46 SimpleType: IMAGE_SYM_TYPE_NULL
47 ComplexType: IMAGE_SYM_DTYPE_NULL
48 StorageClass: IMAGE_SYM_CLASS_STATIC
49 SectionDefinition:
50 Length: 108
51 NumberOfRelocations: 0
52 NumberOfLinenumbers: 0
53 CheckSum: 2189213922
54 Number: 1
55 ...
56
57 # CHECK: --- !COFF
58 # CHECK: header:
59 # CHECK: Machine: IMAGE_FILE_MACHINE_AMD64
60 # CHECK: Characteristics: [ ]
61 # CHECK: sections:
62 # CHECK: - Name: '.debug$T'
63 # CHECK: Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
64 # CHECK: Alignment: 1
65 # CHECK: Types:
66 # CHECK: - Kind: LF_TYPESERVER2
67 # CHECK: TypeServer2:
68 # CHECK: Guid: '{01DF191B-22BF-6B42-96CE-5258B8329FE5}'
69 # CHECK: Age: 24
70 # CHECK: Name: 'C:\src\llvm-project\build\vc140.pdb'
71 # CHECK: - Name: '.debug$H'
72 # CHECK: Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
73 # CHECK: Alignment: 4
74 # CHECK: GlobalHashes:
75 # CHECK: Version: 0
76 # CHECK: HashAlgorithm: 0
77 # CHECK: HashValues:
78 # CHECK: - 1522A98D88FAF71B618D97BCAC2B89A424EC4805
79 # CHECK: - 8B2BA87CC27BF9D290A31A6070FA296AAA577E53
80 # CHECK: - EC11CE9F78D6BF61F8D913A9E2C98293782A7EB4
81 # CHECK: - 1088AD64CEBC88D9E015058A159516AF20B79286
82 # CHECK: - 457ABCB8AB70407594B5D72BF471B6BDECC99BC9
83 # CHECK: symbols:
84 # CHECK: - Name: '.debug$T'
85 # CHECK: Value: 0
86 # CHECK: SectionNumber: 1
87 # CHECK: SimpleType: IMAGE_SYM_TYPE_NULL
88 # CHECK: ComplexType: IMAGE_SYM_DTYPE_NULL
89 # CHECK: StorageClass: IMAGE_SYM_CLASS_STATIC
90 # CHECK: SectionDefinition:
91 # CHECK: Length: 64
92 # CHECK: NumberOfRelocations: 0
93 # CHECK: NumberOfLinenumbers: 0
94 # CHECK: CheckSum: 0
95 # CHECK: Number: 0
96 # CHECK: - Name: '.debug$H'
97 # CHECK: Value: 0
98 # CHECK: SectionNumber: 2
99 # CHECK: SimpleType: IMAGE_SYM_TYPE_NULL
100 # CHECK: ComplexType: IMAGE_SYM_DTYPE_NULL
101 # CHECK: StorageClass: IMAGE_SYM_CLASS_STATIC
102 # CHECK: SectionDefinition:
103 # CHECK: Length: 108
104 # CHECK: NumberOfRelocations: 0
105 # CHECK: NumberOfLinenumbers: 0
106 # CHECK: CheckSum: 2189213922
107 # CHECK: Number: 1
108 # CHECK: ...
109
110 # HEADERS: 0 .debug$T 00000040 0000000000000000 DATA
111 # HEADERS: 1 .debug$H 0000006c 0000000000000000 DATA
171171 NewYAMLSection.DebugS = CodeViewYAML::fromDebugS(sectionData, SC);
172172 else if (NewYAMLSection.Name == ".debug$T")
173173 NewYAMLSection.DebugT = CodeViewYAML::fromDebugT(sectionData);
174 else if (NewYAMLSection.Name == ".debug$H")
175 NewYAMLSection.DebugH = CodeViewYAML::fromDebugH(sectionData);
174176
175177 std::vector Relocations;
176178 for (const auto &Reloc : ObjSection.relocations()) {
233233 } else if (S.Name == ".debug$T") {
234234 if (S.SectionData.binary_size() == 0)
235235 S.SectionData = CodeViewYAML::toDebugT(S.DebugT, CP.Allocator);
236 } else if (S.Name == ".debug$H") {
237 if (S.DebugH.hasValue() && S.SectionData.binary_size() == 0)
238 S.SectionData = CodeViewYAML::toDebugH(*S.DebugH, CP.Allocator);
236239 }
237240
238241 if (S.SectionData.binary_size() > 0) {