]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/DebugInfo/PDB/Native/RawTypes.h
Merge ^/head r317971 through r318379.
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / DebugInfo / PDB / Native / RawTypes.h
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 DbiModuleDescriptor 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.  Corresponds to the type MODI in the reference implementation.
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 C11 line number info in above stream
235   support::ulittle32_t C11Bytes;
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.  In the reference
247   /// implementation this field is a pointer.  But since you can't portably
248   /// serialize a pointer, on 64-bit platforms they copy all the values except
249   /// this one into the 32-bit version of the struct and use that for
250   /// serialization.  Regardless, this field is unused, it is only there to
251   /// store a pointer that can be accessed at runtime.
252   support::ulittle32_t FileNameOffs;
253
254   /// Name Index for src file name
255   support::ulittle32_t SrcFileNameNI;
256
257   /// Name Index for path to compiler PDB
258   support::ulittle32_t PdbFilePathNI;
259
260   /// Following this header are two zero terminated strings.
261   /// char ModuleName[];
262   /// char ObjFileName[];
263 };
264
265 /// Defines a 128-bit unique identifier.  This maps to a GUID on Windows, but
266 /// is abstracted here for the purposes of non-Windows platforms that don't have
267 /// the GUID structure defined.
268 struct PDB_UniqueId {
269   uint8_t Guid[16];
270 };
271
272 inline bool operator==(const PDB_UniqueId &LHS, const PDB_UniqueId &RHS) {
273   return 0 == ::memcmp(LHS.Guid, RHS.Guid, sizeof(LHS.Guid));
274 }
275
276 // The header preceeding the global TPI stream.
277 // This corresponds to `HDR` in PDB/dbi/tpi.h.
278 struct TpiStreamHeader {
279   struct EmbeddedBuf {
280     support::little32_t Off;
281     support::ulittle32_t Length;
282   };
283
284   support::ulittle32_t Version;
285   support::ulittle32_t HeaderSize;
286   support::ulittle32_t TypeIndexBegin;
287   support::ulittle32_t TypeIndexEnd;
288   support::ulittle32_t TypeRecordBytes;
289
290   // The following members correspond to `TpiHash` in PDB/dbi/tpi.h.
291   support::ulittle16_t HashStreamIndex;
292   support::ulittle16_t HashAuxStreamIndex;
293   support::ulittle32_t HashKeySize;
294   support::ulittle32_t NumHashBuckets;
295
296   EmbeddedBuf HashValueBuffer;
297   EmbeddedBuf IndexOffsetBuffer;
298   EmbeddedBuf HashAdjBuffer;
299 };
300
301 const uint32_t MinTpiHashBuckets = 0x1000;
302 const uint32_t MaxTpiHashBuckets = 0x40000;
303
304 /// The header preceeding the global PDB Stream (Stream 1)
305 struct InfoStreamHeader {
306   support::ulittle32_t Version;
307   support::ulittle32_t Signature;
308   support::ulittle32_t Age;
309   PDB_UniqueId Guid;
310 };
311
312 /// The header preceeding the /names stream.
313 struct PDBStringTableHeader {
314   support::ulittle32_t Signature;   // PDBStringTableSignature
315   support::ulittle32_t HashVersion; // 1 or 2
316   support::ulittle32_t ByteSize;    // Number of bytes of names buffer.
317 };
318
319 const uint32_t PDBStringTableSignature = 0xEFFEEFFE;
320
321 } // namespace pdb
322 } // namespace llvm
323
324 #endif