LLVM 20.0.0git
Classes | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
llvm::dwarf_linker::parallel::DWARFLinkerImpl Class Reference

This class links debug info. More...

#include "DWARFLinker/Parallel/DWARFLinkerImpl.h"

Inheritance diagram for llvm::dwarf_linker::parallel::DWARFLinkerImpl:
Inheritance graph
[legend]

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_tClangModules
 Mapping the PCM filename to the DwoId.
 
std::mutex ClangModulesMutex
 
std::unique_ptr< TypeUnitArtificialTypeUnit
 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< DWARFLinkercreateLinker (MessageHandlerTy ErrorHandler, MessageHandlerTy WarningHandler)
 Creates dwarf linker instance.
 

Detailed Description

This class links debug info.

Definition at line 26 of file DWARFLinkerImpl.h.

Member Enumeration Documentation

◆ StringDestinationKind

Enumerator
DebugStr 
DebugLineStr 

Definition at line 293 of file DWARFLinkerImpl.h.

Constructor & Destructor Documentation

◆ DWARFLinkerImpl()

DWARFLinkerImpl::DWARFLinkerImpl ( MessageHandlerTy  ErrorHandler,
MessageHandlerTy  WarningHandler 
)

Member Function Documentation

◆ addObjectFile()

void DWARFLinkerImpl::addObjectFile ( DWARFFile File,
ObjFileLoaderTy  Loader = nullptr,
CompileUnitHandlerTy  OnCUDieLoaded = [](const DWARFUnit &) {} 
)
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.

Precondition
NoODR, Update options should be set before call to addObjectFile.

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.

◆ assignOffsets()

void DWARFLinkerImpl::assignOffsets ( )
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().

◆ assignOffsetsToSections()

void DWARFLinkerImpl::assignOffsetsToSections ( )
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().

◆ assignOffsetsToStrings()

void DWARFLinkerImpl::assignOffsetsToStrings ( )
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().

◆ cleanupDataAfterDWARFOutputIsWritten()

void DWARFLinkerImpl::cleanupDataAfterDWARFOutputIsWritten ( )
protected

◆ emitAppleAcceleratorSections()

void DWARFLinkerImpl::emitAppleAcceleratorSections ( const Triple TargetTriple)
protected

◆ emitCommonSectionsAndWriteCompileUnitsToTheOutput()

void DWARFLinkerImpl::emitCommonSectionsAndWriteCompileUnitsToTheOutput ( )
protected

◆ emitDWARFv5DebugNamesSection()

void DWARFLinkerImpl::emitDWARFv5DebugNamesSection ( const Triple TargetTriple)
protected

◆ emitStringSections()

void DWARFLinkerImpl::emitStringSections ( )
protected

◆ forEachCompileAndTypeUnit()

void DWARFLinkerImpl::forEachCompileAndTypeUnit ( function_ref< void(DwarfUnit *CU)>  UnitHandler)
protected

◆ forEachCompileUnit()

void DWARFLinkerImpl::forEachCompileUnit ( function_ref< void(CompileUnit *CU)>  UnitHandler)
protected

◆ forEachObjectSectionsSet()

void DWARFLinkerImpl::forEachObjectSectionsSet ( function_ref< void(OutputSections &SectionsSet)>  SectionsSetHandler)
protected

◆ forEachOutputString()

void DWARFLinkerImpl::forEachOutputString ( function_ref< void(StringDestinationKind, const StringEntry *)>  StringHandler)
protected

◆ glueCompileUnitsAndWriteToTheOutput()

void DWARFLinkerImpl::glueCompileUnitsAndWriteToTheOutput ( )
protected

◆ link()

Error DWARFLinkerImpl::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().

◆ patchOffsetsAndSizes()

void DWARFLinkerImpl::patchOffsetsAndSizes ( )
protected

◆ printStatistic()

void DWARFLinkerImpl::printStatistic ( )
protected

◆ setOutputDWARFHandler()

void llvm::dwarf_linker::parallel::DWARFLinkerImpl::setOutputDWARFHandler ( const Triple TargetTriple,
SectionHandlerTy  SectionHandler 
)
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().

◆ validateAndUpdateOptions()

Error DWARFLinkerImpl::validateAndUpdateOptions ( )
protected

◆ verifyInput()

void DWARFLinkerImpl::verifyInput ( const DWARFFile File)
protected

◆ writeCommonSectionsToTheOutput()

void DWARFLinkerImpl::writeCommonSectionsToTheOutput ( )
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().

◆ writeCompileUnitsToTheOutput()

void DWARFLinkerImpl::writeCompileUnitsToTheOutput ( )
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().

Friends And Related Function Documentation

◆ DependencyTracker

friend class DependencyTracker
friend

Definition at line 157 of file DWARFLinkerImpl.h.


The documentation for this class was generated from the following files: