aboutsummaryrefslogtreecommitdiffstats
path: root/COFF/PDB.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'COFF/PDB.cpp')
-rw-r--r--COFF/PDB.cpp59
1 files changed, 27 insertions, 32 deletions
diff --git a/COFF/PDB.cpp b/COFF/PDB.cpp
index a55e5136e040..ea99583b1d80 100644
--- a/COFF/PDB.cpp
+++ b/COFF/PDB.cpp
@@ -51,21 +51,22 @@
#include "llvm/Object/COFF.h"
#include "llvm/Object/CVDebugRecord.h"
#include "llvm/Support/BinaryByteStream.h"
+#include "llvm/Support/CRC.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/FormatVariadic.h"
-#include "llvm/Support/JamCRC.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/ScopedPrinter.h"
#include <memory>
-using namespace lld;
-using namespace lld::coff;
using namespace llvm;
using namespace llvm::codeview;
using llvm::object::coff_section;
+namespace lld {
+namespace coff {
+
static ExitOnError exitOnErr;
static Timer totalPdbLinkTimer("PDB Emission (Cumulative)", Timer::root());
@@ -513,16 +514,15 @@ static bool equals_path(StringRef path1, StringRef path2) {
return path1.equals(path2);
#endif
}
-
// Find by name an OBJ provided on the command line
-static ObjFile *findObjByName(StringRef fileNameOnly) {
- SmallString<128> currentPath;
-
+static ObjFile *findObjWithPrecompSignature(StringRef fileNameOnly,
+ uint32_t precompSignature) {
for (ObjFile *f : ObjFile::instances) {
StringRef currentFileName = sys::path::filename(f->getName());
- // Compare based solely on the file name (link.exe behavior)
- if (equals_path(currentFileName, fileNameOnly))
+ if (f->pchSignature.hasValue() &&
+ f->pchSignature.getValue() == precompSignature &&
+ equals_path(fileNameOnly, currentFileName))
return f;
}
return nullptr;
@@ -559,22 +559,15 @@ Expected<const CVIndexMap &> PDBLinker::aquirePrecompObj(ObjFile *file) {
// link.exe requires that a precompiled headers object must always be provided
// on the command-line, even if that's not necessary.
- auto precompFile = findObjByName(precompFileName);
+ auto precompFile =
+ findObjWithPrecompSignature(precompFileName, precomp.Signature);
if (!precompFile)
return createFileError(
- precompFileName.str(),
- make_error<pdb::PDBError>(pdb::pdb_error_code::external_cmdline_ref));
+ precomp.getPrecompFilePath().str(),
+ make_error<pdb::PDBError>(pdb::pdb_error_code::no_matching_pch));
addObjFile(precompFile, &indexMap);
- if (!precompFile->pchSignature)
- fatal(precompFile->getName() + " is not a precompiled headers object");
-
- if (precomp.getSignature() != precompFile->pchSignature.getValueOr(0))
- return createFileError(
- precomp.getPrecompFilePath().str(),
- make_error<pdb::PDBError>(pdb::pdb_error_code::signature_out_of_date));
-
return indexMap;
}
@@ -965,9 +958,7 @@ static pdb::SectionContrib createSectionContrib(const Chunk *c, uint32_t modi) {
sc.Imod = secChunk->file->moduleDBI->getModuleIndex();
ArrayRef<uint8_t> contents = secChunk->getContents();
JamCRC crc(0);
- ArrayRef<char> charContents = makeArrayRef(
- reinterpret_cast<const char *>(contents.data()), contents.size());
- crc.update(charContents);
+ crc.update(contents);
sc.DataCrc = crc.getCRC();
} else {
sc.Characteristics = os ? os->header.Characteristics : 0;
@@ -1150,7 +1141,7 @@ void DebugSHandler::finish() {
// string table. Generally the string table subsection appears after the
// checksum table, so we have to do this after looping over all the
// subsections.
- auto newChecksums = make_unique<DebugChecksumsSubsection>(linker.pdbStrTab);
+ auto newChecksums = std::make_unique<DebugChecksumsSubsection>(linker.pdbStrTab);
for (FileChecksumEntry &fc : checksums) {
SmallString<128> filename =
exitOnErr(cVStrTab.getString(fc.FileNameOffset));
@@ -1599,7 +1590,7 @@ void PDBLinker::addImportFilesToPDB(ArrayRef<OutputSection *> outputSections) {
}
// Creates a PDB file.
-void coff::createPDB(SymbolTable *symtab,
+void createPDB(SymbolTable *symtab,
ArrayRef<OutputSection *> outputSections,
ArrayRef<uint8_t> sectionTable,
llvm::codeview::DebugInfo *buildId) {
@@ -1693,6 +1684,7 @@ void PDBLinker::addSections(ArrayRef<OutputSection *> outputSections,
}
void PDBLinker::commit(codeview::GUID *guid) {
+ ExitOnError exitOnErr((config->pdbPath + ": ").str());
// Write to a file.
exitOnErr(builder.commit(config->pdbPath, guid));
}
@@ -1797,10 +1789,10 @@ static bool findLineTable(const SectionChunk *c, uint32_t addr,
}
// Use CodeView line tables to resolve a file and line number for the given
-// offset into the given chunk and return them, or {"", 0} if a line table was
+// offset into the given chunk and return them, or None if a line table was
// not found.
-std::pair<StringRef, uint32_t> coff::getFileLine(const SectionChunk *c,
- uint32_t addr) {
+Optional<std::pair<StringRef, uint32_t>>
+getFileLineCodeView(const SectionChunk *c, uint32_t addr) {
ExitOnError exitOnErr;
DebugStringTableSubsectionRef cVStrTab;
@@ -1809,7 +1801,7 @@ std::pair<StringRef, uint32_t> coff::getFileLine(const SectionChunk *c,
uint32_t offsetInLinetable;
if (!findLineTable(c, addr, cVStrTab, checksums, lines, offsetInLinetable))
- return {"", 0};
+ return None;
Optional<uint32_t> nameIndex;
Optional<uint32_t> lineNumber;
@@ -1823,14 +1815,17 @@ std::pair<StringRef, uint32_t> coff::getFileLine(const SectionChunk *c,
}
StringRef filename =
exitOnErr(getFileName(cVStrTab, checksums, *nameIndex));
- return {filename, *lineNumber};
+ return std::make_pair(filename, *lineNumber);
}
nameIndex = entry.NameIndex;
lineNumber = li.getStartLine();
}
}
if (!nameIndex)
- return {"", 0};
+ return None;
StringRef filename = exitOnErr(getFileName(cVStrTab, checksums, *nameIndex));
- return {filename, *lineNumber};
+ return std::make_pair(filename, *lineNumber);
}
+
+} // namespace coff
+} // namespace lld