From 8d927b6bf908503e7d2f7aca22d6fec2a15fd44b Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Mon, 31 Jul 2017 19:36:08 +0000 Subject: [lld/pdb] Add an empty globals stream. We don't write any actual symbols to this stream yet, but for now we just create the stream and hook it up to the appropriate places and give it a valid header. Differential Revision: https://reviews.llvm.org/D35290 llvm-svn: 309608 --- .../DebugInfo/PDB/Native/GlobalsStreamBuilder.cpp | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 llvm/lib/DebugInfo/PDB/Native/GlobalsStreamBuilder.cpp (limited to 'llvm/lib/DebugInfo/PDB/Native/GlobalsStreamBuilder.cpp') diff --git a/llvm/lib/DebugInfo/PDB/Native/GlobalsStreamBuilder.cpp b/llvm/lib/DebugInfo/PDB/Native/GlobalsStreamBuilder.cpp new file mode 100644 index 00000000000..004691e78e7 --- /dev/null +++ b/llvm/lib/DebugInfo/PDB/Native/GlobalsStreamBuilder.cpp @@ -0,0 +1,79 @@ +//===- GlobalsStreamBuilder.cpp - PDB Globals Stream Creation ---*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/Native/GlobalsStreamBuilder.h" + +#include "llvm/DebugInfo/MSF/MSFBuilder.h" +#include "llvm/DebugInfo/MSF/MSFCommon.h" +#include "llvm/DebugInfo/MSF/MappedBlockStream.h" +#include "llvm/DebugInfo/PDB/Native/GlobalsStream.h" + +using namespace llvm; +using namespace llvm::msf; +using namespace llvm::pdb; + +GlobalsStreamBuilder::GlobalsStreamBuilder(msf::MSFBuilder &Msf) : Msf(Msf) {} + +GlobalsStreamBuilder::~GlobalsStreamBuilder() {} + +uint32_t GlobalsStreamBuilder::calculateSerializedLength() const { + uint32_t Size = 0; + // First is the header + Size += sizeof(GSIHashHeader); + + // Next is the records. For now we don't write any records, just an empty + // stream. + // FIXME: Write records and account for their size here. + Size += 0; + + // Next is a bitmap indicating which hash buckets are valid. The bitmap + // is alway present, but we only write buckets for bitmap entries which are + // non-zero, which now is noting. + size_t BitmapSizeInBits = alignTo(IPHR_HASH + 1, 32); + uint32_t NumBitmapEntries = BitmapSizeInBits / 8; + Size += NumBitmapEntries; + + // FIXME: Account for hash buckets. For now since we we write a zero-bitmap + // indicating that no hash buckets are valid, we also write zero byets of hash + // bucket data. + Size += 0; + return Size; +} + +Error GlobalsStreamBuilder::finalizeMsfLayout() { + Expected Idx = Msf.addStream(calculateSerializedLength()); + if (!Idx) + return Idx.takeError(); + StreamIdx = *Idx; + return Error::success(); +} + +Error GlobalsStreamBuilder::commit(BinaryStreamWriter &PublicsWriter) { + GSIHashHeader GSH; + + GSH.VerSignature = GSIHashHeader::HdrSignature; + GSH.VerHdr = GSIHashHeader::HdrVersion; + GSH.HrSize = 0; + GSH.NumBuckets = 0; + + if (auto EC = PublicsWriter.writeObject(GSH)) + return EC; + + // FIXME: Once we start writing a value other than 0 for GSH.HrSize, we need + // to write the hash records here. + size_t BitmapSizeInBits = alignTo(IPHR_HASH + 1, 32); + uint32_t NumBitmapEntries = BitmapSizeInBits / 8; + std::vector BitmapData(NumBitmapEntries); + // FIXME: Build an actual bitmap + if (auto EC = PublicsWriter.writeBytes(makeArrayRef(BitmapData))) + return EC; + + // FIXME: Write actual hash buckets. + return Error::success(); +} -- cgit v1.2.3