84 return LHS.RecordData ==
RHS.RecordData;
90struct PublicSym32Layout {
101 NameLen = std::min(NameLen,
103 return alignTo(
sizeof(PublicSym32Layout) + NameLen + 1, 4);
110 size_t Size =
alignTo(
sizeof(PublicSym32Layout) + NameLen + 1, 4);
112 auto *FixedMem =
reinterpret_cast<PublicSym32Layout *
>(Mem);
113 FixedMem->Prefix.RecordKind =
static_cast<uint16_t>(codeview::S_PUB32);
114 FixedMem->Prefix.RecordLen =
static_cast<uint16_t>(
Size - 2);
115 FixedMem->Pub.Flags = Pub.
Flags;
116 FixedMem->Pub.Offset = Pub.
Offset;
117 FixedMem->Pub.Segment = Pub.
Segment;
118 char *NameMem =
reinterpret_cast<char *
>(FixedMem + 1);
119 memcpy(NameMem, Pub.
Name, NameLen);
121 memset(&NameMem[NameLen], 0,
Size -
sizeof(PublicSym32Layout) - NameLen);
158 size_t LS =
S1.size();
159 size_t RS = S2.
size();
162 return (LS > RS) - (LS < RS);
169 return S1.compare_insensitive(S2.
data());
172void GSIStreamBuilder::finalizePublicBuckets() {
173 PSH->finalizeBuckets(0, Publics);
176void GSIStreamBuilder::finalizeGlobalBuckets(
uint32_t RecordZeroOffset) {
185 std::vector<BulkPublic>
Records;
186 Records.resize(Globals.size());
187 uint32_t SymOffset = RecordZeroOffset;
188 for (
size_t I = 0, E = Globals.size();
I < E; ++
I) {
193 SymOffset += Globals[
I].length();
196 GSH->finalizeBuckets(RecordZeroOffset, Records);
203 Records[I].setBucketIdx(hashStringV1(Records[I].Name) % IPHR_HASH);
211 ++BucketStarts[
P.BucketIdx];
224 memcpy(BucketCursors, BucketStarts,
sizeof(BucketCursors));
225 for (
int I = 0, E = Records.size();
I < E; ++
I) {
226 uint32_t HashIdx = BucketCursors[Records[
I].BucketIdx]++;
246 assert(L.BucketIdx == R.BucketIdx);
253 return L.SymOffset < R.SymOffset;
261 HRec.Off = Records[
uint32_t(HRec.Off)].SymOffset + 1;
272 BucketStarts[BucketIdx] == BucketCursors[BucketIdx])
279 const int SizeOfHROffsetCalc = 12;
280 ulittle32_t ChainStartOff =
281 ulittle32_t(BucketStarts[BucketIdx] * SizeOfHROffsetCalc);
294uint32_t GSIStreamBuilder::calculatePublicsHashStreamSize()
const {
297 Size += PSH->calculateSerializedLength();
304uint32_t GSIStreamBuilder::calculateGlobalsHashStreamSize()
const {
305 return GSH->calculateSerializedLength();
310 finalizePublicBuckets();
311 finalizeGlobalBuckets(PSH->RecordByteSize);
315 return Idx.takeError();
316 GlobalsStreamIndex = *
Idx;
320 return Idx.takeError();
321 PublicsStreamIndex = *
Idx;
323 uint64_t RecordBytes = PSH->RecordByteSize + GSH->RecordByteSize;
324 if (RecordBytes > UINT32_MAX)
325 return make_error<StringError>(
326 formatv(
"the public symbols ({0} bytes) and global symbols ({1} bytes) "
327 "are too large to fit in a PDB file; "
328 "the maximum total is {2} bytes.",
329 PSH->RecordByteSize, GSH->RecordByteSize, UINT32_MAX),
334 return Idx.takeError();
335 RecordStreamIndex = *
Idx;
340 assert(Publics.empty() && PSH->RecordByteSize == 0 &&
341 "publics can only be added once");
342 Publics = std::move(PublicsIn);
346 return L.getName() < R.getName();
352 Pub.SymOffset = SymOffset;
357 PSH->RecordByteSize = SymOffset;
361 serializeAndAddGlobal(
Sym);
365 serializeAndAddGlobal(
Sym);
369 serializeAndAddGlobal(
Sym);
373void GSIStreamBuilder::serializeAndAddGlobal(
const T &Symbol) {
376 CodeViewContainer::Pdb));
381 if (Symbol.kind() == S_UDT || Symbol.kind() == S_CONSTANT) {
382 auto Iter = GlobalsSeen.insert(Symbol);
386 GSH->RecordByteSize += Symbol.length();
387 Globals.push_back(Symbol);
393 std::vector<uint8_t> Storage;
411Error GSIStreamBuilder::commitSymbolRecordStream(
426static std::vector<support::ulittle32_t>
430 std::vector<ulittle32_t> PubAddrMap;
431 PubAddrMap.reserve(Publics.size());
432 for (
int I = 0, E = Publics.size();
I < E; ++
I)
433 PubAddrMap.push_back(ulittle32_t(
I));
435 auto AddrCmp = [Publics](
const ulittle32_t &LIdx,
const ulittle32_t &RIdx) {
438 if (L.Segment != R.Segment)
439 return L.Segment < R.Segment;
440 if (L.Offset != R.Offset)
441 return L.Offset < R.Offset;
444 return L.getName() < R.getName();
449 for (ulittle32_t &Entry : PubAddrMap)
450 Entry = Publics[Entry].SymOffset;
454Error GSIStreamBuilder::commitPublicsHashStream(
460 Header.SymHash = PSH->calculateSerializedLength();
461 Header.AddrMap = Publics.size() * 4;
462 Header.NumThunks = 0;
463 Header.SizeOfThunk = 0;
464 Header.ISectThunkTable = 0;
465 memset(Header.Padding, 0,
sizeof(Header.Padding));
466 Header.OffThunkTable = 0;
467 Header.NumSections = 0;
468 if (
auto EC = Writer.writeObject(Header))
471 if (
auto EC = PSH->commit(Writer))
474 std::vector<support::ulittle32_t> PubAddrMap =
computeAddrMap(Publics);
475 assert(PubAddrMap.size() == Publics.size());
476 if (
auto EC = Writer.writeArray(
ArrayRef(PubAddrMap)))
482Error GSIStreamBuilder::commitGlobalsHashStream(
485 return GSH->commit(Writer);
498 if (
auto EC = commitSymbolRecordStream(*PRS))
500 if (
auto EC = commitGlobalsHashStream(*GS))
502 if (
auto EC = commitPublicsHashStream(*PS))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-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
ArrayRef - 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.
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.
constexpr const char * data() const
data - 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.
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()
LLVM_ABI 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)
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.
LLVM_ABI uint64_t xxh3_64bits(ArrayRef< uint8_t > data)
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)
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
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.
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()