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