Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 1 | //===- DbiStreamBuilder.cpp - PDB Dbi Stream Creation -----------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "llvm/DebugInfo/PDB/Native/GSIStreamBuilder.h" |
| 10 | |
Zachary Turner | 7c6b19f | 2018-12-04 21:48:46 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/DenseSet.h" |
Zachary Turner | ee9906d | 2017-08-11 19:00:03 +0000 | [diff] [blame] | 12 | #include "llvm/DebugInfo/CodeView/RecordName.h" |
Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 13 | #include "llvm/DebugInfo/CodeView/SymbolDeserializer.h" |
| 14 | #include "llvm/DebugInfo/CodeView/SymbolRecord.h" |
| 15 | #include "llvm/DebugInfo/CodeView/SymbolSerializer.h" |
| 16 | #include "llvm/DebugInfo/MSF/MSFBuilder.h" |
| 17 | #include "llvm/DebugInfo/MSF/MSFCommon.h" |
| 18 | #include "llvm/DebugInfo/MSF/MappedBlockStream.h" |
| 19 | #include "llvm/DebugInfo/PDB/Native/GlobalsStream.h" |
| 20 | #include "llvm/DebugInfo/PDB/Native/Hash.h" |
| 21 | #include "llvm/Support/BinaryItemStream.h" |
| 22 | #include "llvm/Support/BinaryStreamWriter.h" |
Zachary Turner | 7c6b19f | 2018-12-04 21:48:46 +0000 | [diff] [blame] | 23 | #include "llvm/Support/xxhash.h" |
Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 24 | #include <algorithm> |
| 25 | #include <vector> |
| 26 | |
| 27 | using namespace llvm; |
| 28 | using namespace llvm::msf; |
| 29 | using namespace llvm::pdb; |
| 30 | using namespace llvm::codeview; |
| 31 | |
Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 32 | struct llvm::pdb::GSIHashStreamBuilder { |
Zachary Turner | 7c6b19f | 2018-12-04 21:48:46 +0000 | [diff] [blame] | 33 | struct UdtDenseMapInfo { |
| 34 | static inline CVSymbol getEmptyKey() { |
| 35 | static CVSymbol Empty; |
| 36 | return Empty; |
| 37 | } |
| 38 | static inline CVSymbol getTombstoneKey() { |
Reid Kleckner | e10d004 | 2019-04-04 00:28:48 +0000 | [diff] [blame^] | 39 | static CVSymbol Tombstone( |
| 40 | DenseMapInfo<ArrayRef<uint8_t>>::getTombstoneKey()); |
Zachary Turner | 7c6b19f | 2018-12-04 21:48:46 +0000 | [diff] [blame] | 41 | return Tombstone; |
| 42 | } |
| 43 | static unsigned getHashValue(const CVSymbol &Val) { |
| 44 | return xxHash64(Val.RecordData); |
| 45 | } |
| 46 | static bool isEqual(const CVSymbol &LHS, const CVSymbol &RHS) { |
| 47 | return LHS.RecordData == RHS.RecordData; |
| 48 | } |
| 49 | }; |
| 50 | |
Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 51 | std::vector<CVSymbol> Records; |
| 52 | uint32_t StreamIndex; |
Zachary Turner | 7c6b19f | 2018-12-04 21:48:46 +0000 | [diff] [blame] | 53 | llvm::DenseSet<CVSymbol, UdtDenseMapInfo> UdtHashes; |
Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 54 | std::vector<PSHashRecord> HashRecords; |
| 55 | std::array<support::ulittle32_t, (IPHR_HASH + 32) / 32> HashBitmap; |
| 56 | std::vector<support::ulittle32_t> HashBuckets; |
| 57 | |
| 58 | uint32_t calculateSerializedLength() const; |
| 59 | uint32_t calculateRecordByteSize() const; |
| 60 | Error commit(BinaryStreamWriter &Writer); |
| 61 | void finalizeBuckets(uint32_t RecordZeroOffset); |
Zachary Turner | ee9906d | 2017-08-11 19:00:03 +0000 | [diff] [blame] | 62 | |
| 63 | template <typename T> void addSymbol(const T &Symbol, MSFBuilder &Msf) { |
| 64 | T Copy(Symbol); |
Zachary Turner | 7c6b19f | 2018-12-04 21:48:46 +0000 | [diff] [blame] | 65 | addSymbol(SymbolSerializer::writeOneSymbol(Copy, Msf.getAllocator(), |
| 66 | CodeViewContainer::Pdb)); |
Zachary Turner | ee9906d | 2017-08-11 19:00:03 +0000 | [diff] [blame] | 67 | } |
Zachary Turner | 7c6b19f | 2018-12-04 21:48:46 +0000 | [diff] [blame] | 68 | void addSymbol(const CVSymbol &Symbol) { |
| 69 | if (Symbol.kind() == S_UDT) { |
| 70 | auto Iter = UdtHashes.insert(Symbol); |
| 71 | if (!Iter.second) |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | Records.push_back(Symbol); |
| 76 | } |
Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | uint32_t GSIHashStreamBuilder::calculateSerializedLength() const { |
| 80 | uint32_t Size = sizeof(GSIHashHeader); |
| 81 | Size += HashRecords.size() * sizeof(PSHashRecord); |
| 82 | Size += HashBitmap.size() * sizeof(uint32_t); |
| 83 | Size += HashBuckets.size() * sizeof(uint32_t); |
| 84 | return Size; |
| 85 | } |
| 86 | |
| 87 | uint32_t GSIHashStreamBuilder::calculateRecordByteSize() const { |
| 88 | uint32_t Size = 0; |
| 89 | for (const auto &Sym : Records) |
| 90 | Size += Sym.length(); |
| 91 | return Size; |
| 92 | } |
| 93 | |
| 94 | Error GSIHashStreamBuilder::commit(BinaryStreamWriter &Writer) { |
| 95 | GSIHashHeader Header; |
| 96 | Header.VerSignature = GSIHashHeader::HdrSignature; |
| 97 | Header.VerHdr = GSIHashHeader::HdrVersion; |
| 98 | Header.HrSize = HashRecords.size() * sizeof(PSHashRecord); |
| 99 | Header.NumBuckets = HashBitmap.size() * 4 + HashBuckets.size() * 4; |
| 100 | |
| 101 | if (auto EC = Writer.writeObject(Header)) |
| 102 | return EC; |
| 103 | |
| 104 | if (auto EC = Writer.writeArray(makeArrayRef(HashRecords))) |
| 105 | return EC; |
| 106 | if (auto EC = Writer.writeArray(makeArrayRef(HashBitmap))) |
| 107 | return EC; |
| 108 | if (auto EC = Writer.writeArray(makeArrayRef(HashBuckets))) |
| 109 | return EC; |
| 110 | return Error::success(); |
| 111 | } |
| 112 | |
Zachary Turner | 648bebd | 2018-07-06 21:01:42 +0000 | [diff] [blame] | 113 | static bool isAsciiString(StringRef S) { |
| 114 | return llvm::all_of(S, [](char C) { return unsigned(C) < 0x80; }); |
| 115 | } |
| 116 | |
| 117 | // See `caseInsensitiveComparePchPchCchCch` in gsi.cpp |
| 118 | static bool gsiRecordLess(StringRef S1, StringRef S2) { |
| 119 | size_t LS = S1.size(); |
| 120 | size_t RS = S2.size(); |
| 121 | // Shorter strings always compare less than longer strings. |
| 122 | if (LS != RS) |
| 123 | return LS < RS; |
| 124 | |
| 125 | // If either string contains non ascii characters, memcmp them. |
| 126 | if (LLVM_UNLIKELY(!isAsciiString(S1) || !isAsciiString(S2))) |
| 127 | return memcmp(S1.data(), S2.data(), LS) < 0; |
| 128 | |
Benjamin Kramer | 9fc944a | 2018-07-06 21:56:57 +0000 | [diff] [blame] | 129 | // Both strings are ascii, perform a case-insenstive comparison. |
| 130 | return S1.compare_lower(S2.data()) < 0; |
Zachary Turner | 648bebd | 2018-07-06 21:01:42 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 133 | void GSIHashStreamBuilder::finalizeBuckets(uint32_t RecordZeroOffset) { |
Zachary Turner | 1f200ad | 2018-07-06 02:33:58 +0000 | [diff] [blame] | 134 | std::array<std::vector<std::pair<StringRef, PSHashRecord>>, IPHR_HASH + 1> |
| 135 | TmpBuckets; |
Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 136 | uint32_t SymOffset = RecordZeroOffset; |
| 137 | for (const CVSymbol &Sym : Records) { |
| 138 | PSHashRecord HR; |
| 139 | // Add one when writing symbol offsets to disk. See GSI1::fixSymRecs. |
| 140 | HR.Off = SymOffset + 1; |
| 141 | HR.CRef = 1; // Always use a refcount of 1. |
| 142 | |
| 143 | // Hash the name to figure out which bucket this goes into. |
| 144 | StringRef Name = getSymbolName(Sym); |
| 145 | size_t BucketIdx = hashStringV1(Name) % IPHR_HASH; |
Zachary Turner | 1f200ad | 2018-07-06 02:33:58 +0000 | [diff] [blame] | 146 | TmpBuckets[BucketIdx].push_back(std::make_pair(Name, HR)); |
Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 147 | SymOffset += Sym.length(); |
| 148 | } |
| 149 | |
| 150 | // Compute the three tables: the hash records in bucket and chain order, the |
| 151 | // bucket presence bitmap, and the bucket chain start offsets. |
| 152 | HashRecords.reserve(Records.size()); |
| 153 | for (ulittle32_t &Word : HashBitmap) |
| 154 | Word = 0; |
| 155 | for (size_t BucketIdx = 0; BucketIdx < IPHR_HASH + 1; ++BucketIdx) { |
| 156 | auto &Bucket = TmpBuckets[BucketIdx]; |
| 157 | if (Bucket.empty()) |
| 158 | continue; |
| 159 | HashBitmap[BucketIdx / 32] |= 1U << (BucketIdx % 32); |
| 160 | |
| 161 | // Calculate what the offset of the first hash record in the chain would |
| 162 | // be if it were inflated to contain 32-bit pointers. On a 32-bit system, |
| 163 | // each record would be 12 bytes. See HROffsetCalc in gsi.h. |
| 164 | const int SizeOfHROffsetCalc = 12; |
| 165 | ulittle32_t ChainStartOff = |
| 166 | ulittle32_t(HashRecords.size() * SizeOfHROffsetCalc); |
| 167 | HashBuckets.push_back(ChainStartOff); |
Zachary Turner | 1f200ad | 2018-07-06 02:33:58 +0000 | [diff] [blame] | 168 | |
Zachary Turner | 648bebd | 2018-07-06 21:01:42 +0000 | [diff] [blame] | 169 | // Sort each bucket by memcmp of the symbol's name. It's important that |
| 170 | // we use the same sorting algorithm as is used by the reference |
| 171 | // implementation to ensure that the search for a record within a bucket |
| 172 | // can properly early-out when it detects the record won't be found. The |
| 173 | // algorithm used here corredsponds to the function |
| 174 | // caseInsensitiveComparePchPchCchCch in the reference implementation. |
Fangrui Song | 0cac726 | 2018-09-27 02:13:45 +0000 | [diff] [blame] | 175 | llvm::sort(Bucket, [](const std::pair<StringRef, PSHashRecord> &Left, |
| 176 | const std::pair<StringRef, PSHashRecord> &Right) { |
| 177 | return gsiRecordLess(Left.first, Right.first); |
| 178 | }); |
Zachary Turner | 1f200ad | 2018-07-06 02:33:58 +0000 | [diff] [blame] | 179 | |
| 180 | for (const auto &Entry : Bucket) |
| 181 | HashRecords.push_back(Entry.second); |
Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
| 185 | GSIStreamBuilder::GSIStreamBuilder(msf::MSFBuilder &Msf) |
| 186 | : Msf(Msf), PSH(llvm::make_unique<GSIHashStreamBuilder>()), |
| 187 | GSH(llvm::make_unique<GSIHashStreamBuilder>()) {} |
| 188 | |
| 189 | GSIStreamBuilder::~GSIStreamBuilder() {} |
| 190 | |
| 191 | uint32_t GSIStreamBuilder::calculatePublicsHashStreamSize() const { |
| 192 | uint32_t Size = 0; |
| 193 | Size += sizeof(PublicsStreamHeader); |
| 194 | Size += PSH->calculateSerializedLength(); |
| 195 | Size += PSH->Records.size() * sizeof(uint32_t); // AddrMap |
| 196 | // FIXME: Add thunk map and section offsets for incremental linking. |
| 197 | |
| 198 | return Size; |
| 199 | } |
| 200 | |
| 201 | uint32_t GSIStreamBuilder::calculateGlobalsHashStreamSize() const { |
| 202 | return GSH->calculateSerializedLength(); |
| 203 | } |
| 204 | |
| 205 | Error GSIStreamBuilder::finalizeMsfLayout() { |
| 206 | // First we write public symbol records, then we write global symbol records. |
| 207 | uint32_t PSHZero = 0; |
| 208 | uint32_t GSHZero = PSH->calculateRecordByteSize(); |
| 209 | |
| 210 | PSH->finalizeBuckets(PSHZero); |
| 211 | GSH->finalizeBuckets(GSHZero); |
| 212 | |
Zachary Turner | a6fb536 | 2018-03-23 18:43:39 +0000 | [diff] [blame] | 213 | Expected<uint32_t> Idx = Msf.addStream(calculateGlobalsHashStreamSize()); |
Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 214 | if (!Idx) |
| 215 | return Idx.takeError(); |
| 216 | GSH->StreamIndex = *Idx; |
Zachary Turner | a6fb536 | 2018-03-23 18:43:39 +0000 | [diff] [blame] | 217 | Idx = Msf.addStream(calculatePublicsHashStreamSize()); |
| 218 | if (!Idx) |
| 219 | return Idx.takeError(); |
| 220 | PSH->StreamIndex = *Idx; |
Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 221 | |
| 222 | uint32_t RecordBytes = |
| 223 | GSH->calculateRecordByteSize() + PSH->calculateRecordByteSize(); |
| 224 | |
| 225 | Idx = Msf.addStream(RecordBytes); |
| 226 | if (!Idx) |
| 227 | return Idx.takeError(); |
| 228 | RecordStreamIdx = *Idx; |
| 229 | return Error::success(); |
| 230 | } |
| 231 | |
Zachary Turner | d76dc2d | 2017-08-21 20:08:40 +0000 | [diff] [blame] | 232 | static bool comparePubSymByAddrAndName( |
| 233 | const std::pair<const CVSymbol *, const PublicSym32 *> &LS, |
| 234 | const std::pair<const CVSymbol *, const PublicSym32 *> &RS) { |
| 235 | if (LS.second->Segment != RS.second->Segment) |
| 236 | return LS.second->Segment < RS.second->Segment; |
| 237 | if (LS.second->Offset != RS.second->Offset) |
| 238 | return LS.second->Offset < RS.second->Offset; |
Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 239 | |
Zachary Turner | d76dc2d | 2017-08-21 20:08:40 +0000 | [diff] [blame] | 240 | return LS.second->Name < RS.second->Name; |
Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | /// Compute the address map. The address map is an array of symbol offsets |
| 244 | /// sorted so that it can be binary searched by address. |
| 245 | static std::vector<ulittle32_t> computeAddrMap(ArrayRef<CVSymbol> Records) { |
| 246 | // Make a vector of pointers to the symbols so we can sort it by address. |
| 247 | // Also gather the symbol offsets while we're at it. |
Zachary Turner | d76dc2d | 2017-08-21 20:08:40 +0000 | [diff] [blame] | 248 | |
| 249 | std::vector<PublicSym32> DeserializedPublics; |
| 250 | std::vector<std::pair<const CVSymbol *, const PublicSym32 *>> PublicsByAddr; |
Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 251 | std::vector<uint32_t> SymOffsets; |
Zachary Turner | d76dc2d | 2017-08-21 20:08:40 +0000 | [diff] [blame] | 252 | DeserializedPublics.reserve(Records.size()); |
Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 253 | PublicsByAddr.reserve(Records.size()); |
Zachary Turner | d76dc2d | 2017-08-21 20:08:40 +0000 | [diff] [blame] | 254 | SymOffsets.reserve(Records.size()); |
| 255 | |
Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 256 | uint32_t SymOffset = 0; |
| 257 | for (const CVSymbol &Sym : Records) { |
Zachary Turner | d76dc2d | 2017-08-21 20:08:40 +0000 | [diff] [blame] | 258 | assert(Sym.kind() == SymbolKind::S_PUB32); |
| 259 | DeserializedPublics.push_back( |
| 260 | cantFail(SymbolDeserializer::deserializeAs<PublicSym32>(Sym))); |
| 261 | PublicsByAddr.emplace_back(&Sym, &DeserializedPublics.back()); |
Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 262 | SymOffsets.push_back(SymOffset); |
| 263 | SymOffset += Sym.length(); |
| 264 | } |
| 265 | std::stable_sort(PublicsByAddr.begin(), PublicsByAddr.end(), |
| 266 | comparePubSymByAddrAndName); |
| 267 | |
| 268 | // Fill in the symbol offsets in the appropriate order. |
| 269 | std::vector<ulittle32_t> AddrMap; |
| 270 | AddrMap.reserve(Records.size()); |
Zachary Turner | d76dc2d | 2017-08-21 20:08:40 +0000 | [diff] [blame] | 271 | for (auto &Sym : PublicsByAddr) { |
| 272 | ptrdiff_t Idx = std::distance(Records.data(), Sym.first); |
Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 273 | assert(Idx >= 0 && size_t(Idx) < Records.size()); |
| 274 | AddrMap.push_back(ulittle32_t(SymOffsets[Idx])); |
| 275 | } |
| 276 | return AddrMap; |
| 277 | } |
| 278 | |
| 279 | uint32_t GSIStreamBuilder::getPublicsStreamIndex() const { |
| 280 | return PSH->StreamIndex; |
| 281 | } |
| 282 | |
| 283 | uint32_t GSIStreamBuilder::getGlobalsStreamIndex() const { |
| 284 | return GSH->StreamIndex; |
| 285 | } |
| 286 | |
| 287 | void GSIStreamBuilder::addPublicSymbol(const PublicSym32 &Pub) { |
Zachary Turner | ee9906d | 2017-08-11 19:00:03 +0000 | [diff] [blame] | 288 | PSH->addSymbol(Pub, Msf); |
| 289 | } |
| 290 | |
| 291 | void GSIStreamBuilder::addGlobalSymbol(const ProcRefSym &Sym) { |
| 292 | GSH->addSymbol(Sym, Msf); |
| 293 | } |
| 294 | |
| 295 | void GSIStreamBuilder::addGlobalSymbol(const DataSym &Sym) { |
| 296 | GSH->addSymbol(Sym, Msf); |
| 297 | } |
| 298 | |
| 299 | void GSIStreamBuilder::addGlobalSymbol(const ConstantSym &Sym) { |
| 300 | GSH->addSymbol(Sym, Msf); |
| 301 | } |
| 302 | |
Zachary Turner | ee9906d | 2017-08-11 19:00:03 +0000 | [diff] [blame] | 303 | void GSIStreamBuilder::addGlobalSymbol(const codeview::CVSymbol &Sym) { |
| 304 | GSH->addSymbol(Sym); |
Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | static Error writeRecords(BinaryStreamWriter &Writer, |
| 308 | ArrayRef<CVSymbol> Records) { |
| 309 | BinaryItemStream<CVSymbol> ItemStream(support::endianness::little); |
| 310 | ItemStream.setItems(Records); |
| 311 | BinaryStreamRef RecordsRef(ItemStream); |
| 312 | return Writer.writeStreamRef(RecordsRef); |
| 313 | } |
| 314 | |
| 315 | Error GSIStreamBuilder::commitSymbolRecordStream( |
| 316 | WritableBinaryStreamRef Stream) { |
| 317 | BinaryStreamWriter Writer(Stream); |
| 318 | |
| 319 | // Write public symbol records first, followed by global symbol records. This |
| 320 | // must match the order that we assume in finalizeMsfLayout when computing |
| 321 | // PSHZero and GSHZero. |
| 322 | if (auto EC = writeRecords(Writer, PSH->Records)) |
| 323 | return EC; |
| 324 | if (auto EC = writeRecords(Writer, GSH->Records)) |
| 325 | return EC; |
| 326 | |
| 327 | return Error::success(); |
| 328 | } |
| 329 | |
| 330 | Error GSIStreamBuilder::commitPublicsHashStream( |
| 331 | WritableBinaryStreamRef Stream) { |
Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 332 | BinaryStreamWriter Writer(Stream); |
Zachary Turner | 5448dab | 2017-08-09 04:23:59 +0000 | [diff] [blame] | 333 | PublicsStreamHeader Header; |
Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 334 | |
| 335 | // FIXME: Fill these in. They are for incremental linking. |
Nico Weber | e2745b5 | 2018-09-11 14:11:52 +0000 | [diff] [blame] | 336 | Header.SymHash = PSH->calculateSerializedLength(); |
| 337 | Header.AddrMap = PSH->Records.size() * 4; |
Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 338 | Header.NumThunks = 0; |
| 339 | Header.SizeOfThunk = 0; |
| 340 | Header.ISectThunkTable = 0; |
Nico Weber | e2745b5 | 2018-09-11 14:11:52 +0000 | [diff] [blame] | 341 | memset(Header.Padding, 0, sizeof(Header.Padding)); |
Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 342 | Header.OffThunkTable = 0; |
| 343 | Header.NumSections = 0; |
Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 344 | if (auto EC = Writer.writeObject(Header)) |
| 345 | return EC; |
| 346 | |
Zachary Turner | 5448dab | 2017-08-09 04:23:59 +0000 | [diff] [blame] | 347 | if (auto EC = PSH->commit(Writer)) |
| 348 | return EC; |
Zachary Turner | 946204c | 2017-08-09 04:23:25 +0000 | [diff] [blame] | 349 | |
| 350 | std::vector<ulittle32_t> AddrMap = computeAddrMap(PSH->Records); |
| 351 | if (auto EC = Writer.writeArray(makeArrayRef(AddrMap))) |
| 352 | return EC; |
| 353 | |
| 354 | return Error::success(); |
| 355 | } |
| 356 | |
| 357 | Error GSIStreamBuilder::commitGlobalsHashStream( |
| 358 | WritableBinaryStreamRef Stream) { |
| 359 | BinaryStreamWriter Writer(Stream); |
| 360 | return GSH->commit(Writer); |
| 361 | } |
| 362 | |
| 363 | Error GSIStreamBuilder::commit(const msf::MSFLayout &Layout, |
| 364 | WritableBinaryStreamRef Buffer) { |
| 365 | auto GS = WritableMappedBlockStream::createIndexedStream( |
| 366 | Layout, Buffer, getGlobalsStreamIndex(), Msf.getAllocator()); |
| 367 | auto PS = WritableMappedBlockStream::createIndexedStream( |
| 368 | Layout, Buffer, getPublicsStreamIndex(), Msf.getAllocator()); |
| 369 | auto PRS = WritableMappedBlockStream::createIndexedStream( |
| 370 | Layout, Buffer, getRecordStreamIdx(), Msf.getAllocator()); |
| 371 | |
| 372 | if (auto EC = commitSymbolRecordStream(*PRS)) |
| 373 | return EC; |
| 374 | if (auto EC = commitGlobalsHashStream(*GS)) |
| 375 | return EC; |
| 376 | if (auto EC = commitPublicsHashStream(*PS)) |
| 377 | return EC; |
| 378 | return Error::success(); |
| 379 | } |