LLVM  5.0.0
PublicsStreamBuilder.cpp
Go to the documentation of this file.
1 //===- DbiStreamBuilder.cpp - PDB Dbi Stream Creation -----------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
11 
15 
16 #include "GSI.h"
17 
18 using namespace llvm;
19 using namespace llvm::msf;
20 using namespace llvm::pdb;
21 
22 PublicsStreamBuilder::PublicsStreamBuilder(msf::MSFBuilder &Msf) : Msf(Msf) {}
23 
25 
27  uint32_t Size = 0;
28  Size += sizeof(PublicsStreamHeader);
29  Size += sizeof(GSIHashHeader);
30  Size += HashRecords.size() * sizeof(PSHashRecord);
31  size_t BitmapSizeInBits = alignTo(IPHR_HASH + 1, 32);
32  uint32_t NumBitmapEntries = BitmapSizeInBits / 8;
33  Size += NumBitmapEntries;
34 
35  // FIXME: Account for hash buckets. For now since we we write a zero-bitmap
36  // indicating that no hash buckets are valid, we also write zero byets of hash
37  // bucket data.
38  Size += 0;
39  return Size;
40 }
41 
44  if (!Idx)
45  return Idx.takeError();
46  StreamIdx = *Idx;
47 
48  Expected<uint32_t> RecordIdx = Msf.addStream(0);
49  if (!RecordIdx)
50  return RecordIdx.takeError();
51  RecordStreamIdx = *RecordIdx;
52  return Error::success();
53 }
54 
57  GSIHashHeader GSH;
58 
59  // FIXME: Figure out what to put for these values.
60  PSH.AddrMap = 0;
61  PSH.ISectThunkTable = 0;
62  PSH.NumSections = 0;
63  PSH.NumThunks = 0;
64  PSH.OffThunkTable = 0;
65  PSH.SizeOfThunk = 0;
66  PSH.SymHash = 0;
67 
70  GSH.HrSize = 0;
71  GSH.NumBuckets = 0;
72 
73  if (auto EC = PublicsWriter.writeObject(PSH))
74  return EC;
75  if (auto EC = PublicsWriter.writeObject(GSH))
76  return EC;
77  if (auto EC = PublicsWriter.writeArray(makeArrayRef(HashRecords)))
78  return EC;
79 
80  size_t BitmapSizeInBits = alignTo(IPHR_HASH + 1, 32);
81  uint32_t NumBitmapEntries = BitmapSizeInBits / 8;
82  std::vector<uint8_t> BitmapData(NumBitmapEntries);
83  // FIXME: Build an actual bitmap
84  if (auto EC = PublicsWriter.writeBytes(makeArrayRef(BitmapData)))
85  return EC;
86 
87  // FIXME: Write actual hash buckets.
88  return Error::success();
89 }
Error writeObject(const T &Obj)
Writes the object Obj to the underlying stream, as if by using memcpy.
Error writeBytes(ArrayRef< uint8_t > Buffer)
Write the bytes specified in Buffer to the underlying stream.
support::ulittle32_t VerSignature
Definition: GSI.h:51
static const unsigned IPHR_HASH
From https://github.com/Microsoft/microsoft-pdb/blob/master/PDB/dbi/gsi.cpp.
Definition: GSI.h:41
support::ulittle32_t VerHdr
Definition: GSI.h:52
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
Definition: MathExtras.h:677
Error takeError()
Take ownership of the stored error.
Definition: Error.h:764
support::ulittle32_t NumThunks
Definition: RawTypes.h:264
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:451
Header of the hash tables found in the globals and publics sections.
Definition: GSI.h:46
support::ulittle16_t ISectThunkTable
Definition: RawTypes.h:266
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
support::ulittle32_t SymHash
Definition: RawTypes.h:262
Error writeArray(ArrayRef< T > Array)
Writes an array of objects of type T to the underlying stream, as if by using memcpy.
support::ulittle32_t NumBuckets
Definition: GSI.h:54
Error commit(BinaryStreamWriter &PublicsWriter)
Provides write only access to a subclass of WritableBinaryStream.
support::ulittle32_t AddrMap
Definition: RawTypes.h:263
static ErrorSuccess success()
Create a success value.
Definition: Error.h:311
support::ulittle32_t SizeOfThunk
Definition: RawTypes.h:265
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.
Definition: MSFBuilder.cpp:136
support::ulittle32_t OffThunkTable
Definition: RawTypes.h:268
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
support::ulittle32_t NumSections
Definition: RawTypes.h:269
support::ulittle32_t HrSize
Definition: GSI.h:53