Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:45

0001 //===- RawTypes.h -----------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_DEBUGINFO_PDB_NATIVE_RAWTYPES_H
0010 #define LLVM_DEBUGINFO_PDB_NATIVE_RAWTYPES_H
0011 
0012 #include "llvm/DebugInfo/CodeView/GUID.h"
0013 #include "llvm/DebugInfo/CodeView/TypeRecord.h"
0014 #include "llvm/Support/Endian.h"
0015 
0016 namespace llvm {
0017 namespace pdb {
0018 // This struct is defined as "SO" in langapi/include/pdb.h.
0019 struct SectionOffset {
0020   support::ulittle32_t Off;
0021   support::ulittle16_t Isect;
0022   char Padding[2];
0023 };
0024 
0025 /// Header of the hash tables found in the globals and publics sections.
0026 /// Based on GSIHashHdr in
0027 /// https://github.com/Microsoft/microsoft-pdb/blob/master/PDB/dbi/gsi.h
0028 struct GSIHashHeader {
0029   enum : unsigned {
0030     HdrSignature = ~0U,
0031     HdrVersion = 0xeffe0000 + 19990810,
0032   };
0033   support::ulittle32_t VerSignature;
0034   support::ulittle32_t VerHdr;
0035   support::ulittle32_t HrSize;
0036   support::ulittle32_t NumBuckets;
0037 };
0038 
0039 // This is HRFile.
0040 struct PSHashRecord {
0041   support::ulittle32_t Off; // Offset in the symbol record stream
0042   support::ulittle32_t CRef;
0043 };
0044 
0045 // This struct is defined as `SC` in include/dbicommon.h
0046 struct SectionContrib {
0047   support::ulittle16_t ISect;
0048   char Padding[2];
0049   support::little32_t Off;
0050   support::little32_t Size;
0051   support::ulittle32_t Characteristics;
0052   support::ulittle16_t Imod;
0053   char Padding2[2];
0054   support::ulittle32_t DataCrc;
0055   support::ulittle32_t RelocCrc;
0056 };
0057 
0058 // This struct is defined as `SC2` in include/dbicommon.h
0059 struct SectionContrib2 {
0060   // To guarantee SectionContrib2 is standard layout, we cannot use inheritance.
0061   SectionContrib Base;
0062   support::ulittle32_t ISectCoff;
0063 };
0064 
0065 // This corresponds to the `OMFSegMap` structure.
0066 struct SecMapHeader {
0067   support::ulittle16_t SecCount;    // Number of segment descriptors in table
0068   support::ulittle16_t SecCountLog; // Number of logical segment descriptors
0069 };
0070 
0071 // This corresponds to the `OMFSegMapDesc` structure.  The definition is not
0072 // present in the reference implementation, but the layout is derived from
0073 // code that accesses the fields.
0074 struct SecMapEntry {
0075   support::ulittle16_t Flags; // Descriptor flags.  See OMFSegDescFlags
0076   support::ulittle16_t Ovl;   // Logical overlay number.
0077   support::ulittle16_t Group; // Group index into descriptor array.
0078   support::ulittle16_t Frame;
0079   support::ulittle16_t SecName;       // Byte index of the segment or group name
0080                                       // in the sstSegName table, or 0xFFFF.
0081   support::ulittle16_t ClassName;     // Byte index of the class name in the
0082                                       // sstSegName table, or 0xFFFF.
0083   support::ulittle32_t Offset;        // Byte offset of the logical segment
0084                                       // within the specified physical segment.
0085                                       // If group is set in flags, offset is the
0086                                       // offset of the group.
0087   support::ulittle32_t SecByteLength; // Byte count of the segment or group.
0088 };
0089 
0090 /// Some of the values are stored in bitfields.  Since this needs to be portable
0091 /// across compilers and architectures (big / little endian in particular) we
0092 /// can't use the actual structures below, but must instead do the shifting
0093 /// and masking ourselves.  The struct definitions are provided for reference.
0094 struct DbiFlags {
0095   ///  uint16_t IncrementalLinking : 1; // True if linked incrementally
0096   ///  uint16_t IsStripped : 1;         // True if private symbols were
0097   ///  stripped.
0098   ///  uint16_t HasCTypes : 1;          // True if linked with /debug:ctypes.
0099   ///  uint16_t Reserved : 13;
0100   static const uint16_t FlagIncrementalMask = 0x0001;
0101   static const uint16_t FlagStrippedMask = 0x0002;
0102   static const uint16_t FlagHasCTypesMask = 0x0004;
0103 };
0104 
0105 struct DbiBuildNo {
0106   ///  uint16_t MinorVersion : 8;
0107   ///  uint16_t MajorVersion : 7;
0108   ///  uint16_t NewVersionFormat : 1;
0109   static const uint16_t BuildMinorMask = 0x00FF;
0110   static const uint16_t BuildMinorShift = 0;
0111 
0112   static const uint16_t BuildMajorMask = 0x7F00;
0113   static const uint16_t BuildMajorShift = 8;
0114 
0115   static const uint16_t NewVersionFormatMask = 0x8000;
0116 };
0117 
0118 /// The fixed size header that appears at the beginning of the DBI Stream.
0119 struct DbiStreamHeader {
0120   support::little32_t VersionSignature;
0121   support::ulittle32_t VersionHeader;
0122 
0123   /// How "old" is this DBI Stream. Should match the age of the PDB InfoStream.
0124   support::ulittle32_t Age;
0125 
0126   /// Global symbol stream #
0127   support::ulittle16_t GlobalSymbolStreamIndex;
0128 
0129   /// See DbiBuildNo structure.
0130   support::ulittle16_t BuildNumber;
0131 
0132   /// Public symbols stream #
0133   support::ulittle16_t PublicSymbolStreamIndex;
0134 
0135   /// version of mspdbNNN.dll
0136   support::ulittle16_t PdbDllVersion;
0137 
0138   /// Symbol records stream #
0139   support::ulittle16_t SymRecordStreamIndex;
0140 
0141   /// rbld number of mspdbNNN.dll
0142   support::ulittle16_t PdbDllRbld;
0143 
0144   /// Size of module info stream
0145   support::little32_t ModiSubstreamSize;
0146 
0147   /// Size of sec. contrib stream
0148   support::little32_t SecContrSubstreamSize;
0149 
0150   /// Size of sec. map substream
0151   support::little32_t SectionMapSize;
0152 
0153   /// Size of file info substream
0154   support::little32_t FileInfoSize;
0155 
0156   /// Size of type server map
0157   support::little32_t TypeServerSize;
0158 
0159   /// Index of MFC Type Server
0160   support::ulittle32_t MFCTypeServerIndex;
0161 
0162   /// Size of DbgHeader info
0163   support::little32_t OptionalDbgHdrSize;
0164 
0165   /// Size of EC stream (what is EC?)
0166   support::little32_t ECSubstreamSize;
0167 
0168   /// See DbiFlags enum.
0169   support::ulittle16_t Flags;
0170 
0171   /// See PDB_MachineType enum.
0172   support::ulittle16_t MachineType;
0173 
0174   /// Pad to 64 bytes
0175   support::ulittle32_t Reserved;
0176 };
0177 static_assert(sizeof(DbiStreamHeader) == 64, "Invalid DbiStreamHeader size!");
0178 
0179 /// The header preceding the File Info Substream of the DBI stream.
0180 struct FileInfoSubstreamHeader {
0181   /// Total # of modules, should match number of records in the ModuleInfo
0182   /// substream.
0183   support::ulittle16_t NumModules;
0184 
0185   /// Total # of source files. This value is not accurate because PDB actually
0186   /// supports more than 64k source files, so we ignore it and compute the value
0187   /// from other stream fields.
0188   support::ulittle16_t NumSourceFiles;
0189 
0190   /// Following this header the File Info Substream is laid out as follows:
0191   ///   ulittle16_t ModIndices[NumModules];
0192   ///   ulittle16_t ModFileCounts[NumModules];
0193   ///   ulittle32_t FileNameOffsets[NumSourceFiles];
0194   ///   char Names[][NumSourceFiles];
0195   /// with the caveat that `NumSourceFiles` cannot be trusted, so
0196   /// it is computed by summing the `ModFileCounts` array.
0197 };
0198 
0199 struct ModInfoFlags {
0200   ///  uint16_t fWritten : 1;   // True if DbiModuleDescriptor is dirty
0201   ///  uint16_t fECEnabled : 1; // Is EC symbolic info present?  (What is EC?)
0202   ///  uint16_t unused : 6;     // Reserved
0203   ///  uint16_t iTSM : 8;       // Type Server Index for this module
0204   static const uint16_t HasECFlagMask = 0x2;
0205 
0206   static const uint16_t TypeServerIndexMask = 0xFF00;
0207   static const uint16_t TypeServerIndexShift = 8;
0208 };
0209 
0210 /// The header preceding each entry in the Module Info substream of the DBI
0211 /// stream.  Corresponds to the type MODI in the reference implementation.
0212 struct ModuleInfoHeader {
0213   /// Currently opened module. This field is a pointer in the reference
0214   /// implementation, but that won't work on 64-bit systems, and anyway it
0215   /// doesn't make sense to read a pointer from a file. For now it is unused,
0216   /// so just ignore it.
0217   support::ulittle32_t Mod;
0218 
0219   /// First section contribution of this module.
0220   SectionContrib SC;
0221 
0222   /// See ModInfoFlags definition.
0223   support::ulittle16_t Flags;
0224 
0225   /// Stream Number of module debug info
0226   support::ulittle16_t ModDiStream;
0227 
0228   /// Size of local symbol debug info in above stream
0229   support::ulittle32_t SymBytes;
0230 
0231   /// Size of C11 line number info in above stream
0232   support::ulittle32_t C11Bytes;
0233 
0234   /// Size of C13 line number info in above stream
0235   support::ulittle32_t C13Bytes;
0236 
0237   /// Number of files contributing to this module
0238   support::ulittle16_t NumFiles;
0239 
0240   /// Padding so the next field is 4-byte aligned.
0241   char Padding1[2];
0242 
0243   /// Array of [0..NumFiles) DBI name buffer offsets.  In the reference
0244   /// implementation this field is a pointer.  But since you can't portably
0245   /// serialize a pointer, on 64-bit platforms they copy all the values except
0246   /// this one into the 32-bit version of the struct and use that for
0247   /// serialization.  Regardless, this field is unused, it is only there to
0248   /// store a pointer that can be accessed at runtime.
0249   support::ulittle32_t FileNameOffs;
0250 
0251   /// Name Index for src file name
0252   support::ulittle32_t SrcFileNameNI;
0253 
0254   /// Name Index for path to compiler PDB
0255   support::ulittle32_t PdbFilePathNI;
0256 
0257   /// Following this header are two zero terminated strings.
0258   /// char ModuleName[];
0259   /// char ObjFileName[];
0260 };
0261 
0262 // This is PSGSIHDR struct defined in
0263 // https://github.com/Microsoft/microsoft-pdb/blob/master/PDB/dbi/gsi.h
0264 struct PublicsStreamHeader {
0265   support::ulittle32_t SymHash;
0266   support::ulittle32_t AddrMap;
0267   support::ulittle32_t NumThunks;
0268   support::ulittle32_t SizeOfThunk;
0269   support::ulittle16_t ISectThunkTable;
0270   char Padding[2];
0271   support::ulittle32_t OffThunkTable;
0272   support::ulittle32_t NumSections;
0273 };
0274 
0275 // The header preceding the global TPI stream.
0276 // This corresponds to `HDR` in PDB/dbi/tpi.h.
0277 struct TpiStreamHeader {
0278   struct EmbeddedBuf {
0279     support::little32_t Off;
0280     support::ulittle32_t Length;
0281   };
0282 
0283   support::ulittle32_t Version;
0284   support::ulittle32_t HeaderSize;
0285   support::ulittle32_t TypeIndexBegin;
0286   support::ulittle32_t TypeIndexEnd;
0287   support::ulittle32_t TypeRecordBytes;
0288 
0289   // The following members correspond to `TpiHash` in PDB/dbi/tpi.h.
0290   support::ulittle16_t HashStreamIndex;
0291   support::ulittle16_t HashAuxStreamIndex;
0292   support::ulittle32_t HashKeySize;
0293   support::ulittle32_t NumHashBuckets;
0294 
0295   EmbeddedBuf HashValueBuffer;
0296   EmbeddedBuf IndexOffsetBuffer;
0297   EmbeddedBuf HashAdjBuffer;
0298 };
0299 
0300 const uint32_t MinTpiHashBuckets = 0x1000;
0301 const uint32_t MaxTpiHashBuckets = 0x40000;
0302 
0303 /// The header preceding the global PDB Stream (Stream 1)
0304 struct InfoStreamHeader {
0305   support::ulittle32_t Version;
0306   support::ulittle32_t Signature;
0307   support::ulittle32_t Age;
0308   codeview::GUID Guid;
0309 };
0310 
0311 /// The header preceding the /names stream.
0312 struct PDBStringTableHeader {
0313   support::ulittle32_t Signature;   // PDBStringTableSignature
0314   support::ulittle32_t HashVersion; // 1 or 2
0315   support::ulittle32_t ByteSize;    // Number of bytes of names buffer.
0316 };
0317 
0318 const uint32_t PDBStringTableSignature = 0xEFFEEFFE;
0319 
0320 /// The header preceding the /src/headerblock stream.
0321 struct SrcHeaderBlockHeader {
0322   support::ulittle32_t Version; // PdbRaw_SrcHeaderBlockVer enumeration.
0323   support::ulittle32_t Size;    // Size of entire stream.
0324   uint64_t FileTime;            // Time stamp (Windows FILETIME format).
0325   support::ulittle32_t Age;     // Age
0326   uint8_t Padding[44];          // Pad to 64 bytes.
0327 };
0328 static_assert(sizeof(SrcHeaderBlockHeader) == 64, "Incorrect struct size!");
0329 
0330 /// A single file record entry within the /src/headerblock stream.
0331 struct SrcHeaderBlockEntry {
0332   support::ulittle32_t Size;     // Record Length.
0333   support::ulittle32_t Version;  // PdbRaw_SrcHeaderBlockVer enumeration.
0334   support::ulittle32_t CRC;      // CRC of the original file contents.
0335   support::ulittle32_t FileSize; // Size of original source file.
0336   support::ulittle32_t FileNI;   // String table index of file name.
0337   support::ulittle32_t ObjNI;    // String table index of object name.
0338   support::ulittle32_t VFileNI;  // String table index of virtual file name.
0339   uint8_t Compression;           // PDB_SourceCompression enumeration.
0340   uint8_t IsVirtual;             // Is this a virtual file (injected)?
0341   short Padding;                 // Pad to 4 bytes.
0342   char Reserved[8];
0343 };
0344 static_assert(sizeof(SrcHeaderBlockEntry) == 40, "Incorrect struct size!");
0345 
0346 } // namespace pdb
0347 } // namespace llvm
0348 
0349 #endif