75 return LHS.RecordData == RHS.RecordData;
81struct PublicSym32Layout {
92 NameLen = std::min(NameLen,
94 return alignTo(
sizeof(PublicSym32Layout) + NameLen + 1, 4);
101 size_t Size =
alignTo(
sizeof(PublicSym32Layout) + NameLen + 1, 4);
103 auto *FixedMem =
reinterpret_cast<PublicSym32Layout *
>(Mem);
104 FixedMem->Prefix.RecordKind =
static_cast<uint16_t>(codeview::S_PUB32);
105 FixedMem->Prefix.RecordLen =
static_cast<uint16_t>(
Size - 2);
106 FixedMem->Pub.Flags = Pub.
Flags;
107 FixedMem->Pub.Offset = Pub.
Offset;
108 FixedMem->Pub.Segment = Pub.
Segment;
109 char *NameMem =
reinterpret_cast<char *
>(FixedMem + 1);
110 memcpy(NameMem, Pub.
Name, NameLen);
112 memset(&NameMem[NameLen], 0,
Size -
sizeof(PublicSym32Layout) - NameLen);
149 size_t LS =
S1.size();
150 size_t RS = S2.
size();
153 return (LS > RS) - (LS < RS);
157 return memcmp(
S1.data(), S2.
data(), LS);
160 return S1.compare_insensitive(S2);
163void GSIStreamBuilder::finalizePublicBuckets() {
164 PSH->finalizeBuckets(0, Publics);
167void GSIStreamBuilder::finalizeGlobalBuckets(uint32_t RecordZeroOffset) {
176 std::vector<BulkPublic>
Records;
178 uint32_t SymOffset = RecordZeroOffset;
179 for (
size_t I = 0,
E = Globals.size();
I <
E; ++
I) {
184 SymOffset += Globals[
I].length();
187 GSH->finalizeBuckets(RecordZeroOffset, Records);
194 Records[I].setBucketIdx(hashStringV1(Records[I].getName()) % IPHR_HASH);
202 ++BucketStarts[
P.BucketIdx];
215 memcpy(BucketCursors, BucketStarts,
sizeof(BucketCursors));
216 for (
int I = 0, E = Records.
size();
I < E; ++
I) {
217 uint32_t HashIdx = BucketCursors[Records[
I].BucketIdx]++;
237 assert(L.BucketIdx == R.BucketIdx);
244 return L.SymOffset < R.SymOffset;
252 HRec.Off = Records[
uint32_t(HRec.Off)].SymOffset + 1;
263 BucketStarts[BucketIdx] == BucketCursors[BucketIdx])
270 const int SizeOfHROffsetCalc = 12;
272 ulittle32_t(BucketStarts[BucketIdx] * SizeOfHROffsetCalc);
285uint32_t GSIStreamBuilder::calculatePublicsHashStreamSize()
const {
288 Size += PSH->calculateSerializedLength();
295uint32_t GSIStreamBuilder::calculateGlobalsHashStreamSize()
const {
296 return GSH->calculateSerializedLength();
301 finalizePublicBuckets();
302 finalizeGlobalBuckets(PSH->RecordByteSize);
307 GlobalsStreamIndex = *Idx;
309 Idx = Msf.addStream(calculatePublicsHashStreamSize());
312 PublicsStreamIndex = *Idx;
314 uint64_t RecordBytes = PSH->RecordByteSize + GSH->RecordByteSize;
315 if (RecordBytes > UINT32_MAX)
317 formatv(
"the public symbols ({0} bytes) and global symbols ({1} bytes) "
318 "are too large to fit in a PDB file; "
319 "the maximum total is {2} bytes.",
320 PSH->RecordByteSize, GSH->RecordByteSize, UINT32_MAX),
323 Idx = Msf.addStream(RecordBytes);
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) {
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(
403 WritableBinaryStreamRef Stream) {
404 BinaryStreamWriter Writer(Stream);
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)
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();
441 Entry = Publics[Entry].SymOffset;
445Error GSIStreamBuilder::commitPublicsHashStream(
446 WritableBinaryStreamRef Stream) {
447 BinaryStreamWriter Writer(Stream);
448 PublicsStreamHeader Header;
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(
474 WritableBinaryStreamRef Stream) {
475 BinaryStreamWriter Writer(Stream);
476 return GSH->commit(Writer);
489 if (
auto EC = commitSymbolRecordStream(*PRS))
491 if (
auto EC = commitGlobalsHashStream(*GS))
493 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 bool isEqual(const CVSymbol &LHS, const CVSymbol &RHS)