diff options
author | Zachary Turner <zturner@google.com> | 2016-07-15 20:43:38 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2016-07-15 20:43:38 +0000 |
commit | f52a899f4aedc5770c5af0a2343bfd1e50385400 (patch) | |
tree | f163389cc1c44dc0b72c8b300a27b6450bb316cb /llvm/lib/DebugInfo/PDB/Raw/MsfCommon.cpp | |
parent | 511f2e5a8955c90d6b9c176c31af2ec3add395fa (diff) | |
download | bcm5719-llvm-f52a899f4aedc5770c5af0a2343bfd1e50385400.tar.gz bcm5719-llvm-f52a899f4aedc5770c5af0a2343bfd1e50385400.zip |
[pdb] Introduce MsfBuilder for laying out PDB files.
Reviewed by: ruiu
Differential Revision: https://reviews.llvm.org/D22308
llvm-svn: 275611
Diffstat (limited to 'llvm/lib/DebugInfo/PDB/Raw/MsfCommon.cpp')
-rw-r--r-- | llvm/lib/DebugInfo/PDB/Raw/MsfCommon.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/llvm/lib/DebugInfo/PDB/Raw/MsfCommon.cpp b/llvm/lib/DebugInfo/PDB/Raw/MsfCommon.cpp new file mode 100644 index 00000000000..5d97f33e110 --- /dev/null +++ b/llvm/lib/DebugInfo/PDB/Raw/MsfCommon.cpp @@ -0,0 +1,48 @@ +//===- MsfCommon.cpp - Common types and functions for MSF files -*- 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/Raw/MsfCommon.h" +#include "llvm/DebugInfo/PDB/Raw/RawError.h" + +using namespace llvm; +using namespace llvm::pdb::msf; + +Error llvm::pdb::msf::validateSuperBlock(const SuperBlock &SB) { + // Check the magic bytes. + if (std::memcmp(SB.MagicBytes, Magic, sizeof(Magic)) != 0) + return make_error<RawError>(raw_error_code::corrupt_file, + "MSF magic header doesn't match"); + + if (!isValidBlockSize(SB.BlockSize)) + return make_error<RawError>(raw_error_code::corrupt_file, + "Unsupported block size."); + + // We don't support directories whose sizes aren't a multiple of four bytes. + if (SB.NumDirectoryBytes % sizeof(support::ulittle32_t) != 0) + return make_error<RawError>(raw_error_code::corrupt_file, + "Directory size is not multiple of 4."); + + // The number of blocks which comprise the directory is a simple function of + // the number of bytes it contains. + uint64_t NumDirectoryBlocks = + bytesToBlocks(SB.NumDirectoryBytes, SB.BlockSize); + + // The directory, as we understand it, is a block which consists of a list of + // block numbers. It is unclear what would happen if the number of blocks + // couldn't fit on a single block. + if (NumDirectoryBlocks > SB.BlockSize / sizeof(support::ulittle32_t)) + return make_error<RawError>(raw_error_code::corrupt_file, + "Too many directory blocks."); + + if (SB.BlockMapAddr == 0) + return make_error<RawError>(raw_error_code::corrupt_file, + "Block 0 is reserved"); + + return Error::success(); +} |