LLVM 20.0.0git
|
This class links debug info. More...
#include "DWARFLinker/Parallel/DWARFLinkerImpl.h"
Classes | |
struct | DebugInfoSize |
Hold the input and output of the debug info size in bytes. More... | |
struct | LinkContext |
Keeps track of data associated with one object during linking. More... | |
Public Member Functions | |
DWARFLinkerImpl (MessageHandlerTy ErrorHandler, MessageHandlerTy WarningHandler) | |
void | addObjectFile (DWARFFile &File, ObjFileLoaderTy Loader=nullptr, CompileUnitHandlerTy OnCUDieLoaded=[](const DWARFUnit &) {}) override |
Add object file to be linked. | |
Error | link () override |
Link debug info for added files. | |
void | setOutputDWARFHandler (const Triple &TargetTriple, SectionHandlerTy SectionHandler) override |
Set output DWARF handler. | |
void | setVerbosity (bool Verbose) override |
Allows to generate log of linking process to the standard output. | |
void | setStatistics (bool Statistics) override |
Print statistics to standard output. | |
void | setVerifyInputDWARF (bool Verify) override |
Verify the input DWARF. | |
void | setNoODR (bool NoODR) override |
Do not unique types according to ODR. | |
void | setUpdateIndexTablesOnly (bool UpdateIndexTablesOnly) override |
Update index tables only(do not modify rest of DWARF). | |
void | setAllowNonDeterministicOutput (bool AllowNonDeterministicOutput) override |
Allow generating valid, but non-deterministic output. | |
void | setKeepFunctionForStatic (bool KeepFunctionForStatic) override |
Set to keep the enclosing function for a static variable. | |
void | setNumThreads (unsigned NumThreads) override |
Use specified number of threads for parallel files linking. | |
void | addAccelTableKind (AccelTableKind Kind) override |
Add kind of accelerator tables to be generated. | |
void | setPrependPath (StringRef Ppath) override |
Set prepend path for clang modules. | |
void | setEstimatedObjfilesAmount (unsigned ObjFilesNum) override |
Set estimated objects files amount, for preliminary data allocation. | |
void | setInputVerificationHandler (InputVerificationHandlerTy Handler) override |
Set verification handler which would be used to report verification errors. | |
void | setSwiftInterfacesMap (SwiftInterfacesMapTy *Map) override |
Set map for Swift interfaces. | |
void | setObjectPrefixMap (ObjectPrefixMapTy *Map) override |
Set prefix map for objects. | |
Error | setTargetDWARFVersion (uint16_t TargetDWARFVersion) override |
Set target DWARF version. | |
Public Member Functions inherited from llvm::dwarf_linker::parallel::DWARFLinker | |
virtual | ~DWARFLinker ()=default |
virtual void | setOutputDWARFHandler (const Triple &TargetTriple, SectionHandlerTy SectionHandler)=0 |
Set output DWARF handler. | |
Public Member Functions inherited from llvm::dwarf_linker::DWARFLinkerBase | |
virtual | ~DWARFLinkerBase ()=default |
virtual void | addObjectFile (DWARFFile &File, ObjFileLoaderTy Loader=nullptr, CompileUnitHandlerTy OnCUDieLoaded=[](const DWARFUnit &) {})=0 |
Add an object file to be linked. | |
virtual Error | link ()=0 |
Link the debug info for all object files added through calls to addObjectFile. | |
virtual void | setVerbosity (bool Verbose)=0 |
A number of methods setting various linking options: Enable logging to standard output. | |
virtual void | setStatistics (bool Statistics)=0 |
Print statistics to standard output. | |
virtual void | setVerifyInputDWARF (bool Verify)=0 |
Verify the input DWARF. | |
virtual void | setNoODR (bool NoODR)=0 |
Do not unique types according to ODR. | |
virtual void | setUpdateIndexTablesOnly (bool Update)=0 |
Update index tables only (do not modify rest of DWARF). | |
virtual void | setAllowNonDeterministicOutput (bool)=0 |
Allows generating non-deterministic output in exchange for more parallelism. | |
virtual void | setKeepFunctionForStatic (bool KeepFunctionForStatic)=0 |
Set whether to keep the enclosing function for a static variable. | |
virtual void | setNumThreads (unsigned NumThreads)=0 |
Use specified number of threads for parallel files linking. | |
virtual void | addAccelTableKind (AccelTableKind Kind)=0 |
Add kind of accelerator tables to be generated. | |
virtual void | setPrependPath (StringRef Ppath)=0 |
Set prepend path for clang modules. | |
virtual void | setEstimatedObjfilesAmount (unsigned ObjFilesNum)=0 |
Set estimated objects files amount, for preliminary data allocation. | |
virtual void | setInputVerificationHandler (InputVerificationHandlerTy Handler)=0 |
Set verification handler used to report verification errors. | |
virtual void | setSwiftInterfacesMap (SwiftInterfacesMapTy *Map)=0 |
Set map for Swift interfaces. | |
virtual void | setObjectPrefixMap (ObjectPrefixMapTy *Map)=0 |
Set prefix map for objects. | |
virtual Error | setTargetDWARFVersion (uint16_t TargetDWARFVersion)=0 |
Set target DWARF version. | |
Protected Types | |
enum | StringDestinationKind : uint8_t { DebugStr , DebugLineStr } |
Protected Member Functions | |
void | verifyInput (const DWARFFile &File) |
Verify input DWARF file. | |
Error | validateAndUpdateOptions () |
Validate specified options. | |
void | glueCompileUnitsAndWriteToTheOutput () |
Take already linked compile units and glue them into single file. | |
void | assignOffsets () |
Enumerate all compile units and assign offsets to their sections and strings. | |
void | assignOffsetsToSections () |
Enumerate all compile units and assign offsets to their sections. | |
void | assignOffsetsToStrings () |
Enumerate all compile units and assign offsets to their strings. | |
void | printStatistic () |
Print statistic for processed Debug Info. | |
void | forEachOutputString (function_ref< void(StringDestinationKind, const StringEntry *)> StringHandler) |
Enumerates all strings. | |
void | forEachObjectSectionsSet (function_ref< void(OutputSections &SectionsSet)> SectionsSetHandler) |
Enumerates sections for modules, invariant for object files, compile units. | |
void | forEachCompileAndTypeUnit (function_ref< void(DwarfUnit *CU)> UnitHandler) |
Enumerates all compile and type units. | |
void | forEachCompileUnit (function_ref< void(CompileUnit *CU)> UnitHandler) |
Enumerates all comple units. | |
void | patchOffsetsAndSizes () |
Enumerates all patches and update them with the correct values. | |
void | emitCommonSectionsAndWriteCompileUnitsToTheOutput () |
Emit debug sections common for all input files. | |
void | emitAppleAcceleratorSections (const Triple &TargetTriple) |
Emit apple accelerator sections. | |
void | emitDWARFv5DebugNamesSection (const Triple &TargetTriple) |
Emit .debug_names section. | |
void | emitStringSections () |
Emit string sections. | |
void | cleanupDataAfterDWARFOutputIsWritten () |
Cleanup data(string pools) after output sections are generated. | |
void | writeCompileUnitsToTheOutput () |
Enumerate all compile units and put their data into the output stream. | |
void | writeCommonSectionsToTheOutput () |
Enumerate common sections and put their data into the output stream. | |
Protected Attributes | |
std::atomic< size_t > | UniqueUnitID |
Unique ID for compile unit. | |
StringMap< uint64_t > | ClangModules |
Mapping the PCM filename to the DwoId. | |
std::mutex | ClangModulesMutex |
std::unique_ptr< TypeUnit > | ArtificialTypeUnit |
Type unit. | |
LinkingGlobalData | GlobalData |
StringEntryToDwarfStringPoolEntryMap | DebugStrStrings |
DwarfStringPoolEntries for .debug_str section. | |
StringEntryToDwarfStringPoolEntryMap | DebugLineStrStrings |
DwarfStringPoolEntries for .debug_line_str section. | |
SmallVector< std::unique_ptr< LinkContext > > | ObjectContexts |
Keeps all linking contexts. | |
OutputSections | CommonSections |
Common sections. | |
SectionHandlerTy | SectionHandler = nullptr |
Hanler for output sections. | |
uint64_t | OverallNumberOfCU = 0 |
Overall compile units number. | |
Friends | |
class | DependencyTracker |
Additional Inherited Members | |
Public Types inherited from llvm::dwarf_linker::DWARFLinkerBase | |
enum class | OutputFileType : uint8_t { Object , Assembly } |
Type of output file. More... | |
enum class | AccelTableKind : uint8_t { Apple , Pub , DebugNames } |
The kind of accelerator tables to be emitted. More... | |
using | MessageHandlerTy = std::function< void(const Twine &Warning, StringRef Context, const DWARFDie *DIE)> |
using | ObjFileLoaderTy = std::function< ErrorOr< DWARFFile & >(StringRef ContainerName, StringRef Path)> |
using | InputVerificationHandlerTy = std::function< void(const DWARFFile &File, llvm::StringRef Output)> |
using | ObjectPrefixMapTy = std::map< std::string, std::string > |
using | CompileUnitHandlerTy = function_ref< void(const DWARFUnit &Unit)> |
using | SwiftInterfacesMapTy = std::map< std::string, std::string > |
Static Public Member Functions inherited from llvm::dwarf_linker::parallel::DWARFLinker | |
static std::unique_ptr< DWARFLinker > | createLinker (MessageHandlerTy ErrorHandler, MessageHandlerTy WarningHandler) |
Creates dwarf linker instance. | |
This class links debug info.
Definition at line 26 of file DWARFLinkerImpl.h.
Enumerator | |
---|---|
DebugStr | |
DebugLineStr |
Definition at line 293 of file DWARFLinkerImpl.h.
DWARFLinkerImpl::DWARFLinkerImpl | ( | MessageHandlerTy | ErrorHandler, |
MessageHandlerTy | WarningHandler | ||
) |
Definition at line 22 of file DWARFLinkerImpl.cpp.
References ErrorHandler, GlobalData, llvm::dwarf_linker::parallel::LinkingGlobalData::setErrorHandler(), and llvm::dwarf_linker::parallel::LinkingGlobalData::setWarningHandler().
|
overridevirtual |
Add object file to be linked.
Pre-load compile unit die. Call OnCUDieLoaded
for each compile unit die. If specified File
has reference to the Clang module then such module would be pre-loaded by Loader
for !Update case.
Implements llvm::dwarf_linker::DWARFLinkerBase.
Definition at line 62 of file DWARFLinkerImpl.cpp.
References llvm::dwarf_linker::parallel::DWARFLinkerImpl::LinkContext::ClangModules, llvm::dwarf_linker::parallel::LinkingGlobalData::getOptions(), llvm::dwarf_linker::parallel::OutputSections::GlobalData, ObjectContexts, OverallNumberOfCU, llvm::dwarf_linker::parallel::DWARFLinkerImpl::LinkContext::UniqueUnitID, and llvm::dwarf_linker::parallel::DWARFLinkerOptions::UpdateIndexTablesOnly.
|
protected |
Enumerate all compile units and assign offsets to their sections and strings.
Definition at line 946 of file DWARFLinkerImpl.cpp.
References assignOffsetsToSections(), assignOffsetsToStrings(), and llvm::parallel::TaskGroup::spawn().
Referenced by glueCompileUnitsAndWriteToTheOutput().
|
protected |
Enumerate all compile units and assign offsets to their sections.
Definition at line 989 of file DWARFLinkerImpl.cpp.
References llvm::dwarf_linker::parallel::OutputSections::assignSectionsOffsetAndAccumulateSize(), and forEachObjectSectionsSet().
Referenced by assignOffsets().
|
protected |
Enumerate all compile units and assign offsets to their strings.
Definition at line 952 of file DWARFLinkerImpl.cpp.
References llvm::dwarf_linker::parallel::StringEntryToDwarfStringPoolEntryMap::add(), assert(), DebugLineStr, DebugLineStrStrings, DebugStr, DebugStrStrings, forEachOutputString(), and llvm::String.
Referenced by assignOffsets().
|
protected |
Cleanup data(string pools) after output sections are generated.
Definition at line 1400 of file DWARFLinkerImpl.cpp.
References llvm::dwarf_linker::StringPool::clear(), llvm::dwarf_linker::parallel::StringEntryToDwarfStringPoolEntryMap::clear(), DebugLineStrStrings, DebugStrStrings, llvm::dwarf_linker::parallel::LinkingGlobalData::getStringPool(), and llvm::dwarf_linker::parallel::OutputSections::GlobalData.
Referenced by glueCompileUnitsAndWriteToTheOutput().
Emit apple accelerator sections.
Definition at line 1210 of file DWARFLinkerImpl.cpp.
References llvm::dwarf_linker::AppleNames, llvm::dwarf_linker::AppleNamespaces, llvm::dwarf_linker::AppleObjC, llvm::dwarf_linker::AppleTypes, forEachCompileAndTypeUnit(), Info, llvm::dwarf_linker::parallel::DwarfUnit::Name, llvm::dwarf_linker::parallel::DwarfUnit::Namespace, llvm::dwarf_linker::parallel::DwarfUnit::ObjC, and llvm::dwarf_linker::parallel::DwarfUnit::Type.
Referenced by emitCommonSectionsAndWriteCompileUnitsToTheOutput().
|
protected |
Emit debug sections common for all input files.
Definition at line 1115 of file DWARFLinkerImpl.cpp.
References llvm::dwarf_linker::parallel::DWARFLinkerOptions::AccelTables, llvm::dwarf_linker::DWARFLinkerBase::Apple, llvm::dwarf_linker::AppleNames, llvm::dwarf_linker::AppleNamespaces, llvm::dwarf_linker::AppleObjC, llvm::dwarf_linker::AppleTypes, CommonSections, llvm::dwarf_linker::DebugLineStr, llvm::dwarf_linker::DebugNames, llvm::dwarf_linker::DWARFLinkerBase::DebugNames, llvm::dwarf_linker::DebugStr, emitAppleAcceleratorSections(), emitDWARFv5DebugNamesSection(), emitStringSections(), llvm::dwarf_linker::parallel::OutputSections::getOrCreateSectionDescriptor(), llvm::dwarf_linker::parallel::LinkingGlobalData::getTargetTriple(), llvm::dwarf_linker::parallel::OutputSections::GlobalData, llvm::is_contained(), llvm::dwarf_linker::parallel::LinkingGlobalData::Options, llvm::parallel::TaskGroup::spawn(), and writeCompileUnitsToTheOutput().
Referenced by glueCompileUnitsAndWriteToTheOutput().
Emit .debug_names section.
Definition at line 1340 of file DWARFLinkerImpl.cpp.
References llvm::dwarf_linker::DebugInfo, llvm::dwarf_linker::DWARFLinkerBase::DebugNames, forEachCompileAndTypeUnit(), and Info.
Referenced by emitCommonSectionsAndWriteCompileUnitsToTheOutput().
|
protected |
Emit string sections.
Definition at line 1161 of file DWARFLinkerImpl.cpp.
References assert(), CommonSections, llvm::dwarf_linker::DebugLineStr, DebugLineStr, DebugLineStrStrings, llvm::dwarf_linker::DebugStr, DebugStr, DebugStrStrings, llvm::dwarf_linker::parallel::SectionDescriptor::emitInplaceString(), forEachOutputString(), llvm::dwarf_linker::parallel::StringEntryToDwarfStringPoolEntryMap::getExistingEntry(), llvm::dwarf_linker::parallel::OutputSections::getSectionDescriptor(), llvm::DwarfStringPoolEntry::isIndexed(), llvm::DwarfStringPoolEntry::Offset, llvm::StringRef::size(), llvm::DwarfStringPoolEntryWithExtString::String, and llvm::String.
Referenced by emitCommonSectionsAndWriteCompileUnitsToTheOutput().
|
protected |
Enumerates all compile and type units.
Definition at line 1073 of file DWARFLinkerImpl.cpp.
References ArtificialTypeUnit, ObjectContexts, llvm::dwarf_linker::parallel::CompileUnit::Skipped, and llvm::dwarf_linker::parallel::DWARFLinkerImpl::LinkContext::RefModuleUnit::Unit.
Referenced by emitAppleAcceleratorSections(), and emitDWARFv5DebugNamesSection().
|
protected |
Enumerates all comple units.
Definition at line 1091 of file DWARFLinkerImpl.cpp.
References ObjectContexts, llvm::dwarf_linker::parallel::CompileUnit::Skipped, and llvm::dwarf_linker::parallel::DWARFLinkerImpl::LinkContext::RefModuleUnit::Unit.
Referenced by forEachOutputString().
|
protected |
Enumerates sections for modules, invariant for object files, compile units.
Definition at line 1049 of file DWARFLinkerImpl.cpp.
References ArtificialTypeUnit, ObjectContexts, llvm::dwarf_linker::parallel::CompileUnit::Skipped, and llvm::dwarf_linker::parallel::DWARFLinkerImpl::LinkContext::RefModuleUnit::Unit.
Referenced by assignOffsetsToSections(), patchOffsetsAndSizes(), and writeCompileUnitsToTheOutput().
|
protected |
Enumerates all strings.
Definition at line 997 of file DWARFLinkerImpl.cpp.
References ArtificialTypeUnit, DebugLineStr, DebugStr, forEachCompileUnit(), Info, and llvm::dwarf_linker::parallel::DebugStrPatch::String.
Referenced by assignOffsetsToStrings(), and emitStringSections().
|
protected |
Take already linked compile units and glue them into single file.
Definition at line 852 of file DWARFLinkerImpl.cpp.
References ArtificialTypeUnit, assert(), assignOffsets(), cleanupDataAfterDWARFOutputIsWritten(), emitCommonSectionsAndWriteCompileUnitsToTheOutput(), llvm::dwarf_linker::parallel::LinkingGlobalData::getOptions(), llvm::dwarf_linker::parallel::LinkingGlobalData::getTargetTriple(), llvm::dwarf_linker::parallel::OutputSections::GlobalData, patchOffsetsAndSizes(), printStatistic(), SectionHandler, llvm::dwarf_linker::parallel::DWARFLinkerOptions::Statistics, and writeCommonSectionsToTheOutput().
Referenced by link().
|
overridevirtual |
Link debug info for added files.
Implements llvm::dwarf_linker::DWARFLinkerBase.
Definition at line 90 of file DWARFLinkerImpl.cpp.
References llvm::dwarf::FormParams::AddrSize, ArtificialTypeUnit, llvm::ThreadPoolInterface::async(), llvm::big, llvm::DIDumpOptions::ChildRecurseDepth, CommonSections, llvm::dwarf::DWARF32, llvm::dwarf_linker::parallel::LinkingGlobalData::error(), llvm::DWARFDie::find(), llvm::dwarf_linker::parallel::LinkingGlobalData::getOptions(), llvm::dwarf_linker::parallel::LinkingGlobalData::getTargetTriple(), llvm::dwarf_linker::parallel::OutputSections::GlobalData, glueCompileUnitsAndWriteToTheOutput(), llvm::hardware_concurrency(), llvm::dwarf_linker::parallel::isODRLanguage(), llvm::little, llvm::native, llvm::dwarf_linker::parallel::DWARFLinkerOptions::NoODR, ObjectContexts, llvm::optimal_concurrency(), llvm::dwarf_linker::parallel::LinkingGlobalData::Options, llvm::outs(), OverallNumberOfCU, llvm::dwarf_linker::parallel::OutputSections::setOutputFormat(), llvm::parallel::TaskGroup::spawn(), llvm::parallel::strategy, llvm::Error::success(), llvm::dwarf_linker::parallel::DWARFLinkerOptions::TargetDWARFVersion, llvm::dwarf_linker::parallel::DWARFLinkerOptions::Threads, llvm::dwarf::toUnsigned(), llvm::dwarf_linker::parallel::DWARFLinkerImpl::LinkContext::UniqueUnitID, validateAndUpdateOptions(), llvm::DIDumpOptions::Verbose, llvm::dwarf_linker::parallel::DWARFLinkerOptions::Verbose, verifyInput(), llvm::dwarf_linker::parallel::DWARFLinkerOptions::VerifyInputDWARF, and llvm::SingleThreadExecutor::wait().
|
protected |
Enumerates all patches and update them with the correct values.
Definition at line 1106 of file DWARFLinkerImpl.cpp.
References llvm::dwarf_linker::parallel::OutputSections::applyPatches(), ArtificialTypeUnit, DebugLineStrStrings, DebugStrStrings, llvm::dwarf_linker::parallel::OutputSections::forEach(), and forEachObjectSectionsSet().
Referenced by glueCompileUnitsAndWriteToTheOutput().
|
protected |
Print statistic for processed Debug Info.
Definition at line 881 of file DWARFLinkerImpl.cpp.
References llvm::dwarf_linker::DebugInfo, llvm::sys::path::filename(), llvm::formatv(), LHS, ObjectContexts, llvm::outs(), RHS, llvm::sort(), and llvm::StringRef::take_back().
Referenced by glueCompileUnitsAndWriteToTheOutput().
|
inlineoverridevirtual |
Set output DWARF handler.
May be not set if output generation is not necessary.
Implements llvm::dwarf_linker::parallel::DWARFLinker.
Definition at line 47 of file DWARFLinkerImpl.h.
References GlobalData, SectionHandler, and llvm::dwarf_linker::parallel::LinkingGlobalData::setTargetTriple().
|
protected |
Validate specified options.
Definition at line 237 of file DWARFLinkerImpl.cpp.
References llvm::createStringError(), llvm::dwarf_linker::parallel::LinkingGlobalData::getOptions(), llvm::dwarf_linker::parallel::OutputSections::GlobalData, llvm::dwarf_linker::parallel::DWARFLinkerOptions::NoODR, llvm::dwarf_linker::parallel::LinkingGlobalData::Options, llvm::Error::success(), llvm::dwarf_linker::parallel::DWARFLinkerOptions::TargetDWARFVersion, llvm::dwarf_linker::parallel::DWARFLinkerOptions::Threads, llvm::dwarf_linker::parallel::DWARFLinkerOptions::UpdateIndexTablesOnly, llvm::dwarf_linker::parallel::DWARFLinkerOptions::Verbose, and llvm::dwarf_linker::parallel::LinkingGlobalData::warn().
Referenced by link().
Verify input DWARF file.
Definition at line 225 of file DWARFLinkerImpl.cpp.
References assert(), llvm::dwarf_linker::parallel::LinkingGlobalData::getOptions(), llvm::dwarf_linker::parallel::OutputSections::GlobalData, llvm::dwarf_linker::parallel::DWARFLinkerOptions::InputVerificationHandler, llvm::DIDumpOptions::noImplicitRecursion(), and OS.
Referenced by link().
|
protected |
Enumerate common sections and put their data into the output stream.
Definition at line 1416 of file DWARFLinkerImpl.cpp.
References CommonSections, llvm::dwarf_linker::parallel::OutputSections::forEach(), and SectionHandler.
Referenced by glueCompileUnitsAndWriteToTheOutput().
|
protected |
Enumerate all compile units and put their data into the output stream.
Definition at line 1406 of file DWARFLinkerImpl.cpp.
References llvm::dwarf_linker::parallel::OutputSections::forEach(), forEachObjectSectionsSet(), and SectionHandler.
Referenced by emitCommonSectionsAndWriteCompileUnitsToTheOutput().
|
friend |
Definition at line 157 of file DWARFLinkerImpl.h.