LLVM 20.0.0git
|
Keeps track of data associated with one object during linking. More...
#include "DWARFLinker/Parallel/DWARFLinkerImpl.h"
Classes | |
struct | RefModuleUnit |
Keep information for referenced clang module: already loaded DWARF info of the clang module and a CompileUnit of the module. More... | |
Public Types | |
using | UnitListTy = SmallVector< std::unique_ptr< CompileUnit > > |
using | ModuleUnitListTy = SmallVector< RefModuleUnit > |
Public Member Functions | |
LinkContext (LinkingGlobalData &GlobalData, DWARFFile &File, StringMap< uint64_t > &ClangModules, std::atomic< size_t > &UniqueUnitID) | |
std::pair< bool, bool > | isClangModuleRef (const DWARFDie &CUDie, std::string &PCMFile, unsigned Indent, bool Quiet) |
Check whether specified CUDie is a Clang module reference. | |
bool | registerModuleReference (const DWARFDie &CUDie, ObjFileLoaderTy Loader, CompileUnitHandlerTy OnCUDieLoaded, unsigned Indent=0) |
If this compile unit is really a skeleton CU that points to a clang module, register it in ClangModules and return true. | |
Error | loadClangModule (ObjFileLoaderTy Loader, const DWARFDie &CUDie, const std::string &PCMFile, CompileUnitHandlerTy OnCUDieLoaded, unsigned Indent=0) |
Recursively add the debug info in this clang module .pcm file (and all the modules imported by it in a bottom-up fashion) to ModuleUnits. | |
void | addModulesCompileUnit (RefModuleUnit &&Unit) |
Add Compile Unit corresponding to the module. | |
uint64_t | getInputDebugInfoSize () const |
Computes the total size of the debug info. | |
Error | link (TypeUnit *ArtificialTypeUnit) |
Link compile units for this context. | |
void | linkSingleCompileUnit (CompileUnit &CU, TypeUnit *ArtificialTypeUnit, enum CompileUnit::Stage DoUntilStage=CompileUnit::Stage::Cleaned) |
Link specified compile unit until specified stage. | |
Error | emitInvariantSections () |
Emit invariant sections. | |
Error | cloneAndEmitDebugFrame () |
Clone and emit .debug_frame. | |
void | emitFDE (uint32_t CIEOffset, uint32_t AddrSize, uint64_t Address, StringRef FDEBytes, SectionDescriptor &Section) |
Emit FDE record. | |
Public Member Functions inherited from llvm::dwarf_linker::parallel::OutputSections | |
OutputSections (LinkingGlobalData &GlobalData) | |
void | setOutputFormat (dwarf::FormParams Format, llvm::endianness Endianness) |
Sets output format for all keeping sections. | |
const SectionDescriptor & | getSectionDescriptor (DebugSectionKind SectionKind) const |
Returns descriptor for the specified section of SectionKind . | |
SectionDescriptor & | getSectionDescriptor (DebugSectionKind SectionKind) |
Returns descriptor for the specified section of SectionKind . | |
std::optional< const SectionDescriptor * > | tryGetSectionDescriptor (DebugSectionKind SectionKind) const |
Returns descriptor for the specified section of SectionKind . | |
std::optional< SectionDescriptor * > | tryGetSectionDescriptor (DebugSectionKind SectionKind) |
Returns descriptor for the specified section of SectionKind . | |
SectionDescriptor & | getOrCreateSectionDescriptor (DebugSectionKind SectionKind) |
Returns descriptor for the specified section of SectionKind . | |
void | eraseSections () |
Erases data of all sections. | |
void | forEach (function_ref< void(SectionDescriptor &)> Handler) |
Enumerate all sections and call Handler for each. | |
void | forEach (function_ref< void(std::shared_ptr< SectionDescriptor > Section)> Handler) |
Enumerate all sections and call Handler for each. | |
void | assignSectionsOffsetAndAccumulateSize (std::array< uint64_t, SectionKindsNum > &SectionSizesAccumulator) |
Enumerate all sections, for each section set current offset (kept by SectionSizesAccumulator ), update current offset with section length. | |
void | applyPatches (SectionDescriptor &Section, StringEntryToDwarfStringPoolEntryMap &DebugStrStrings, StringEntryToDwarfStringPoolEntryMap &DebugLineStrStrings, TypeUnit *TypeUnitPtr) |
Enumerate all sections, for each section apply all section patches. | |
llvm::endianness | getEndianness () const |
Endiannes for the sections. | |
uint16_t | getVersion () const |
Return DWARF version. | |
uint16_t | getDebugInfoHeaderSize () const |
Return size of header of debug_info table. | |
uint16_t | getDebugAddrHeaderSize () const |
Return size of header of debug_ table. | |
uint16_t | getDebugStrOffsetsHeaderSize () const |
Return size of header of debug_str_offsets table. | |
const dwarf::FormParams & | getFormParams () const |
Return size of address. | |
Public Attributes | |
DWARFFile & | InputDWARFFile |
Object file descriptor. | |
UnitListTy | CompileUnits |
Set of Compilation Units(may be accessed asynchroniously for reading). | |
ModuleUnitListTy | ModulesCompileUnits |
Set of Compile Units for modules. | |
uint64_t | OriginalDebugInfoSize = 0 |
Size of Debug info before optimizing. | |
bool | InterCUProcessingStarted = false |
Flag indicating that all inter-connected units are loaded and the dwarf linking process for these units is started. | |
StringMap< uint64_t > & | ClangModules |
std::atomic< bool > | HasNewInterconnectedCUs = {false} |
Flag indicating that new inter-connected compilation units were discovered. | |
std::atomic< bool > | HasNewGlobalDependency = {false} |
std::atomic< size_t > & | UniqueUnitID |
Counter for compile units ID. | |
std::function< CompileUnit *(uint64_t)> | getUnitForOffset |
Additional Inherited Members | |
Protected Types inherited from llvm::dwarf_linker::parallel::OutputSections | |
using | SectionsSetTy = std::map< DebugSectionKind, std::shared_ptr< SectionDescriptor > > |
All keeping sections. | |
Protected Attributes inherited from llvm::dwarf_linker::parallel::OutputSections | |
LinkingGlobalData & | GlobalData |
dwarf::FormParams | Format = {4, 4, dwarf::DWARF32} |
Format for sections. | |
llvm::endianness | Endianness = llvm::endianness::native |
Endiannes for sections. | |
SectionsSetTy | SectionDescriptors |
Keeps track of data associated with one object during linking.
i.e. source file descriptor, compilation units, output data for compilation units common tables.
Definition at line 161 of file DWARFLinkerImpl.h.
using llvm::dwarf_linker::parallel::DWARFLinkerImpl::LinkContext::ModuleUnitListTy = SmallVector<RefModuleUnit> |
Definition at line 174 of file DWARFLinkerImpl.h.
using llvm::dwarf_linker::parallel::DWARFLinkerImpl::LinkContext::UnitListTy = SmallVector<std::unique_ptr<CompileUnit> > |
Definition at line 162 of file DWARFLinkerImpl.h.
DWARFLinkerImpl::LinkContext::LinkContext | ( | LinkingGlobalData & | GlobalData, |
DWARFFile & | File, | ||
StringMap< uint64_t > & | ClangModules, | ||
std::atomic< size_t > & | UniqueUnitID | ||
) |
Definition at line 30 of file DWARFLinkerImpl.cpp.
References llvm::dwarf::FormParams::AddrSize, llvm::big, CompileUnits, llvm::dwarf_linker::parallel::OutputSections::Endianness, llvm::dwarf_linker::parallel::OutputSections::Format, llvm::little, llvm::SmallVectorImpl< T >::reserve(), and llvm::dwarf::FormParams::Version.
void DWARFLinkerImpl::LinkContext::addModulesCompileUnit | ( | LinkContext::RefModuleUnit && | Unit | ) |
Add Compile Unit corresponding to the module.
Definition at line 57 of file DWARFLinkerImpl.cpp.
References llvm::SmallVectorImpl< T >::emplace_back(), and ModulesCompileUnits.
Error DWARFLinkerImpl::LinkContext::cloneAndEmitDebugFrame | ( | ) |
Clone and emit .debug_frame.
The CIEs that have been emitted in the output section. The actual CIE data serves a the key to this StringMap.
Definition at line 731 of file DWARFLinkerImpl.cpp.
References CompileUnits, llvm::createFileError(), llvm::createStringError(), llvm::DWARFSection::Data, llvm::Data, llvm::dwarf_linker::DebugFrame, llvm::dwarf_linker::DWARFFile::Dwarf, emitFDE(), llvm::StringRef::empty(), llvm::DWARFObject::getAddressSize(), llvm::DWARFObject::getFileName(), llvm::DWARFObject::getFrameSection(), llvm::dwarf_linker::parallel::OutputSections::getOrCreateSectionDescriptor(), llvm::AddressRangesBase< T >::getRangeThatContains(), llvm::dwarf_linker::parallel::LinkingGlobalData::getTargetTriple(), llvm::dwarf_linker::parallel::OutputSections::GlobalData, InputDWARFFile, llvm::AddressRangesMap::insert(), llvm::StringMap< ValueTy, AllocatorTy >::insert(), llvm::DWARFObject::isLittleEndian(), llvm::dwarf_linker::parallel::SectionDescriptor::OS, Range, llvm::StringRef::substr(), llvm::Error::success(), and llvm::raw_ostream::tell().
Referenced by link().
void DWARFLinkerImpl::LinkContext::emitFDE | ( | uint32_t | CIEOffset, |
uint32_t | AddrSize, | ||
uint64_t | Address, | ||
StringRef | FDEBytes, | ||
SectionDescriptor & | Section | ||
) |
Emit FDE record.
Emit a FDE into the debug_frame section.
FDEBytes
contains the FDE data without the length, CIE offset and address which will be replaced with the parameter values.
Definition at line 842 of file DWARFLinkerImpl.cpp.
References llvm::Address, llvm::StringRef::data(), and llvm::StringRef::size().
Referenced by cloneAndEmitDebugFrame().
Error DWARFLinkerImpl::LinkContext::emitInvariantSections | ( | ) |
Emit invariant sections.
Definition at line 709 of file DWARFLinkerImpl.cpp.
References llvm::dwarf_linker::DebugAddr, llvm::dwarf_linker::DebugARanges, llvm::dwarf_linker::DebugFrame, llvm::dwarf_linker::DebugLoc, llvm::dwarf_linker::DebugLocLists, llvm::dwarf_linker::DebugRange, llvm::dwarf_linker::DebugRngLists, llvm::dwarf_linker::DWARFFile::Dwarf, llvm::dwarf_linker::parallel::OutputSections::getOrCreateSectionDescriptor(), llvm::dwarf_linker::parallel::LinkingGlobalData::getTargetTriple(), llvm::dwarf_linker::parallel::OutputSections::GlobalData, InputDWARFFile, llvm::dwarf_linker::parallel::SectionDescriptor::OS, and llvm::Error::success().
Referenced by link().
|
inline |
Computes the total size of the debug info.
Definition at line 238 of file DWARFLinkerImpl.h.
References llvm::dwarf_linker::DWARFFile::Dwarf, InputDWARFFile, and Size.
Referenced by link().
std::pair< bool, bool > DWARFLinkerImpl::LinkContext::isClangModuleRef | ( | const DWARFDie & | CUDie, |
std::string & | PCMFile, | ||
unsigned | Indent, | ||
bool | Quiet | ||
) |
Check whether specified CUDie
is a Clang module reference.
if Quiet
is false then display error messages.
Definition at line 297 of file DWARFLinkerImpl.cpp.
References ClangModules, llvm::StringMap< ValueTy, AllocatorTy >::end(), llvm::dwarf_linker::DWARFFile::FileName, llvm::DWARFDie::find(), llvm::StringMap< ValueTy, AllocatorTy >::find(), llvm::getDwoId(), llvm::dwarf_linker::parallel::LinkingGlobalData::getOptions(), llvm::dwarf_linker::parallel::OutputSections::GlobalData, llvm::raw_ostream::indent(), InputDWARFFile, Name, llvm::outs(), llvm::Quiet, llvm::dwarf::toString(), llvm::dwarf_linker::parallel::DWARFLinkerOptions::Verbose, and llvm::dwarf_linker::parallel::LinkingGlobalData::warn().
Referenced by link(), and registerModuleReference().
Link compile units for this context.
Definition at line 447 of file DWARFLinkerImpl.cpp.
References llvm::dwarf_linker::DWARFFile::Addresses, llvm::dwarf_linker::parallel::DWARFLinkerImpl::ArtificialTypeUnit, llvm::SmallVectorTemplateCommon< T, typename >::back(), llvm::dwarf_linker::parallel::CompileUnit::Cleaned, cloneAndEmitDebugFrame(), llvm::dwarf_linker::parallel::CompileUnit::Cloned, CompileUnits, llvm::dwarf_linker::DWARFFile::Dwarf, emitInvariantSections(), llvm::SmallVectorImpl< T >::emplace_back(), llvm::SmallVectorBase< Size_T >::empty(), llvm::dwarf_linker::finiteLoop(), llvm::dwarf_linker::parallel::OutputSections::getEndianness(), getInputDebugInfoSize(), llvm::dwarf_linker::parallel::LinkingGlobalData::getOptions(), llvm::getPCMFile(), getUnitForOffset, llvm::dwarf_linker::parallel::OutputSections::GlobalData, HasNewGlobalDependency, HasNewInterconnectedCUs, InputDWARFFile, InterCUProcessingStarted, isClangModuleRef(), linkSingleCompileUnit(), llvm::dwarf_linker::parallel::CompileUnit::LivenessAnalysisDone, ModulesCompileUnits, llvm::dwarf_linker::parallel::DWARFLinkerOptions::ObjectPrefixMap, OriginalDebugInfoSize, llvm::outs(), llvm::parallelForEach(), llvm::dwarf_linker::parallel::CompileUnit::PatchesUpdated, llvm::parallel::TaskGroup::spawn(), llvm::Error::success(), llvm::dwarf_linker::parallel::CompileUnit::TypeNamesAssigned, UniqueUnitID, llvm::dwarf_linker::parallel::DWARFLinkerImpl::LinkContext::RefModuleUnit::Unit, llvm::dwarf_linker::parallel::CompileUnit::UpdateDependenciesCompleteness, llvm::dwarf_linker::parallel::DWARFLinkerOptions::UpdateIndexTablesOnly, and llvm::dwarf_linker::parallel::DWARFLinkerOptions::Verbose.
void DWARFLinkerImpl::LinkContext::linkSingleCompileUnit | ( | CompileUnit & | CU, |
TypeUnit * | ArtificialTypeUnit, | ||
enum CompileUnit::Stage | DoUntilStage = CompileUnit::Stage::Cleaned |
||
) |
Link specified compile unit until specified stage.
Definition at line 591 of file DWARFLinkerImpl.cpp.
References llvm::dwarf_linker::parallel::DWARFLinkerImpl::ArtificialTypeUnit, assert(), llvm::dwarf_linker::parallel::CompileUnit::Cleaned, llvm::dwarf_linker::parallel::CompileUnit::Cloned, llvm::dwarf_linker::finiteLoop(), llvm::dwarf_linker::parallel::LinkingGlobalData::getOptions(), llvm::dwarf_linker::parallel::OutputSections::GlobalData, HasNewGlobalDependency, InterCUProcessingStarted, llvm::dwarf_linker::parallel::CompileUnit::LivenessAnalysisDone, llvm::dwarf_linker::parallel::CompileUnit::Loaded, llvm::dwarf_linker::parallel::CompileUnit::PatchesUpdated, llvm::dwarf_linker::parallel::CompileUnit::Skipped, llvm::dwarf_linker::parallel::CompileUnit::TypeNamesAssigned, llvm::dwarf_linker::parallel::CompileUnit::UpdateDependenciesCompleteness, and llvm::dwarf_linker::parallel::DWARFLinkerOptions::UpdateIndexTablesOnly.
Referenced by link().
Error DWARFLinkerImpl::LinkContext::loadClangModule | ( | ObjFileLoaderTy | Loader, |
const DWARFDie & | CUDie, | ||
const std::string & | PCMFile, | ||
CompileUnitHandlerTy | OnCUDieLoaded, | ||
unsigned | Indent = 0 |
||
) |
Recursively add the debug info in this clang module .pcm file (and all the modules imported by it in a bottom-up fashion) to ModuleUnits.
Using a SmallString<0> because loadClangModule() is recursive.
Definition at line 372 of file DWARFLinkerImpl.cpp.
References llvm::sys::path::append(), llvm::SmallVectorTemplateCommon< T, typename >::back(), ClangModules, llvm::SmallVectorImpl< T >::emplace_back(), llvm::dwarf_linker::parallel::LinkingGlobalData::error(), llvm::dwarf_linker::DWARFFile::FileName, llvm::DWARFDie::find(), llvm::getDwoId(), llvm::dwarf_linker::parallel::OutputSections::getEndianness(), llvm::dwarf_linker::parallel::LinkingGlobalData::getOptions(), getUnitForOffset, llvm::dwarf_linker::parallel::OutputSections::GlobalData, llvm::inconvertibleErrorCode(), InputDWARFFile, llvm::sys::path::is_relative(), ModulesCompileUnits, llvm::dwarf_linker::parallel::DWARFLinkerOptions::PrependPath, registerModuleReference(), llvm::resolveRelativeObjectPath(), llvm::Error::success(), llvm::dwarf::toString(), UniqueUnitID, llvm::dwarf_linker::parallel::DWARFLinkerOptions::Verbose, and llvm::dwarf_linker::parallel::LinkingGlobalData::warn().
Referenced by registerModuleReference().
bool DWARFLinkerImpl::LinkContext::registerModuleReference | ( | const DWARFDie & | CUDie, |
ObjFileLoaderTy | Loader, | ||
CompileUnitHandlerTy | OnCUDieLoaded, | ||
unsigned | Indent = 0 |
||
) |
If this compile unit is really a skeleton CU that points to a clang module, register it in ClangModules and return true.
A skeleton CU is a CU without children, a DW_AT_gnu_dwo_name pointing to the module, and a DW_AT_gnu_dwo_id with the module hash.
Definition at line 343 of file DWARFLinkerImpl.cpp.
References ClangModules, llvm::consumeError(), llvm::getDwoId(), llvm::dwarf_linker::parallel::LinkingGlobalData::getOptions(), llvm::getPCMFile(), llvm::dwarf_linker::parallel::OutputSections::GlobalData, llvm::StringMap< ValueTy, AllocatorTy >::insert(), isClangModuleRef(), loadClangModule(), llvm::dwarf_linker::parallel::DWARFLinkerOptions::ObjectPrefixMap, llvm::outs(), and llvm::dwarf_linker::parallel::DWARFLinkerOptions::Verbose.
Referenced by loadClangModule().
Definition at line 192 of file DWARFLinkerImpl.h.
Referenced by llvm::dwarf_linker::parallel::DWARFLinkerImpl::addObjectFile(), isClangModuleRef(), loadClangModule(), and registerModuleReference().
UnitListTy llvm::dwarf_linker::parallel::DWARFLinkerImpl::LinkContext::CompileUnits |
Set of Compilation Units(may be accessed asynchroniously for reading).
Definition at line 180 of file DWARFLinkerImpl.h.
Referenced by cloneAndEmitDebugFrame(), link(), and LinkContext().
std::function<CompileUnit *(uint64_t)> llvm::dwarf_linker::parallel::DWARFLinkerImpl::LinkContext::getUnitForOffset |
Definition at line 268 of file DWARFLinkerImpl.h.
Referenced by link(), and loadClangModule().
std::atomic<bool> llvm::dwarf_linker::parallel::DWARFLinkerImpl::LinkContext::HasNewGlobalDependency = {false} |
Definition at line 199 of file DWARFLinkerImpl.h.
Referenced by link(), and linkSingleCompileUnit().
std::atomic<bool> llvm::dwarf_linker::parallel::DWARFLinkerImpl::LinkContext::HasNewInterconnectedCUs = {false} |
Flag indicating that new inter-connected compilation units were discovered.
It is used for restarting units processing if new inter-connected units were found.
Definition at line 197 of file DWARFLinkerImpl.h.
Referenced by link().
DWARFFile& llvm::dwarf_linker::parallel::DWARFLinkerImpl::LinkContext::InputDWARFFile |
Object file descriptor.
Definition at line 177 of file DWARFLinkerImpl.h.
Referenced by cloneAndEmitDebugFrame(), emitInvariantSections(), getInputDebugInfoSize(), isClangModuleRef(), link(), and loadClangModule().
bool llvm::dwarf_linker::parallel::DWARFLinkerImpl::LinkContext::InterCUProcessingStarted = false |
Flag indicating that all inter-connected units are loaded and the dwarf linking process for these units is started.
Definition at line 190 of file DWARFLinkerImpl.h.
Referenced by link(), and linkSingleCompileUnit().
ModuleUnitListTy llvm::dwarf_linker::parallel::DWARFLinkerImpl::LinkContext::ModulesCompileUnits |
Set of Compile Units for modules.
Definition at line 183 of file DWARFLinkerImpl.h.
Referenced by addModulesCompileUnit(), link(), and loadClangModule().
uint64_t llvm::dwarf_linker::parallel::DWARFLinkerImpl::LinkContext::OriginalDebugInfoSize = 0 |
Size of Debug info before optimizing.
Definition at line 186 of file DWARFLinkerImpl.h.
Referenced by link().
std::atomic<size_t>& llvm::dwarf_linker::parallel::DWARFLinkerImpl::LinkContext::UniqueUnitID |
Counter for compile units ID.
Definition at line 202 of file DWARFLinkerImpl.h.
Referenced by llvm::dwarf_linker::parallel::DWARFLinkerImpl::addObjectFile(), llvm::dwarf_linker::parallel::DWARFLinkerImpl::link(), link(), and loadClangModule().