LLVM 22.0.0git
GSIStreamBuilder.h
Go to the documentation of this file.
1//===- GSIStreamBuilder.h - PDB Publics/Globals Stream Creation -*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_DEBUGINFO_PDB_NATIVE_GSISTREAMBUILDER_H
10#define LLVM_DEBUGINFO_PDB_NATIVE_GSISTREAMBUILDER_H
11
12#include "llvm/ADT/DenseSet.h"
19#include "llvm/Support/Error.h"
20
21namespace llvm {
22namespace codeview {
23class ConstantSym;
24class DataSym;
25class ProcRefSym;
26} // namespace codeview
27template <typename T> struct BinaryItemTraits;
28
29template <> struct BinaryItemTraits<codeview::CVSymbol> {
30 static size_t length(const codeview::CVSymbol &Item) {
31 return Item.RecordData.size();
32 }
34 return Item.RecordData;
35 }
36};
37
38namespace msf {
39class MSFBuilder;
40struct MSFLayout;
41} // namespace msf
42namespace pdb {
43struct GSIHashStreamBuilder;
44struct BulkPublic;
45struct SymbolDenseMapInfo;
46
48
49public:
52
55
57
58 LLVM_ABI Error commit(const msf::MSFLayout &Layout,
60
61 uint32_t getPublicsStreamIndex() const { return PublicsStreamIndex; }
62 uint32_t getGlobalsStreamIndex() const { return GlobalsStreamIndex; }
63 uint32_t getRecordStreamIndex() const { return RecordStreamIndex; }
64
65 // Add public symbols in bulk.
66 LLVM_ABI void addPublicSymbols(std::vector<BulkPublic> &&PublicsIn);
67
71
72 // Add a pre-serialized global symbol record. The caller must ensure that the
73 // symbol data remains alive until the global stream is committed to disk.
75
76private:
77 void finalizePublicBuckets();
78 void finalizeGlobalBuckets(uint32_t RecordZeroOffset);
79
80 template <typename T> void serializeAndAddGlobal(const T &Symbol);
81
82 uint32_t calculatePublicsHashStreamSize() const;
83 uint32_t calculateGlobalsHashStreamSize() const;
84 Error commitSymbolRecordStream(WritableBinaryStreamRef Stream);
85 Error commitPublicsHashStream(WritableBinaryStreamRef Stream);
86 Error commitGlobalsHashStream(WritableBinaryStreamRef Stream);
87
88 uint32_t PublicsStreamIndex = kInvalidStreamIndex;
89 uint32_t GlobalsStreamIndex = kInvalidStreamIndex;
90 uint32_t RecordStreamIndex = kInvalidStreamIndex;
91 msf::MSFBuilder &Msf;
92 std::unique_ptr<GSIHashStreamBuilder> PSH;
93 std::unique_ptr<GSIHashStreamBuilder> GSH;
94
95 // List of all of the public records. These are stored unserialized so that we
96 // can defer copying the names until we are ready to commit the PDB.
97 std::vector<BulkPublic> Publics;
98
99 // List of all of the global records.
100 std::vector<codeview::CVSymbol> Globals;
101
102 // Hash table for deduplicating global typedef and constant records. Only used
103 // for globals.
105};
106
107/// This struct is equivalent to codeview::PublicSym32, but it has been
108/// optimized for size to speed up bulk serialization and sorting operations
109/// during PDB writing.
112
113 const char *Name = nullptr;
115
116 // Offset of the symbol record in the publics stream.
118
119 // Section offset of the symbol in the image.
121
122 // Section index of the section containing the symbol.
124
125 // PublicSymFlags.
127
128 // GSI hash table bucket index. The maximum value is IPHR_HASH.
130 static_assert(IPHR_HASH <= 1 << 12, "bitfield too small");
131
133 Flags = uint32_t(F);
134 assert(Flags == uint32_t(F) && "truncated");
135 }
136
138 assert(B < IPHR_HASH);
139 BucketIdx = B;
140 }
141
142 StringRef getName() const { return StringRef(Name, NameLen); }
143};
144
145static_assert(sizeof(BulkPublic) <= 24, "unexpected size increase");
146static_assert(std::is_trivially_copyable<BulkPublic>::value,
147 "should be trivial");
148
149} // namespace pdb
150} // namespace llvm
151
152#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition: Compiler.h:213
This file defines the DenseSet and SmallDenseSet classes.
Symbol * Sym
Definition: ELF_riscv.cpp:479
#define F(x, y, z)
Definition: MD5.cpp:55
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:147
Implements a dense probed hash-table based set.
Definition: DenseSet.h:263
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
CVRecord is a fat pointer (base + size pair) to a symbol or type record.
Definition: CVRecord.h:29
ArrayRef< uint8_t > RecordData
Definition: CVRecord.h:60
LLVM_ABI void addPublicSymbols(std::vector< BulkPublic > &&PublicsIn)
uint32_t getRecordStreamIndex() const
GSIStreamBuilder(const GSIStreamBuilder &)=delete
LLVM_ABI Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef Buffer)
LLVM_ABI void addGlobalSymbol(const codeview::ProcRefSym &Sym)
GSIStreamBuilder & operator=(const GSIStreamBuilder &)=delete
uint32_t getPublicsStreamIndex() const
uint32_t getGlobalsStreamIndex() const
PublicSymFlags
Corresponds to the CV_PUBSYMFLAGS bitfield.
Definition: CodeView.h:406
const uint16_t kInvalidStreamIndex
Definition: RawConstants.h:19
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
static size_t length(const codeview::CVSymbol &Item)
static ArrayRef< uint8_t > bytes(const codeview::CVSymbol &Item)
This struct is equivalent to codeview::PublicSym32, but it has been optimized for size to speed up bu...
StringRef getName() const
void setFlags(codeview::PublicSymFlags F)
void setBucketIdx(uint16_t B)