10
10
#define LLD_COFF_DEBUGTYPES_H
11
11
12
12
#include " lld/Common/LLVM.h"
13
- #include " llvm/ADT/BitVector.h"
14
- #include " llvm/ADT/DenseMap.h"
15
- #include " llvm/DebugInfo/CodeView/TypeIndexDiscovery.h"
16
- #include " llvm/DebugInfo/CodeView/TypeRecord.h"
13
+ #include " llvm/DebugInfo/CodeView/TypeIndex.h"
17
14
#include " llvm/Support/Error.h"
18
15
#include " llvm/Support/MemoryBuffer.h"
19
16
20
17
namespace llvm {
21
18
namespace codeview {
22
- struct GloballyHashedType ;
19
+ class PrecompRecord ;
20
+ class TypeServer2Record ;
23
21
} // namespace codeview
24
22
namespace pdb {
25
23
class NativeSession ;
26
- class TpiStream ;
27
24
}
28
25
} // namespace llvm
29
26
30
27
namespace lld {
31
28
namespace coff {
32
29
33
- using llvm::codeview::GloballyHashedType;
34
30
using llvm::codeview::TypeIndex;
35
31
36
32
class ObjFile ;
37
33
class PDBInputFile ;
38
34
class TypeMerger ;
39
- struct GHashState ;
40
35
41
36
class TpiSource {
42
37
public:
43
- enum TpiKind : uint8_t { Regular, PCH, UsingPCH, PDB, PDBIpi, UsingPDB };
38
+ enum TpiKind { Regular, PCH, UsingPCH, PDB, PDBIpi, UsingPDB };
44
39
45
40
TpiSource (TpiKind k, ObjFile *f);
46
41
virtual ~TpiSource ();
@@ -58,97 +53,21 @@ class TpiSource {
58
53
// / caller-provided ObjectIndexMap.
59
54
virtual Error mergeDebugT (TypeMerger *m);
60
55
61
- // / Load global hashes, either by hashing types directly, or by loading them
62
- // / from LLVM's .debug$H section.
63
- virtual void loadGHashes ();
64
-
65
- // / Use global hashes to merge type information.
66
- virtual void remapTpiWithGHashes (GHashState *g);
67
-
68
- // Remap a type index in place.
69
- bool remapTypeIndex (TypeIndex &ti, llvm::codeview::TiRefKind refKind) const ;
70
-
71
- protected:
72
- void remapRecord (MutableArrayRef<uint8_t > rec,
73
- ArrayRef<llvm::codeview::TiReference> typeRefs);
74
-
75
- void mergeTypeRecord (llvm::codeview::CVType ty);
76
-
77
- // Merge the type records listed in uniqueTypes. beginIndex is the TypeIndex
78
- // of the first record in this source, typically 0x1000. When PCHs are
79
- // involved, it may start higher.
80
- void mergeUniqueTypeRecords (
81
- ArrayRef<uint8_t > debugTypes,
82
- TypeIndex beginIndex = TypeIndex(TypeIndex::FirstNonSimpleIndex));
83
-
84
- // Use the ghash table to construct a map from source type index to
85
- // destination PDB type index. Usable for either TPI or IPI.
86
- void fillMapFromGHashes (GHashState *m,
87
- llvm::SmallVectorImpl<TypeIndex> &indexMap);
88
-
89
- // Copies ghashes from a vector into an array. These are long lived, so it's
90
- // worth the time to copy these into an appropriately sized vector to reduce
91
- // memory usage.
92
- void assignGHashesFromVector (std::vector<GloballyHashedType> &&hashVec);
93
-
94
- // Walk over file->debugTypes and fill in the isItemIndex bit vector.
95
- void fillIsItemIndexFromDebugT ();
96
-
97
- public:
98
- bool remapTypesInSymbolRecord (MutableArrayRef<uint8_t > rec);
99
-
100
- void remapTypesInTypeRecord (MutableArrayRef<uint8_t > rec);
101
-
102
56
// / Is this a dependent file that needs to be processed first, before other
103
57
// / OBJs?
104
58
virtual bool isDependency () const { return false ; }
105
59
106
- // / Returns true if this type record should be omitted from the PDB, even if
107
- // / it is unique. This prevents a record from being added to the input ghash
108
- // / table.
109
- bool shouldOmitFromPdb (uint32_t ghashIdx) {
110
- return ghashIdx == endPrecompGHashIdx;
111
- }
112
-
113
- // / All sources of type information in the program.
114
- static std::vector<TpiSource *> instances;
115
-
116
- // / Dependency type sources, such as type servers or PCH object files. These
117
- // / must be processed before objects that rely on them. Set by
118
- // / TpiSources::sortDependencies.
119
- static ArrayRef<TpiSource *> dependencySources;
120
-
121
- // / Object file sources. These must be processed after dependencySources.
122
- static ArrayRef<TpiSource *> objectSources;
123
-
124
- // / Sorts the dependencies and reassigns TpiSource indices.
125
- static void sortDependencies ();
60
+ static void forEachSource (llvm::function_ref<void (TpiSource *)> fn);
126
61
127
62
static uint32_t countTypeServerPDBs ();
128
63
static uint32_t countPrecompObjs ();
129
64
130
- // / Free heap allocated ghashes.
131
- static void clearGHashes ();
132
-
133
65
// / Clear global data structures for TpiSources.
134
66
static void clear ();
135
67
136
68
const TpiKind kind;
137
- bool ownedGHashes = true ;
138
- uint32_t tpiSrcIdx = 0 ;
139
-
140
- protected:
141
- // / The ghash index (zero based, not 0x1000-based) of the LF_ENDPRECOMP record
142
- // / in this object, if one exists. This is the all ones value otherwise. It is
143
- // / recorded here so that it can be omitted from the final ghash table.
144
- uint32_t endPrecompGHashIdx = ~0U ;
145
-
146
- public:
147
69
ObjFile *file;
148
70
149
- // / An error encountered during type merging, if any.
150
- Error typeMergingError = Error::success();
151
-
152
71
// Storage for tpiMap or ipiMap, depending on the kind of source.
153
72
llvm::SmallVector<TypeIndex, 0 > indexMapStorage;
154
73
@@ -157,31 +76,6 @@ class TpiSource {
157
76
// objects.
158
77
llvm::ArrayRef<TypeIndex> tpiMap;
159
78
llvm::ArrayRef<TypeIndex> ipiMap;
160
-
161
- // / Array of global type hashes, indexed by TypeIndex. May be calculated on
162
- // / demand, or present in input object files.
163
- llvm::ArrayRef<llvm::codeview::GloballyHashedType> ghashes;
164
-
165
- // / When ghashing is used, record the mapping from LF_[M]FUNC_ID to function
166
- // / type index here. Both indices are PDB indices, not object type indexes.
167
- llvm::DenseMap<TypeIndex, TypeIndex> funcIdToType;
168
-
169
- // / Indicates if a type record is an item index or a type index.
170
- llvm::BitVector isItemIndex;
171
-
172
- // / A list of all "unique" type indices which must be merged into the final
173
- // / PDB. GHash type deduplication produces this list, and it should be
174
- // / considerably smaller than the input.
175
- std::vector<uint32_t > uniqueTypes;
176
-
177
- struct MergedInfo {
178
- std::vector<uint8_t > recs;
179
- std::vector<uint16_t > recSizes;
180
- std::vector<uint32_t > recHashes;
181
- };
182
-
183
- MergedInfo mergedTpi;
184
- MergedInfo mergedIpi;
185
79
};
186
80
187
81
TpiSource *makeTpiSource (ObjFile *file);
0 commit comments