#include "PDB.h"
#include "COFFLinkerContext.h"
#include "Chunks.h"
#include "Config.h"
#include "DebugTypes.h"
#include "Driver.h"
#include "SymbolTable.h"
#include "Symbols.h"
#include "TypeMerger.h"
#include "Writer.h"
#include "lld/Common/Timer.h"
#include "llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h"
#include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h"
#include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h"
#include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h"
#include "llvm/DebugInfo/CodeView/GlobalTypeTableBuilder.h"
#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
#include "llvm/DebugInfo/CodeView/MergingTypeTableBuilder.h"
#include "llvm/DebugInfo/CodeView/RecordName.h"
#include "llvm/DebugInfo/CodeView/SymbolDeserializer.h"
#include "llvm/DebugInfo/CodeView/SymbolRecordHelpers.h"
#include "llvm/DebugInfo/CodeView/SymbolSerializer.h"
#include "llvm/DebugInfo/CodeView/TypeIndexDiscovery.h"
#include "llvm/DebugInfo/MSF/MSFBuilder.h"
#include "llvm/DebugInfo/MSF/MSFCommon.h"
#include "llvm/DebugInfo/MSF/MSFError.h"
#include "llvm/DebugInfo/PDB/GenericError.h"
#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h"
#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
#include "llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h"
#include "llvm/DebugInfo/PDB/Native/GSIStreamBuilder.h"
#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
#include "llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h"
#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
#include "llvm/DebugInfo/PDB/Native/PDBFileBuilder.h"
#include "llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h"
#include "llvm/DebugInfo/PDB/Native/TpiHashing.h"
#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
#include "llvm/DebugInfo/PDB/Native/TpiStreamBuilder.h"
#include "llvm/DebugInfo/PDB/PDB.h"
#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/FormatAdapters.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/ScopedPrinter.h"
#include "llvm/Support/TimeProfiler.h"
#include <memory>
#include <optional>
usingnamespacellvm;
usingnamespacellvm::codeview;
usingnamespacelld;
usingnamespacelld::coff;
coff_section;
StringTableFixup;
namespace {
class DebugSHandler;
class PDBLinker { … };
struct UnrelocatedFpoData { … };
enum : uint32_t { … };
class DebugSHandler { … };
}
void PDBLinker::pdbMakeAbsolute(SmallVectorImpl<char> &fileName) { … }
static void addTypeInfo(pdb::TpiStreamBuilder &tpiBuilder,
TypeCollection &typeTable) { … }
static void addGHashTypeInfo(COFFLinkerContext &ctx,
pdb::PDBFileBuilder &builder) { … }
static void
recordStringTableReferences(CVSymbol sym, uint32_t symOffset,
std::vector<StringTableFixup> &stringTableFixups) { … }
static SymbolKind symbolKind(ArrayRef<uint8_t> recordData) { … }
void PDBLinker::translateIdSymbols(MutableArrayRef<uint8_t> &recordData,
TpiSource *source) { … }
namespace {
struct ScopeRecord { … };
}
static ScopeRecord *getSymbolScopeFields(void *sym) { … }
static void scopeStackOpen(SmallVectorImpl<uint32_t> &stack,
std::vector<uint8_t> &storage) { … }
static void scopeStackClose(SmallVectorImpl<uint32_t> &stack,
std::vector<uint8_t> &storage,
uint32_t storageBaseOffset, ObjFile *file) { … }
static bool symbolGoesInModuleStream(const CVSymbol &sym,
unsigned symbolScopeDepth) { … }
static bool symbolGoesInGlobalsStream(const CVSymbol &sym,
unsigned symbolScopeDepth) { … }
static void addGlobalSymbol(pdb::GSIStreamBuilder &builder, uint16_t modIndex,
unsigned symOffset,
std::vector<uint8_t> &symStorage) { … }
static void fixRecordAlignment(MutableArrayRef<uint8_t> recordBytes,
size_t oldSize) { … }
static void replaceWithSkipRecord(MutableArrayRef<uint8_t> recordBytes) { … }
void PDBLinker::writeSymbolRecord(SectionChunk *debugChunk,
ArrayRef<uint8_t> sectionContents,
CVSymbol sym, size_t alignedSize,
uint32_t &nextRelocIndex,
std::vector<uint8_t> &storage) { … }
void PDBLinker::analyzeSymbolSubsection(
SectionChunk *debugChunk, uint32_t &moduleSymOffset,
uint32_t &nextRelocIndex, std::vector<StringTableFixup> &stringTableFixups,
BinaryStreamRef symData) { … }
Error PDBLinker::writeAllModuleSymbolRecords(ObjFile *file,
BinaryStreamWriter &writer) { … }
Error PDBLinker::commitSymbolsForObject(void *ctx, void *obj,
BinaryStreamWriter &writer) { … }
static pdb::SectionContrib createSectionContrib(COFFLinkerContext &ctx,
const Chunk *c, uint32_t modi) { … }
static uint32_t
translateStringTableIndex(uint32_t objIndex,
const DebugStringTableSubsectionRef &objStrTable,
DebugStringTableSubsection &pdbStrTable) { … }
void DebugSHandler::handleDebugS(SectionChunk *debugChunk) { … }
void DebugSHandler::advanceRelocIndex(SectionChunk *sc,
ArrayRef<uint8_t> subsec) { … }
namespace {
class UnrelocatedDebugSubsection : public DebugSubsection { … };
}
Error UnrelocatedDebugSubsection::commit(BinaryStreamWriter &writer) const { … }
void DebugSHandler::addUnrelocatedSubsection(SectionChunk *debugChunk,
const DebugSubsectionRecord &ss) { … }
void DebugSHandler::addFrameDataSubsection(SectionChunk *debugChunk,
const DebugSubsectionRecord &ss) { … }
static Expected<StringRef>
getFileName(const DebugStringTableSubsectionRef &strings,
const DebugChecksumsSubsectionRef &checksums, uint32_t fileID) { … }
void DebugSHandler::finish() { … }
static void warnUnusable(InputFile *f, Error e, bool shouldWarn) { … }
static ArrayRef<uint8_t> relocateDebugChunk(SectionChunk &debugChunk) { … }
void PDBLinker::addDebugSymbols(TpiSource *source) { … }
void PDBLinker::createModuleDBI(ObjFile *file) { … }
void PDBLinker::addDebug(TpiSource *source) { … }
static pdb::BulkPublic createPublic(COFFLinkerContext &ctx, Defined *def) { … }
void PDBLinker::addObjectsToPDB() { … }
void PDBLinker::addPublicsToPDB() { … }
void PDBLinker::printStats() { … }
void PDBLinker::addNatvisFiles() { … }
void PDBLinker::addNamedStreams() { … }
static codeview::CPUType toCodeViewMachine(COFF::MachineTypes machine) { … }
static std::string quote(ArrayRef<StringRef> args) { … }
static void fillLinkerVerRecord(Compile3Sym &cs, MachineTypes machine) { … }
void PDBLinker::addCommonLinkerModuleSymbols(
StringRef path, pdb::DbiModuleDescriptorBuilder &mod) { … }
static void addLinkerModuleCoffGroup(PartialSection *sec,
pdb::DbiModuleDescriptorBuilder &mod,
OutputSection &os) { … }
static void addLinkerModuleSectionSymbol(pdb::DbiModuleDescriptorBuilder &mod,
OutputSection &os, bool isMinGW) { … }
void PDBLinker::addImportFilesToPDB() { … }
void lld::coff::createPDB(COFFLinkerContext &ctx,
ArrayRef<uint8_t> sectionTable,
llvm::codeview::DebugInfo *buildId) { … }
void PDBLinker::initialize(llvm::codeview::DebugInfo *buildId) { … }
void PDBLinker::addSections(ArrayRef<uint8_t> sectionTable) { … }
void PDBLinker::commit(codeview::GUID *guid) { … }
static uint32_t getSecrelReloc(Triple::ArchType arch) { … }
static bool findLineTable(const SectionChunk *c, uint32_t addr,
DebugStringTableSubsectionRef &cvStrTab,
DebugChecksumsSubsectionRef &checksums,
DebugLinesSubsectionRef &lines,
uint32_t &offsetInLinetable) { … }
std::optional<std::pair<StringRef, uint32_t>>
lld::coff::getFileLineCodeView(const SectionChunk *c, uint32_t addr) { … }