21 AcceleratorRecords(&
GlobalData.getAllocator()) {
29 LineTable.Prologue.MinInstLength = 1;
30 LineTable.Prologue.MaxOpsPerInst = 1;
31 LineTable.Prologue.DefaultIsStmt = 1;
32 LineTable.Prologue.LineBase = -5;
33 LineTable.Prologue.LineRange = 14;
34 LineTable.Prologue.OpcodeBase = 13;
35 LineTable.Prologue.StandardOpcodeLengths = {0, 1, 1, 1, 1, 0,
42 prepareDataForTreeCreation();
57 DIE *UnitDIE = DIETreeGenerator.
createDIE(dwarf::DW_TAG_compile_unit, 0);
62 ProducerString +=
"llvm DWARFLinkerParallel library version ";
66 GlobalData.getStringPool().insert(ProducerString.
str()).first},
68 OutOffset += DIETreeGenerator
74 OutOffset += DIETreeGenerator
76 dwarf::DW_FORM_data2, *Language)
84 OutOffset += DIETreeGenerator
89 if (!LineTable.Prologue.FileNames.empty()) {
93 OutOffset += DIETreeGenerator
95 dwarf::DW_FORM_sec_offset, 0xbaddef)
102 OutOffset += DIETreeGenerator
111 OutOffset += DIETreeGenerator
113 dwarf::DW_FORM_sec_offset,
120 finalizeTypeEntryRec(UnitDIE->
getOffset(), UnitDIE, Types.getRoot());
123 for (
uint64_t *OffsetPtr : PatchesOffsets)
130void TypeUnit::prepareDataForTreeCreation() {
150 return LHS.Directory->first() < RHS.Directory->first() ||
151 (!(RHS.Directory->first() < LHS.Directory->first()) &&
152 LHS.FilePath->first() < RHS.FilePath->first());
154 DebugInfoSection.ListDebugTypeDeclFilePatch.sort(PatchesComparator);
158 getScalarFormForValue(
159 DebugInfoSection.ListDebugTypeDeclFilePatch.size())
162 DebugInfoSection.ListDebugTypeDeclFilePatch.forEach(
180 .addScalarAttribute(dwarf::DW_AT_decl_file,
181 DeclFileForm, FileIdx)
189 forEach([&](SectionDescriptor &OutSection) {
190 std::function<bool(
const DebugStrPatch &
LHS,
const DebugStrPatch &
RHS)>
191 StrPatchesComparator =
192 [&](
const DebugStrPatch &
LHS,
const DebugStrPatch &
RHS) {
193 return LHS.String->getKey() <
RHS.String->getKey();
195 OutSection.ListDebugStrPatch.sort(StrPatchesComparator);
197 std::function<bool(
const DebugTypeStrPatch &
LHS,
198 const DebugTypeStrPatch &
RHS)>
199 TypeStrPatchesComparator =
200 [&](
const DebugTypeStrPatch &
LHS,
const DebugTypeStrPatch &
RHS) {
201 return LHS.String->getKey() <
RHS.String->getKey();
203 OutSection.ListDebugTypeStrPatch.sort(TypeStrPatchesComparator);
209 forEach([&](SectionDescriptor &OutSection) {
210 std::function<bool(
const DebugLineStrPatch &
LHS,
211 const DebugLineStrPatch &
RHS)>
212 LineStrPatchesComparator =
213 [&](
const DebugLineStrPatch &
LHS,
const DebugLineStrPatch &
RHS) {
214 return LHS.String->getKey() <
RHS.String->getKey();
216 OutSection.ListDebugLineStrPatch.sort(LineStrPatchesComparator);
218 std::function<bool(
const DebugTypeLineStrPatch &
LHS,
219 const DebugTypeLineStrPatch &
RHS)>
220 TypeLineStrPatchesComparator = [&](
const DebugTypeLineStrPatch &
LHS,
221 const DebugTypeLineStrPatch &
RHS) {
222 return LHS.String->getKey() <
RHS.String->getKey();
224 OutSection.ListDebugTypeLineStrPatch.sort(TypeLineStrPatchesComparator);
229uint64_t TypeUnit::finalizeTypeEntryRec(uint64_t OutOffset, DIE *OutDIE,
231 bool HasChildren = !
Entry->getValue().load()->Children.empty();
232 DIEGenerator DIEGen(OutDIE, Types.getThreadLocalAllocator(), *
this);
233 OutOffset += DIEGen.finalizeAbbreviations(HasChildren,
nullptr);
234 OutOffset += OutDIE->
getSize() - 1;
237 Entry->getValue().load()->Children.forEach([&](
TypeEntry *ChildEntry) {
238 DIE *ChildDIE = &ChildEntry->
getValue().load()->getFinalDie();
239 DIEGen.addChild(ChildDIE);
243 OutOffset = finalizeTypeEntryRec(OutOffset, ChildDIE, ChildEntry);
247 OutOffset +=
sizeof(int8_t);
254uint32_t TypeUnit::addFileNameIntoLinetable(
StringEntry *Dir,
258 if (Dir->
first() ==
"") {
261 DirectoriesMapTy::iterator DirEntry = DirectoriesMap.find(Dir);
262 if (DirEntry == DirectoriesMap.end()) {
264 assert(LineTable.Prologue.IncludeDirectories.size() < UINT32_MAX);
265 DirIdx = LineTable.Prologue.IncludeDirectories.size();
266 DirectoriesMap.insert({Dir, DirIdx});
267 LineTable.Prologue.IncludeDirectories.push_back(
271 DirIdx = DirEntry->second;
278 auto [FileEntry,
Inserted] = FileNamesMap.try_emplace(
279 {FileName, DirIdx}, LineTable.Prologue.FileNames.size());
282 assert(LineTable.Prologue.FileNames.size() < UINT32_MAX);
283 LineTable.Prologue.FileNames.push_back(DWARFDebugLine::FileNameEntry());
285 dwarf::DW_FORM_string, FileName->
getKeyData());
286 LineTable.Prologue.FileNames.back().DirIdx = DirIdx;
289 uint32_t FileIdx = FileEntry->second;
290 return getVersion() < 5 ? FileIdx + 1 : FileIdx;
293std::pair<dwarf::Form, uint8_t>
294TypeUnit::getScalarFormForValue(uint64_t
Value)
const {
295 if (
Value > 0xFFFFFFFF)
296 return std::make_pair(dwarf::DW_FORM_data8, 8);
299 return std::make_pair(dwarf::DW_FORM_data4, 4);
302 return std::make_pair(dwarf::DW_FORM_data2, 2);
304 return std::make_pair(dwarf::DW_FORM_data1, 1);
307uint8_t TypeUnit::getSizeByAttrForm(
dwarf::Form Form)
const {
308 if (Form == dwarf::DW_FORM_data1)
311 if (Form == dwarf::DW_FORM_data2)
314 if (Form == dwarf::DW_FORM_data4)
317 if (Form == dwarf::DW_FORM_data8)
320 if (Form == dwarf::DW_FORM_data16)
348 if (!LineTable.Prologue.FileNames.empty()) {
359 Tasks.push_back([&]() ->
Error {
372 Tasks, [&](std::function<
Error(
void)>
F) {
return F(); }))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
const ValueTy & getValue() const
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.
@ 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.
std::string UnitName
The name of this unit.
IndexedValuesMap< const StringEntry * > DebugStringIndexMap
Maps a string into the index inside .debug_str_offsets section.
unsigned ID
Unique ID for the unit.
StringRef getUnitName() const
Returns this unit name.
void setOutUnitDIE(DIE *UnitDie)
Set output unit DIE.
DwarfUnit(LinkingGlobalData &GlobalData, unsigned ID, StringRef ClangModuleName)
DIE * getOutUnitDIE()
Returns output unit DIE.
This class keeps data and services common for the whole linking process.
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.
void forEach(function_ref< void(SectionDescriptor &)> Handler)
Enumerate all sections and call Handler for each.
SectionDescriptor & getOrCreateSectionDescriptor(DebugSectionKind SectionKind)
Returns descriptor for the specified section of SectionKind.
Keeps cloned data for the type DIE.
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.
SmallVector< uint64_t * > OffsetsPtrVector
Type for list of pointers to patches offsets.
StringMapEntry< std::atomic< TypeEntryBody * > > TypeEntry
StringMapEntry< EmptyStringSetTag > StringEntry
StringEntry keeps data of the string: the length, external offset and a string body which is placed r...
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
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.
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Error parallelForEachError(RangeTy &&R, FuncTy Fn)
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...