82 return LHS.RecordData ==
RHS.RecordData;
88struct PublicSym32Layout {
99 NameLen = std::min(NameLen,
101 return alignTo(
sizeof(PublicSym32Layout) + NameLen + 1, 4);
108 size_t Size =
alignTo(
sizeof(PublicSym32Layout) + NameLen + 1, 4);
110 auto *FixedMem =
reinterpret_cast<PublicSym32Layout *
>(Mem);
111 FixedMem->Prefix.RecordKind =
static_cast<uint16_t>(codeview::S_PUB32);
112 FixedMem->Prefix.RecordLen =
static_cast<uint16_t>(
Size - 2);
113 FixedMem->Pub.Flags = Pub.
Flags;
114 FixedMem->Pub.Offset = Pub.
Offset;
115 FixedMem->Pub.Segment = Pub.
Segment;
116 char *NameMem =
reinterpret_cast<char *
>(FixedMem + 1);
117 memcpy(NameMem, Pub.
Name, NameLen);
119 memset(&NameMem[NameLen], 0,
Size -
sizeof(PublicSym32Layout) - NameLen);
156 size_t LS = S1.
size();
157 size_t RS = S2.
size();
160 return (LS > RS) - (LS < RS);
170void GSIStreamBuilder::finalizePublicBuckets() {
171 PSH->finalizeBuckets(0, Publics);
174void GSIStreamBuilder::finalizeGlobalBuckets(
uint32_t RecordZeroOffset) {
183 std::vector<BulkPublic> Records;
184 Records.resize(Globals.size());
185 uint32_t SymOffset = RecordZeroOffset;
186 for (
size_t I = 0,
E = Globals.size();
I <
E; ++
I) {
188 Records[
I].Name =
Name.data();
189 Records[
I].NameLen =
Name.size();
190 Records[
I].SymOffset = SymOffset;
191 SymOffset += Globals[
I].length();
194 GSH->finalizeBuckets(RecordZeroOffset, Records);
201 Records[I].setBucketIdx(hashStringV1(Records[I].Name) % IPHR_HASH);
209 ++BucketStarts[
P.BucketIdx];
222 memcpy(BucketCursors, BucketStarts,
sizeof(BucketCursors));
223 for (
int I = 0,
E = Records.
size();
I <
E; ++
I) {
224 uint32_t HashIdx = BucketCursors[Records[
I].BucketIdx]++;
244 assert(L.BucketIdx == R.BucketIdx);
251 return L.SymOffset < R.SymOffset;
259 HRec.Off = Records[
uint32_t(HRec.Off)].SymOffset + 1;
270 BucketStarts[BucketIdx] == BucketCursors[BucketIdx])
277 const int SizeOfHROffsetCalc = 12;
278 ulittle32_t ChainStartOff =
279 ulittle32_t(BucketStarts[BucketIdx] * SizeOfHROffsetCalc);
292uint32_t GSIStreamBuilder::calculatePublicsHashStreamSize()
const {
295 Size += PSH->calculateSerializedLength();
302uint32_t GSIStreamBuilder::calculateGlobalsHashStreamSize()
const {
303 return GSH->calculateSerializedLength();
308 finalizePublicBuckets();
309 finalizeGlobalBuckets(PSH->RecordByteSize);
313 return Idx.takeError();
314 GlobalsStreamIndex = *
Idx;
318 return Idx.takeError();
319 PublicsStreamIndex = *
Idx;
321 uint32_t RecordBytes = PSH->RecordByteSize + GSH->RecordByteSize;
325 return Idx.takeError();
326 RecordStreamIndex = *
Idx;
331 assert(Publics.empty() && PSH->RecordByteSize == 0 &&
332 "publics can only be added once");
333 Publics = std::move(PublicsIn);
337 return L.getName() < R.getName();
343 Pub.SymOffset = SymOffset;
348 PSH->RecordByteSize = SymOffset;
352 serializeAndAddGlobal(
Sym);
356 serializeAndAddGlobal(
Sym);
360 serializeAndAddGlobal(
Sym);
364void GSIStreamBuilder::serializeAndAddGlobal(
const T &Symbol) {
367 CodeViewContainer::Pdb));
372 if (Symbol.kind() == S_UDT || Symbol.kind() == S_CONSTANT) {
373 auto Iter = GlobalsSeen.insert(Symbol);
377 GSH->RecordByteSize += Symbol.length();
378 Globals.push_back(Symbol);
384 std::vector<uint8_t> Storage;
402Error GSIStreamBuilder::commitSymbolRecordStream(
417static std::vector<support::ulittle32_t>
421 std::vector<ulittle32_t> PubAddrMap;
422 PubAddrMap.reserve(Publics.size());
423 for (
int I = 0,
E = Publics.size();
I <
E; ++
I)
424 PubAddrMap.push_back(ulittle32_t(
I));
426 auto AddrCmp = [Publics](
const ulittle32_t &LIdx,
const ulittle32_t &RIdx) {
429 if (L.Segment != R.Segment)
430 return L.Segment < R.Segment;
431 if (L.Offset != R.Offset)
432 return L.Offset < R.Offset;
435 return L.getName() < R.getName();
440 for (ulittle32_t &Entry : PubAddrMap)
441 Entry = Publics[Entry].SymOffset;
445Error GSIStreamBuilder::commitPublicsHashStream(
451 Header.SymHash = PSH->calculateSerializedLength();
452 Header.AddrMap = Publics.size() * 4;
453 Header.NumThunks = 0;
454 Header.SizeOfThunk = 0;
455 Header.ISectThunkTable = 0;
456 memset(Header.Padding, 0,
sizeof(Header.Padding));
457 Header.OffThunkTable = 0;
458 Header.NumSections = 0;
459 if (
auto EC = Writer.writeObject(Header))
462 if (
auto EC = PSH->commit(Writer))
465 std::vector<support::ulittle32_t> PubAddrMap =
computeAddrMap(Publics);
466 assert(PubAddrMap.size() == Publics.size());
467 if (
auto EC = Writer.writeArray(
ArrayRef(PubAddrMap)))
473Error GSIStreamBuilder::commitGlobalsHashStream(
476 return GSH->commit(Writer);
488 if (
auto EC = commitSymbolRecordStream(*PRS))
490 if (
auto EC = commitGlobalsHashStream(*GS))
492 if (
auto EC = commitPublicsHashStream(*PS))
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_UNLIKELY(EXPR)
#define LLVM_PACKED_START
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
static CVSymbol serializePublic(uint8_t *Mem, const BulkPublic &Pub)
static Error writePublics(BinaryStreamWriter &Writer, ArrayRef< BulkPublic > Publics)
static bool isAsciiString(StringRef S)
static Error writeRecords(BinaryStreamWriter &Writer, ArrayRef< CVSymbol > Records)
static int gsiRecordCmp(StringRef S1, StringRef S2)
static std::vector< support::ulittle32_t > computeAddrMap(ArrayRef< BulkPublic > Publics)
static uint32_t sizeOfPublic(const BulkPublic &Pub)
Merge contiguous icmps into a memcmp
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
BinaryItemStream represents a sequence of objects stored in some kind of external container but for w...
void setItems(ArrayRef< T > ItemArray)
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Provides write only access to a subclass of WritableBinaryStream.
Error writeArray(ArrayRef< T > Array)
Writes an array of objects of type T to the underlying stream, as if by using memcpy.
Error writeStreamRef(BinaryStreamRef Ref)
Efficiently reads all data from Ref, and writes it to this stream.
Error writeBytes(ArrayRef< uint8_t > Buffer)
Write the bytes specified in Buffer to the underlying stream.
Error writeObject(const T &Obj)
Writes the object Obj to the underlying stream, as if by using memcpy.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
StringRef - Represent a constant reference to a string, i.e.
constexpr size_t size() const
size - Get the string size.
int compare_insensitive(StringRef RHS) const
Compare two strings, ignoring case.
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
CVRecord is a fat pointer (base + size pair) to a symbol or type record.
ArrayRef< uint8_t > RecordData
static CVSymbol writeOneSymbol(SymType &Sym, BumpPtrAllocator &Storage, CodeViewContainer Container)
BumpPtrAllocator & getAllocator()
Expected< uint32_t > addStream(uint32_t Size, ArrayRef< uint32_t > Blocks)
Add a stream to the MSF file with the given size, occupying the given list of blocks.
static std::unique_ptr< WritableMappedBlockStream > createIndexedStream(const MSFLayout &Layout, WritableBinaryStreamRef MsfData, uint32_t StreamIndex, BumpPtrAllocator &Allocator)
void addPublicSymbols(std::vector< BulkPublic > &&PublicsIn)
Error finalizeMsfLayout()
uint32_t getRecordStreamIndex() const
Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef Buffer)
GSIStreamBuilder(msf::MSFBuilder &Msf)
void addGlobalSymbol(const codeview::ProcRefSym &Sym)
uint32_t getPublicsStreamIndex() const
uint32_t getGlobalsStreamIndex() const
@ C
The default llvm calling convention, compatible with C.
CVRecord< SymbolKind > CVSymbol
StringRef getSymbolName(CVSymbol Sym)
detail::packed_endian_specific_integral< uint32_t, little, unaligned > ulittle32_t
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
uint64_t xxh3_64bits(ArrayRef< uint8_t > data)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
void parallelSort(RandomAccessIterator Start, RandomAccessIterator End, const Comparator &Comp=Comparator())
void sort(IteratorTy Start, IteratorTy End)
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
void parallelFor(size_t Begin, size_t End, function_ref< void(size_t)> Fn)
Implement std::hash so that hash_code can be used in STL containers.
An information struct used to provide DenseMap with the various necessary components for a given valu...
This struct is equivalent to codeview::PublicSym32, but it has been optimized for size to speed up bu...
uint32_t calculateSerializedLength() const
std::vector< support::ulittle32_t > HashBuckets
void finalizePublicBuckets()
Error commit(BinaryStreamWriter &Writer)
std::array< support::ulittle32_t,(IPHR_HASH+32)/32 > HashBitmap
void finalizeGlobalBuckets(uint32_t RecordZeroOffset)
std::vector< PSHashRecord > HashRecords
void finalizeBuckets(uint32_t RecordZeroOffset, MutableArrayRef< BulkPublic > Globals)
static unsigned getHashValue(const CVSymbol &Val)
static CVSymbol getEmptyKey()
static bool isEqual(const CVSymbol &LHS, const CVSymbol &RHS)
static CVSymbol getTombstoneKey()