14using namespace dwarf_linker;
15using namespace dwarf_linker::parallel;
20 :
DwarfUnit(GlobalData,
ID,
""), Language(Language),
21 AcceleratorRecords(&GlobalData.getAllocator()) {
42 prepareDataForTreeCreation();
57 DIE *UnitDIE = DIETreeGenerator.
createDIE(dwarf::DW_TAG_compile_unit, 0);
62 ProducerString +=
"llvm DWARFLinkerParallel library version ";
68 OutOffset += DIETreeGenerator
74 OutOffset += DIETreeGenerator
76 dwarf::DW_FORM_data2, *Language)
84 OutOffset += DIETreeGenerator
93 OutOffset += DIETreeGenerator
95 dwarf::DW_FORM_sec_offset, 0xbaddef)
102 OutOffset += DIETreeGenerator
111 OutOffset += DIETreeGenerator
113 dwarf::DW_FORM_sec_offset,
123 for (
uint64_t *OffsetPtr : PatchesOffsets)
130void TypeUnit::prepareDataForTreeCreation() {
149 std::function<bool(const DebugTypeDeclFilePatch &LHS,
150 const DebugTypeDeclFilePatch &RHS)>
151 PatchesComparator = [&](const DebugTypeDeclFilePatch &LHS,
152 const DebugTypeDeclFilePatch &RHS) {
153 return LHS.Directory->first() < RHS.Directory->first() ||
154 (!(RHS.Directory->first() < LHS.Directory->first()) &&
155 LHS.FilePath->first() < RHS.FilePath->first());
158 DebugInfoSection.ListDebugTypeDeclFilePatch.sort(PatchesComparator);
163 getScalarFormForValue(
164 DebugInfoSection.ListDebugTypeDeclFilePatch.size())
167 DebugInfoSection.ListDebugTypeDeclFilePatch.forEach(
185 .addScalarAttribute(dwarf::DW_AT_decl_file,
186 DeclFileForm, FileIdx)
192 if (!GlobalData.getOptions().AllowNonDeterministicOutput) {
197 StrPatchesComparator =
199 return LHS.String->getKey() <
RHS.String->getKey();
201 OutSection.ListDebugStrPatch.sort(StrPatchesComparator);
207 return LHS.String->getKey() <
RHS.String->getKey();
209 OutSection.ListDebugTypeStrPatch.sort(TypeStrPatchesComparator);
214 if (!GlobalData.getOptions().AllowNonDeterministicOutput) {
222 return LHS.String->getKey() <
RHS.String->getKey();
224 OutSection.ListDebugLineStrPatch.sort(LineStrPatchesComparator);
228 TypeLineStrPatchesComparator =
231 return LHS.String->getKey() <
RHS.String->getKey();
233 OutSection.ListDebugTypeLineStrPatch.sort(TypeLineStrPatchesComparator);
241 bool HasChildren = !
Entry->getValue().load()->Children.empty();
243 OutOffset += DIEGen.finalizeAbbreviations(HasChildren,
nullptr);
244 OutOffset += OutDIE->
getSize() - 1;
247 Entry->getValue().load()->Children.forEach([&](
TypeEntry *ChildEntry) {
249 DIEGen.addChild(ChildDIE);
253 OutOffset = finalizeTypeEntryRec(OutOffset, ChildDIE, ChildEntry);
257 OutOffset +=
sizeof(int8_t);
268 if (Dir->
first() ==
"") {
271 DirectoriesMapTy::iterator DirEntry = DirectoriesMap.find(Dir);
272 if (DirEntry == DirectoriesMap.end()) {
276 DirectoriesMap.insert({Dir, DirIdx});
281 DirIdx = DirEntry->second;
288 auto [FileEntry,
Inserted] = FileNamesMap.try_emplace(
295 dwarf::DW_FORM_string, FileName->
getKeyData());
299 uint32_t FileIdx = FileEntry->second;
300 return getVersion() < 5 ? FileIdx + 1 : FileIdx;
303std::pair<dwarf::Form, uint8_t>
305 if (
Value > 0xFFFFFFFF)
306 return std::make_pair(dwarf::DW_FORM_data8, 8);
309 return std::make_pair(dwarf::DW_FORM_data4, 4);
312 return std::make_pair(dwarf::DW_FORM_data2, 2);
314 return std::make_pair(dwarf::DW_FORM_data1, 1);
318 if (Form == dwarf::DW_FORM_data1)
321 if (Form == dwarf::DW_FORM_data2)
324 if (Form == dwarf::DW_FORM_data4)
327 if (Form == dwarf::DW_FORM_data8)
330 if (Form == dwarf::DW_FORM_data16)
369 Tasks.push_back([&]() ->
Error {
382 Tasks, [&](std::function<
Error(
void)>
F) {
return F(); }))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU Mark last scratch load
Allocate memory in an ever growing pool, as if by bump-pointer.
A structured debug information entry.
unsigned getAbbrevNumber() const
unsigned getOffset() const
Get the compile/type unit relative offset of this DIE.
void setOffset(unsigned O)
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef str() const
Explicit conversion to StringRef.
const ValueTy & getValue() const
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
const char * getKeyData() const
getKeyData - Return the start of the string data that is the key for this value.
Triple - Helper class for working with autoconf configuration names.
LLVM Value Representation.
@ Pub
.debug_pubnames, .debug_pubtypes
This class is a helper to create output DIE tree.
std::pair< DIEValue &, size_t > addStringPlaceholderAttribute(dwarf::Attribute Attr, dwarf::Form AttrForm)
Adds string attribute with dummy offset to the current DIE.
DIE * createDIE(dwarf::Tag DieTag, uint32_t OutOffset)
Creates a DIE of specified tag DieTag and OutOffset.
std::pair< DIEValue &, size_t > addScalarAttribute(dwarf::Attribute Attr, dwarf::Form AttrForm, uint64_t Value)
Adds specified scalar attribute to the current DIE.
Base class for all Dwarf units(Compile unit/Type table unit).
std::string UnitName
The name of this unit.
IndexedValuesMap< const StringEntry * > DebugStringIndexMap
Maps a string into the index inside .debug_str_offsets section.
StringRef getUnitName() const
Returns this unit name.
void setOutUnitDIE(DIE *UnitDie)
Set output unit DIE.
DIE * getOutUnitDIE()
Returns output unit DIE.
This class keeps data and services common for the whole linking process.
const DWARFLinkerOptions & getOptions() const
Returns linking options.
StringPool & getStringPool()
Returns global string pool.
uint16_t getDebugStrOffsetsHeaderSize() const
Return size of header of debug_str_offsets table.
LinkingGlobalData & GlobalData
dwarf::FormParams Format
Format for sections.
const dwarf::FormParams & getFormParams() const
Return size of address.
void setOutputFormat(dwarf::FormParams Format, llvm::endianness Endianness)
Sets output format for all keeping sections.
uint16_t getVersion() const
Return DWARF version.
uint16_t getDebugInfoHeaderSize() const
Return size of header of debug_info table.
SectionDescriptor & getOrCreateSectionDescriptor(DebugSectionKind SectionKind)
Returns descriptor for the specified section of SectionKind.
Keeps cloned data for the type DIE.
BumpPtrAllocator & getThreadLocalAllocator()
Return thread local allocator used by pool.
TypeEntry * getRoot() const
Return root for all type entries.
void sortTypes()
Sort children for each kept type entry.
Error finishCloningAndEmit(const Triple &TargetTriple)
Emits resulting dwarf based on information from DIE tree.
void createDIETree(BumpPtrAllocator &Allocator)
Generates DIE tree based on information from TypesMap.
TypeUnit(LinkingGlobalData &GlobalData, unsigned ID, std::optional< uint16_t > Language, dwarf::FormParams Format, llvm::endianness Endianess)
LLVM_ABI void spawn(std::function< void()> f)
Error emitDebugInfo(const Triple &TargetTriple)
Emit .debug_info section for unit DIEs.
Error emitDebugStringOffsetSection()
Emit the .debug_str_offsets section for current unit.
void emitPubAccelerators()
Emit .debug_pubnames and .debug_pubtypes for Unit.
Error emitAbbreviations()
Error emitDebugLine(const Triple &TargetTriple, const DWARFDebugLine::LineTable &OutLineTable)
Emit .debug_line section.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
LLVM_ABI unsigned getULEB128Size(uint64_t Value)
Utility function to get the size of the ULEB128-encoded value.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Error parallelForEachError(RangeTy &&R, FuncTy Fn)
uint8_t MaxOpsPerInst
The maximum number of individual operations that may be encoded in an instruction.
uint8_t MinInstLength
The size in bytes of the smallest target machine instruction.
int8_t LineBase
This parameter affects the meaning of the special opcodes. See below.
uint8_t LineRange
This parameter affects the meaning of the special opcodes. See below.
std::vector< DWARFFormValue > IncludeDirectories
uint8_t OpcodeBase
The number assigned to the first special opcode.
std::vector< uint8_t > StandardOpcodeLengths
uint8_t DefaultIsStmt
The initial value of theis_stmtregister.
dwarf::FormParams FormParams
Version, address size (starting in v5), and DWARF32/64 format; these parameters affect interpretation...
std::vector< FileNameEntry > FileNames
SmallVector< DWARFLinkerBase::AccelTableKind, 1 > AccelTables
The accelerator table kinds.
bool AllowNonDeterministicOutput
Allow to generate valid, but non deterministic output.
This structure is used to update strings offsets into .debug_line_str.
This structure is used to update strings offsets into .debug_str.
This structure is used to keep data of the concrete section.
void notePatchWithOffsetUpdate(const T &Patch, OffsetsPtrVector &PatchesOffsetsList)
While creating patches, offsets to attributes may be partially unknown(because size of abbreviation n...