LLVM 19.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"
18#include "llvm/Support/Error.h"
19
20namespace llvm {
21namespace codeview {
22class ConstantSym;
23class DataSym;
24class ProcRefSym;
25} // namespace codeview
26template <typename T> struct BinaryItemTraits;
27
28template <> struct BinaryItemTraits<codeview::CVSymbol> {
29 static size_t length(const codeview::CVSymbol &Item) {
30 return Item.RecordData.size();
31 }
33 return Item.RecordData;
34 }
35};
36
37namespace msf {
38class MSFBuilder;
39struct MSFLayout;
40} // namespace msf
41namespace pdb {
42struct GSIHashStreamBuilder;
43struct BulkPublic;
44struct SymbolDenseMapInfo;
45
47
48public:
49 explicit GSIStreamBuilder(msf::MSFBuilder &Msf);
51
54
56
58
59 uint32_t getPublicsStreamIndex() const { return PublicsStreamIndex; }
60 uint32_t getGlobalsStreamIndex() const { return GlobalsStreamIndex; }
61 uint32_t getRecordStreamIndex() const { return RecordStreamIndex; }
62
63 // Add public symbols in bulk.
64 void addPublicSymbols(std::vector<BulkPublic> &&PublicsIn);
65
69
70 // Add a pre-serialized global symbol record. The caller must ensure that the
71 // symbol data remains alive until the global stream is committed to disk.
73
74private:
75 void finalizePublicBuckets();
76 void finalizeGlobalBuckets(uint32_t RecordZeroOffset);
77
78 template <typename T> void serializeAndAddGlobal(const T &Symbol);
79
80 uint32_t calculatePublicsHashStreamSize() const;
81 uint32_t calculateGlobalsHashStreamSize() const;
82 Error commitSymbolRecordStream(WritableBinaryStreamRef Stream);
83 Error commitPublicsHashStream(WritableBinaryStreamRef Stream);
84 Error commitGlobalsHashStream(WritableBinaryStreamRef Stream);
85
86 uint32_t PublicsStreamIndex = kInvalidStreamIndex;
87 uint32_t GlobalsStreamIndex = kInvalidStreamIndex;
88 uint32_t RecordStreamIndex = kInvalidStreamIndex;
89 msf::MSFBuilder &Msf;
90 std::unique_ptr<GSIHashStreamBuilder> PSH;
91 std::unique_ptr<GSIHashStreamBuilder> GSH;
92
93 // List of all of the public records. These are stored unserialized so that we
94 // can defer copying the names until we are ready to commit the PDB.
95 std::vector<BulkPublic> Publics;
96
97 // List of all of the global records.
98 std::vector<codeview::CVSymbol> Globals;
99
100 // Hash table for deduplicating global typedef and constant records. Only used
101 // for globals.
103};
104
105/// This struct is equivalent to codeview::PublicSym32, but it has been
106/// optimized for size to speed up bulk serialization and sorting operations
107/// during PDB writing.
110
111 const char *Name = nullptr;
113
114 // Offset of the symbol record in the publics stream.
116
117 // Section offset of the symbol in the image.
119
120 // Section index of the section containing the symbol.
122
123 // PublicSymFlags.
125
126 // GSI hash table bucket index. The maximum value is IPHR_HASH.
128 static_assert(IPHR_HASH <= 1 << 12, "bitfield too small");
129
131 Flags = uint32_t(F);
132 assert(Flags == uint32_t(F) && "truncated");
133 }
134
136 assert(B < IPHR_HASH);
137 BucketIdx = B;
138 }
139
140 StringRef getName() const { return StringRef(Name, NameLen); }
141};
142
143static_assert(sizeof(BulkPublic) <= 24, "unexpected size increase");
144static_assert(std::is_trivially_copyable<BulkPublic>::value,
145 "should be trivial");
146
147} // namespace pdb
148} // namespace llvm
149
150#endif
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file defines the DenseSet and SmallDenseSet classes.
Symbol * Sym
Definition: ELF_riscv.cpp:479
#define F(x, y, z)
Definition: MD5.cpp:55
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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:165
Implements a dense probed hash-table based set.
Definition: DenseSet.h:271
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
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
void addPublicSymbols(std::vector< BulkPublic > &&PublicsIn)
uint32_t getRecordStreamIndex() const
GSIStreamBuilder(const GSIStreamBuilder &)=delete
Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef Buffer)
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:433
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)