79 return LHS.RecordData == RHS.RecordData;
85struct PublicSym32Layout {
96 NameLen = std::min(NameLen,
98 return alignTo(
sizeof(PublicSym32Layout) + NameLen + 1, 4);
105 size_t Size =
alignTo(
sizeof(PublicSym32Layout) + NameLen + 1, 4);
107 auto *FixedMem =
reinterpret_cast<PublicSym32Layout *
>(Mem);
108 FixedMem->Prefix.RecordKind =
static_cast<uint16_t>(codeview::S_PUB32);
109 FixedMem->Prefix.RecordLen =
static_cast<uint16_t>(
Size - 2);
110 FixedMem->Pub.Flags = Pub.
Flags;
111 FixedMem->Pub.Offset = Pub.
Offset;
112 FixedMem->Pub.Segment = Pub.
Segment;
113 char *NameMem =
reinterpret_cast<char *
>(FixedMem + 1);
114 memcpy(NameMem, Pub.
Name, NameLen);
116 memset(&NameMem[NameLen], 0,
Size -
sizeof(PublicSym32Layout) - NameLen);
153 size_t LS =
S1.size();
154 size_t RS = S2.
size();
157 return (LS > RS) - (LS < RS);
161 return memcmp(
S1.data(), S2.
data(), LS);
164 return S1.compare_insensitive(S2);
167void GSIStreamBuilder::finalizePublicBuckets() {
168 PSH->finalizeBuckets(0, Publics);
171void GSIStreamBuilder::finalizeGlobalBuckets(uint32_t RecordZeroOffset) {
180 std::vector<BulkPublic>
Records;
182 uint32_t SymOffset = RecordZeroOffset;
183 for (
size_t I = 0,
E = Globals.size();
I <
E; ++
I) {
188 SymOffset += Globals[
I].length();
191 GSH->finalizeBuckets(RecordZeroOffset, Records);
198 Records[I].setBucketIdx(hashStringV1(Records[I].getName()) % IPHR_HASH);
206 ++BucketStarts[
P.BucketIdx];
219 memcpy(BucketCursors, BucketStarts,
sizeof(BucketCursors));
220 for (
int I = 0, E = Records.
size();
I < E; ++
I) {
221 uint32_t HashIdx = BucketCursors[Records[
I].BucketIdx]++;
241 assert(L.BucketIdx == R.BucketIdx);
248 return L.SymOffset < R.SymOffset;
256 HRec.Off = Records[
uint32_t(HRec.Off)].SymOffset + 1;
267 BucketStarts[BucketIdx] == BucketCursors[BucketIdx])
274 const int SizeOfHROffsetCalc = 12;
276 ulittle32_t(BucketStarts[BucketIdx] * SizeOfHROffsetCalc);
289uint32_t GSIStreamBuilder::calculatePublicsHashStreamSize()
const {
292 Size += PSH->calculateSerializedLength();
299uint32_t GSIStreamBuilder::calculateGlobalsHashStreamSize()
const {
300 return GSH->calculateSerializedLength();
305 finalizePublicBuckets();
306 finalizeGlobalBuckets(PSH->RecordByteSize);
311 GlobalsStreamIndex = *Idx;
313 Idx = Msf.addStream(calculatePublicsHashStreamSize());
316 PublicsStreamIndex = *Idx;
318 uint64_t RecordBytes = PSH->RecordByteSize + GSH->RecordByteSize;
319 if (RecordBytes > UINT32_MAX)
321 formatv(
"the public symbols ({0} bytes) and global symbols ({1} bytes) "
322 "are too large to fit in a PDB file; "
323 "the maximum total is {2} bytes.",
324 PSH->RecordByteSize, GSH->RecordByteSize, UINT32_MAX),
327 Idx = Msf.addStream(RecordBytes);
330 RecordStreamIndex = *Idx;
335 assert(Publics.empty() && PSH->RecordByteSize == 0 &&
336 "publics can only be added once");
337 Publics = std::move(PublicsIn);
341 return L.getName() < R.getName();
347 Pub.SymOffset = SymOffset;
352 PSH->RecordByteSize = SymOffset;
356 serializeAndAddGlobal(Sym);
360 serializeAndAddGlobal(Sym);
364 serializeAndAddGlobal(Sym);
368void GSIStreamBuilder::serializeAndAddGlobal(
const T &Symbol) {
376 if (Symbol.kind() == S_UDT || Symbol.kind() == S_CONSTANT) {
377 auto Iter = GlobalsSeen.insert(Symbol);
381 GSH->RecordByteSize += Symbol.length();
382 Globals.push_back(Symbol);
388 std::vector<uint8_t> Storage;
406Error GSIStreamBuilder::commitSymbolRecordStream(
407 WritableBinaryStreamRef Stream) {
408 BinaryStreamWriter Writer(Stream);
421static std::vector<support::ulittle32_t>
425 std::vector<ulittle32_t> PubAddrMap;
426 PubAddrMap.reserve(Publics.size());
427 for (
int I = 0,
E = Publics.size();
I <
E; ++
I)
433 if (L.Segment != R.Segment)
434 return L.Segment < R.Segment;
435 if (L.Offset != R.Offset)
436 return L.Offset < R.Offset;
439 return L.getName() < R.getName();
445 Entry = Publics[Entry].SymOffset;
449Error GSIStreamBuilder::commitPublicsHashStream(
450 WritableBinaryStreamRef Stream) {
451 BinaryStreamWriter Writer(Stream);
452 PublicsStreamHeader Header;
455 Header.SymHash = PSH->calculateSerializedLength();
456 Header.AddrMap = Publics.size() * 4;
457 Header.NumThunks = 0;
458 Header.SizeOfThunk = 0;
459 Header.ISectThunkTable = 0;
460 memset(Header.Padding, 0,
sizeof(Header.Padding));
461 Header.OffThunkTable = 0;
462 Header.NumSections = 0;
463 if (
auto EC = Writer.writeObject(Header))
466 if (
auto EC = PSH->commit(Writer))
469 std::vector<support::ulittle32_t> PubAddrMap =
computeAddrMap(Publics);
470 assert(PubAddrMap.size() == Publics.size());
471 if (
auto EC = Writer.writeArray(
ArrayRef(PubAddrMap)))
477Error GSIStreamBuilder::commitGlobalsHashStream(
478 WritableBinaryStreamRef Stream) {
479 BinaryStreamWriter Writer(Stream);
480 return GSH->commit(Writer);
493 if (
auto EC = commitSymbolRecordStream(*PRS))
495 if (
auto EC = commitGlobalsHashStream(*GS))
497 if (
auto EC = commitPublicsHashStream(*PS))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_UNLIKELY(EXPR)
#define LLVM_PACKED_START
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)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
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.
LLVM_ABI Error writeStreamRef(BinaryStreamRef Ref)
Efficiently reads all data from Ref, and writes it to this stream.
LLVM_ABI 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.
Error takeError()
Take ownership of the stored error.
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
Represent a constant reference to a string, i.e.
constexpr size_t size() const
Get the string size.
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
The TimeTraceScope is a helper class to call the begin and end functions of the time trace profiler.
ArrayRef< uint8_t > RecordData
static CVSymbol writeOneSymbol(SymType &Sym, BumpPtrAllocator &Storage, CodeViewContainer Container)
BumpPtrAllocator & getAllocator()
static std::unique_ptr< WritableMappedBlockStream > createIndexedStream(const MSFLayout &Layout, WritableBinaryStreamRef MsfData, uint32_t StreamIndex, BumpPtrAllocator &Allocator)
LLVM_ABI void addPublicSymbols(std::vector< BulkPublic > &&PublicsIn)
LLVM_ABI Error finalizeMsfLayout()
uint32_t getRecordStreamIndex() const
LLVM_ABI ~GSIStreamBuilder()
LLVM_ABI Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef Buffer)
LLVM_ABI GSIStreamBuilder(msf::MSFBuilder &Msf)
LLVM_ABI void addGlobalSymbol(const codeview::ProcRefSym &Sym)
uint32_t getPublicsStreamIndex() const
uint32_t getGlobalsStreamIndex() const
@ C
The default llvm calling convention, compatible with C.
llvm::SmallVector< std::shared_ptr< RecordsSlice >, 4 > Records
CVRecord< SymbolKind > CVSymbol
LLVM_ABI StringRef getSymbolName(CVSymbol Sym)
detail::packed_endian_specific_integral< uint32_t, llvm::endianness::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)
Inline ArrayRef overloads of the xxhash entry points declared out-of-line in llvm/Support/xxhash....
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
void parallelSort(RandomAccessIterator Start, RandomAccessIterator End, const Comparator &Comp=Comparator())
void sort(IteratorTy Start, IteratorTy End)
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
ArrayRef(const T &OneElt) -> ArrayRef< T >
LLVM_ABI 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.
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)