LLVM  6.0.0svn
PublicsStream.cpp
Go to the documentation of this file.
1 //===- PublicsStream.cpp - PDB Public Symbol Stream -----------------------===//
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 //
10 // The data structures defined in this file are based on the reference
11 // implementation which is available at
12 // https://github.com/Microsoft/microsoft-pdb/blob/master/PDB/dbi/gsi.h
13 //
14 // When you are reading the reference source code, you'd find the
15 // information below useful.
16 //
17 // - ppdb1->m_fMinimalDbgInfo seems to be always true.
18 // - SMALLBUCKETS macro is defined.
19 //
20 // The reference doesn't compile, so I learned just by reading code.
21 // It's not guaranteed to be correct.
22 //
23 //===----------------------------------------------------------------------===//
24 
33 #include "llvm/Support/Endian.h"
34 #include "llvm/Support/Error.h"
35 #include <algorithm>
36 #include <cstdint>
37 
38 using namespace llvm;
39 using namespace llvm::msf;
40 using namespace llvm::support;
41 using namespace llvm::pdb;
42 
43 PublicsStream::PublicsStream(std::unique_ptr<MappedBlockStream> Stream)
44  : Stream(std::move(Stream)) {}
45 
47 
48 uint32_t PublicsStream::getSymHash() const { return Header->SymHash; }
50  return Header->ISectThunkTable;
51 }
53  return Header->OffThunkTable;
54 }
55 
56 // Publics stream contains fixed-size headers and a serialized hash table.
57 // This implementation is not complete yet. It reads till the end of the
58 // stream so that we verify the stream is at least not corrupted. However,
59 // we skip over the hash table which we believe contains information about
60 // public symbols.
62  BinaryStreamReader Reader(*Stream);
63 
64  // Check stream size.
65  if (Reader.bytesRemaining() <
66  sizeof(PublicsStreamHeader) + sizeof(GSIHashHeader))
67  return make_error<RawError>(raw_error_code::corrupt_file,
68  "Publics Stream does not contain a header.");
69 
70  // Read PSGSIHDR struct.
71  if (Reader.readObject(Header))
72  return make_error<RawError>(raw_error_code::corrupt_file,
73  "Publics Stream does not contain a header.");
74 
75  // Read the hash table.
76  if (auto E = PublicsTable.read(Reader))
77  return E;
78 
79  // Something called "address map" follows.
80  uint32_t NumAddressMapEntries = Header->AddrMap / sizeof(uint32_t);
81  if (auto EC = Reader.readArray(AddressMap, NumAddressMapEntries))
82  return joinErrors(std::move(EC),
83  make_error<RawError>(raw_error_code::corrupt_file,
84  "Could not read an address map."));
85 
86  // Something called "thunk map" follows.
87  if (auto EC = Reader.readArray(ThunkMap, Header->NumThunks))
88  return joinErrors(std::move(EC),
89  make_error<RawError>(raw_error_code::corrupt_file,
90  "Could not read a thunk map."));
91 
92  // Something called "section map" follows.
93  if (Reader.bytesRemaining() > 0) {
94  if (auto EC = Reader.readArray(SectionOffsets, Header->NumSections))
95  return joinErrors(std::move(EC),
96  make_error<RawError>(raw_error_code::corrupt_file,
97  "Could not read a section map."));
98  }
99 
100  if (Reader.bytesRemaining() > 0)
101  return make_error<RawError>(raw_error_code::corrupt_file,
102  "Corrupted publics stream.");
103  return Error::success();
104 }
uint32_t getThunkTableOffset() const
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
Error readObject(const T *&Dest)
Get a pointer to an object of type T from the underlying stream, as if by memcpy, and store the resul...
support::ulittle32_t NumThunks
Definition: RawTypes.h:278
uint16_t getThunkTableSection() const
Definition: BitVector.h:920
Header of the hash tables found in the globals and publics sections.
Definition: RawTypes.h:29
support::ulittle16_t ISectThunkTable
Definition: RawTypes.h:280
uint32_t getSymHash() const
Error read(BinaryStreamReader &Reader)
support::ulittle32_t SymHash
Definition: RawTypes.h:276
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
support::ulittle32_t AddrMap
Definition: RawTypes.h:277
static ErrorSuccess success()
Create a success value.
Definition: Error.h:313
support::ulittle32_t OffThunkTable
Definition: RawTypes.h:282
Error joinErrors(Error E1, Error E2)
Concatenate errors.
Definition: Error.h:408
uint32_t bytesRemaining() const
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
Provides read only access to a subclass of BinaryStream.
support::ulittle32_t NumSections
Definition: RawTypes.h:283
Error readArray(ArrayRef< T > &Array, uint32_t NumElements)
Get a reference to a NumElements element array of objects of type T from the underlying stream as if ...