Line data Source code
1 : //===- RawTypes.h -----------------------------------------------*- C++ -*-===//
2 : //
3 : // The LLVM Compiler Infrastructure
4 : //
5 : // This file is distributed under the University of Illinois Open Source
6 : // License. See LICENSE.TXT for details.
7 : //
8 : //===----------------------------------------------------------------------===//
9 :
10 : #ifndef LLVM_DEBUGINFO_PDB_RAW_RAWTYPES_H
11 : #define LLVM_DEBUGINFO_PDB_RAW_RAWTYPES_H
12 :
13 : #include "llvm/DebugInfo/CodeView/TypeRecord.h"
14 : #include "llvm/Support/Endian.h"
15 :
16 : namespace llvm {
17 : namespace pdb {
18 : // This struct is defined as "SO" in langapi/include/pdb.h.
19 : struct SectionOffset {
20 : support::ulittle32_t Off;
21 : support::ulittle16_t Isect;
22 : char Padding[2];
23 : };
24 :
25 : // This is HRFile.
26 : struct PSHashRecord {
27 : support::ulittle32_t Off; // Offset in the symbol record stream
28 : support::ulittle32_t CRef;
29 : };
30 :
31 : // This struct is defined as `SC` in include/dbicommon.h
32 : struct SectionContrib {
33 : support::ulittle16_t ISect;
34 : char Padding[2];
35 : support::little32_t Off;
36 : support::little32_t Size;
37 : support::ulittle32_t Characteristics;
38 : support::ulittle16_t Imod;
39 : char Padding2[2];
40 : support::ulittle32_t DataCrc;
41 : support::ulittle32_t RelocCrc;
42 : };
43 :
44 : // This struct is defined as `SC2` in include/dbicommon.h
45 : struct SectionContrib2 {
46 : // To guarantee SectionContrib2 is standard layout, we cannot use inheritance.
47 : SectionContrib Base;
48 : support::ulittle32_t ISectCoff;
49 : };
50 :
51 : // This corresponds to the `OMFSegMap` structure.
52 : struct SecMapHeader {
53 : support::ulittle16_t SecCount; // Number of segment descriptors in table
54 : support::ulittle16_t SecCountLog; // Number of logical segment descriptors
55 : };
56 :
57 : // This corresponds to the `OMFSegMapDesc` structure. The definition is not
58 : // present in the reference implementation, but the layout is derived from
59 : // code that accesses the fields.
60 : struct SecMapEntry {
61 : support::ulittle16_t Flags; // Descriptor flags. See OMFSegDescFlags
62 : support::ulittle16_t Ovl; // Logical overlay number.
63 : support::ulittle16_t Group; // Group index into descriptor array.
64 : support::ulittle16_t Frame;
65 : support::ulittle16_t SecName; // Byte index of the segment or group name
66 : // in the sstSegName table, or 0xFFFF.
67 : support::ulittle16_t ClassName; // Byte index of the class name in the
68 : // sstSegName table, or 0xFFFF.
69 : support::ulittle32_t Offset; // Byte offset of the logical segment
70 : // within the specified physical segment.
71 : // If group is set in flags, offset is the
72 : // offset of the group.
73 : support::ulittle32_t SecByteLength; // Byte count of the segment or group.
74 : };
75 :
76 : // Used for serialized hash table in TPI stream.
77 : // In the reference, it is an array of TI and cbOff pair.
78 : struct TypeIndexOffset {
79 : codeview::TypeIndex Type;
80 : support::ulittle32_t Offset;
81 : };
82 :
83 : /// Some of the values are stored in bitfields. Since this needs to be portable
84 : /// across compilers and architectures (big / little endian in particular) we
85 : /// can't use the actual structures below, but must instead do the shifting
86 : /// and masking ourselves. The struct definitions are provided for reference.
87 : struct DbiFlags {
88 : /// uint16_t IncrementalLinking : 1; // True if linked incrementally
89 : /// uint16_t IsStripped : 1; // True if private symbols were
90 : /// stripped.
91 : /// uint16_t HasCTypes : 1; // True if linked with /debug:ctypes.
92 : /// uint16_t Reserved : 13;
93 : static const uint16_t FlagIncrementalMask = 0x0001;
94 : static const uint16_t FlagStrippedMask = 0x0002;
95 : static const uint16_t FlagHasCTypesMask = 0x0004;
96 : };
97 :
98 : struct DbiBuildNo {
99 : /// uint16_t MinorVersion : 8;
100 : /// uint16_t MajorVersion : 7;
101 : /// uint16_t NewVersionFormat : 1;
102 : static const uint16_t BuildMinorMask = 0x00FF;
103 : static const uint16_t BuildMinorShift = 0;
104 :
105 : static const uint16_t BuildMajorMask = 0x7F00;
106 : static const uint16_t BuildMajorShift = 8;
107 : };
108 :
109 : /// The fixed size header that appears at the beginning of the DBI Stream.
110 : struct DbiStreamHeader {
111 : support::little32_t VersionSignature;
112 : support::ulittle32_t VersionHeader;
113 :
114 : /// How "old" is this DBI Stream. Should match the age of the PDB InfoStream.
115 : support::ulittle32_t Age;
116 :
117 : /// Global symbol stream #
118 : support::ulittle16_t GlobalSymbolStreamIndex;
119 :
120 : /// See DbiBuildNo structure.
121 : support::ulittle16_t BuildNumber;
122 :
123 : /// Public symbols stream #
124 : support::ulittle16_t PublicSymbolStreamIndex;
125 :
126 : /// version of mspdbNNN.dll
127 : support::ulittle16_t PdbDllVersion;
128 :
129 : /// Symbol records stream #
130 : support::ulittle16_t SymRecordStreamIndex;
131 :
132 : /// rbld number of mspdbNNN.dll
133 : support::ulittle16_t PdbDllRbld;
134 :
135 : /// Size of module info stream
136 : support::little32_t ModiSubstreamSize;
137 :
138 : /// Size of sec. contrib stream
139 : support::little32_t SecContrSubstreamSize;
140 :
141 : /// Size of sec. map substream
142 : support::little32_t SectionMapSize;
143 :
144 : /// Size of file info substream
145 : support::little32_t FileInfoSize;
146 :
147 : /// Size of type server map
148 : support::little32_t TypeServerSize;
149 :
150 : /// Index of MFC Type Server
151 : support::ulittle32_t MFCTypeServerIndex;
152 :
153 : /// Size of DbgHeader info
154 : support::little32_t OptionalDbgHdrSize;
155 :
156 : /// Size of EC stream (what is EC?)
157 : support::little32_t ECSubstreamSize;
158 :
159 : /// See DbiFlags enum.
160 : support::ulittle16_t Flags;
161 :
162 : /// See PDB_MachineType enum.
163 : support::ulittle16_t MachineType;
164 :
165 : /// Pad to 64 bytes
166 : support::ulittle32_t Reserved;
167 : };
168 : static_assert(sizeof(DbiStreamHeader) == 64, "Invalid DbiStreamHeader size!");
169 :
170 : struct SectionContribEntry {
171 : support::ulittle16_t Section;
172 : char Padding1[2];
173 : support::little32_t Offset;
174 : support::little32_t Size;
175 : support::ulittle32_t Characteristics;
176 : support::ulittle16_t ModuleIndex;
177 : char Padding2[2];
178 : support::ulittle32_t DataCrc;
179 : support::ulittle32_t RelocCrc;
180 : };
181 :
182 : /// The header preceeding the File Info Substream of the DBI stream.
183 : struct FileInfoSubstreamHeader {
184 : /// Total # of modules, should match number of records in the ModuleInfo
185 : /// substream.
186 : support::ulittle16_t NumModules;
187 :
188 : /// Total # of source files. This value is not accurate because PDB actually
189 : /// supports more than 64k source files, so we ignore it and compute the value
190 : /// from other stream fields.
191 : support::ulittle16_t NumSourceFiles;
192 :
193 : /// Following this header the File Info Substream is laid out as follows:
194 : /// ulittle16_t ModIndices[NumModules];
195 : /// ulittle16_t ModFileCounts[NumModules];
196 : /// ulittle32_t FileNameOffsets[NumSourceFiles];
197 : /// char Names[][NumSourceFiles];
198 : /// with the caveat that `NumSourceFiles` cannot be trusted, so
199 : /// it is computed by summing the `ModFileCounts` array.
200 : };
201 :
202 : struct ModInfoFlags {
203 : /// uint16_t fWritten : 1; // True if ModInfo is dirty
204 : /// uint16_t fECEnabled : 1; // Is EC symbolic info present? (What is EC?)
205 : /// uint16_t unused : 6; // Reserved
206 : /// uint16_t iTSM : 8; // Type Server Index for this module
207 : static const uint16_t HasECFlagMask = 0x2;
208 :
209 : static const uint16_t TypeServerIndexMask = 0xFF00;
210 : static const uint16_t TypeServerIndexShift = 8;
211 : };
212 :
213 : /// The header preceeding each entry in the Module Info substream of the DBI
214 : /// stream.
215 : struct ModuleInfoHeader {
216 : /// Currently opened module. This field is a pointer in the reference
217 : /// implementation, but that won't work on 64-bit systems, and anyway it
218 : /// doesn't make sense to read a pointer from a file. For now it is unused,
219 : /// so just ignore it.
220 : support::ulittle32_t Mod;
221 :
222 : /// First section contribution of this module.
223 : SectionContribEntry SC;
224 :
225 : /// See ModInfoFlags definition.
226 : support::ulittle16_t Flags;
227 :
228 : /// Stream Number of module debug info
229 : support::ulittle16_t ModDiStream;
230 :
231 : /// Size of local symbol debug info in above stream
232 : support::ulittle32_t SymBytes;
233 :
234 : /// Size of line number debug info in above stream
235 : support::ulittle32_t LineBytes;
236 :
237 : /// Size of C13 line number info in above stream
238 : support::ulittle32_t C13Bytes;
239 :
240 : /// Number of files contributing to this module
241 : support::ulittle16_t NumFiles;
242 :
243 : /// Padding so the next field is 4-byte aligned.
244 : char Padding1[2];
245 :
246 : /// Array of [0..NumFiles) DBI name buffer offsets. This field is a pointer
247 : /// in the reference implementation, but as with `Mod`, we ignore it for now
248 : /// since it is unused.
249 : support::ulittle32_t FileNameOffs;
250 :
251 : /// Name Index for src file name
252 : support::ulittle32_t SrcFileNameNI;
253 :
254 : /// Name Index for path to compiler PDB
255 : support::ulittle32_t PdbFilePathNI;
256 :
257 : /// Following this header are two zero terminated strings.
258 : /// char ModuleName[];
259 : /// char ObjFileName[];
260 : };
261 :
262 : /// Defines a 128-bit unique identifier. This maps to a GUID on Windows, but
263 : /// is abstracted here for the purposes of non-Windows platforms that don't have
264 : /// the GUID structure defined.
265 : struct PDB_UniqueId {
266 : uint8_t Guid[16];
267 : };
268 :
269 : // The header preceeding the global TPI stream.
270 : // This corresponds to `HDR` in PDB/dbi/tpi.h.
271 : struct TpiStreamHeader {
272 : struct EmbeddedBuf {
273 : support::little32_t Off;
274 : support::ulittle32_t Length;
275 : };
276 :
277 : support::ulittle32_t Version;
278 : support::ulittle32_t HeaderSize;
279 : support::ulittle32_t TypeIndexBegin;
280 : support::ulittle32_t TypeIndexEnd;
281 : support::ulittle32_t TypeRecordBytes;
282 :
283 : // The following members correspond to `TpiHash` in PDB/dbi/tpi.h.
284 : support::ulittle16_t HashStreamIndex;
285 : support::ulittle16_t HashAuxStreamIndex;
286 : support::ulittle32_t HashKeySize;
287 : support::ulittle32_t NumHashBuckets;
288 :
289 : EmbeddedBuf HashValueBuffer;
290 : EmbeddedBuf IndexOffsetBuffer;
291 : EmbeddedBuf HashAdjBuffer;
292 : };
293 :
294 : const uint32_t MinTpiHashBuckets = 0x1000;
295 : const uint32_t MaxTpiHashBuckets = 0x40000;
296 :
297 : /// The header preceeding the global PDB Stream (Stream 1)
298 4 : struct InfoStreamHeader {
299 : support::ulittle32_t Version;
300 : support::ulittle32_t Signature;
301 : support::ulittle32_t Age;
302 : PDB_UniqueId Guid;
303 : };
304 :
305 : /// The header preceeding the /names stream.
306 5 : struct StringTableHeader {
307 : support::ulittle32_t Signature;
308 : support::ulittle32_t HashVersion;
309 : support::ulittle32_t ByteSize;
310 : };
311 :
312 : const uint32_t StringTableSignature = 0xEFFEEFFE;
313 :
314 : } // namespace pdb
315 : } // namespace llvm
316 :
317 : #endif
|