LLVM 18.0.0git
DWARFLinkerCompileUnit.h
Go to the documentation of this file.
1//===- DWARFLinkerCompileUnit.h ---------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERCOMPILEUNIT_H
10#define LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERCOMPILEUNIT_H
11
12#include "DWARFLinkerUnit.h"
13#include "IndexedValuesMap.h"
15#include <optional>
16
17namespace llvm {
18namespace dwarflinker_parallel {
19
21
22struct AttributesInfo;
23
25 Resolve = true,
27};
28
29/// Stores all information related to a compile unit, be it in its original
30/// instance of the object file or its brand new cloned and generated DIE tree.
31class CompileUnit : public DwarfUnit {
32public:
33 /// The stages of new compile unit processing.
34 enum class Stage : uint8_t {
35 /// Created, linked with input DWARF file.
37
38 /// Input DWARF is loaded.
39 Loaded,
40
41 /// Input DWARF is analysed(DIEs pointing to the real code section are
42 /// discovered, type names are assigned if ODR is requested).
44
45 /// Output DWARF is generated.
46 Cloned,
47
48 /// Offsets inside patch records are updated.
50
51 /// Resources(Input DWARF, Output DWARF tree) are released.
52 Cleaned,
53 };
54
58 support::endianness Endianess)
59 : DwarfUnit(GlobalData, ID, ClangModuleName), File(File),
60 getUnitFromOffset(UnitFromOffset), Stage(Stage::CreatedNotLoaded) {
61 UnitName = File.FileName;
62 setOutputFormat(Format, Endianess);
63 }
64
68 support::endianness Endianess)
69 : DwarfUnit(GlobalData, ID, ClangModuleName), File(File),
70 OrigUnit(&OrigUnit), getUnitFromOffset(UnitFromOffset),
72 DWARFDie CUDie = OrigUnit.getUnitDIE();
73 if (!CUDie)
74 return;
75
76 setOutputFormat(Format, Endianess);
77
78 Language = dwarf::toUnsigned(CUDie.find(dwarf::DW_AT_language), 0);
79 if (const char *CUName = CUDie.getName(DINameKind::ShortName))
80 UnitName = CUName;
81 else
82 UnitName = File.FileName;
83 SysRoot = dwarf::toStringRef(CUDie.find(dwarf::DW_AT_LLVM_sysroot)).str();
84 }
85
86 /// Returns stage of overall processing.
87 Stage getStage() const { return Stage; }
88
89 /// Set stage of overall processing.
90 void setStage(Stage Stage) { this->Stage = Stage; }
91
92 /// Loads unit line table.
93 void loadLineTable();
94
95 /// Returns name of the file for the \p FileIdx
96 /// from the unit`s line table.
97 StringEntry *getFileName(unsigned FileIdx, StringPool &GlobalStrings);
98
99 /// Returns DWARFFile containing this compile unit.
100 const DWARFFile &getContaingFile() const { return File; }
101
102 /// Load DIEs of input compilation unit. \returns true if input DIEs
103 /// successfully loaded.
104 bool loadInputDIEs();
105
106 /// Reset compile units data(results of liveness analysis, clonning)
107 /// if current stage greater than Stage::Loaded. We need to reset data
108 /// as we are going to repeat stages.
110
111 /// Collect references to parseable Swift interfaces in imported
112 /// DW_TAG_module blocks.
113 void analyzeImportedModule(const DWARFDebugInfoEntry *DieEntry);
114
115 /// Navigate DWARF tree and set die properties.
117 analyzeDWARFStructureRec(getUnitDIE().getDebugInfoEntry(), false, false);
118 }
119
120 /// Cleanup unneeded resources after compile unit is cloned.
122
123 /// After cloning stage the output DIEs offsets are deallocated.
124 /// This method copies output offsets for referenced DIEs into DIEs patches.
126
127 /// Kinds of placement for the output die.
128 enum DieOutputPlacement : uint8_t {
130
131 /// Corresponding DIE goes to the type table only.
132 /// NOTE: Not used yet.
134
135 /// Corresponding DIE goes to the plain dwarf only.
137
138 /// Corresponding DIE goes to type table and to plain dwarf.
139 /// NOTE: Not used yet.
140 Both = 3,
141
142 /// Corresponding DIE needs to examine parent to determine
143 /// the point of placement.
144 /// NOTE: Not used yet.
145 Parent = 4
146 };
147
148 /// Information gathered about source DIEs.
149 struct DIEInfo {
150 DIEInfo() = default;
151 DIEInfo(const DIEInfo &Other) { Flags = Other.Flags.load(); }
153 Flags = Other.Flags.load();
154 return *this;
155 }
156
157 /// Data member keeping various flags.
158 std::atomic<uint16_t> Flags = {0};
159
160 /// \returns Placement kind for the corresponding die.
162 return DieOutputPlacement(Flags & 0x7);
163 }
164
165 /// Sets Placement kind for the corresponding die.
167 auto InputData = Flags.load();
168 while (!Flags.compare_exchange_weak(InputData,
169 ((InputData & ~0x7) | Placement))) {
170 }
171 }
172
173 /// Unsets Placement kind for the corresponding die.
175 auto InputData = Flags.load();
176 while (!Flags.compare_exchange_weak(InputData, (InputData & ~0x7))) {
177 }
178 }
179
180 /// Sets Placement kind for the corresponding die.
182 auto InputData = Flags.load();
183 if ((InputData & 0x7) == NotSet)
184 if (Flags.compare_exchange_weak(InputData, (InputData | Placement)))
185 return true;
186
187 return false;
188 }
189
190#define SINGLE_FLAG_METHODS_SET(Name, Value) \
191 bool get##Name() const { return Flags & Value; } \
192 void set##Name() { \
193 auto InputData = Flags.load(); \
194 while (!Flags.compare_exchange_weak(InputData, InputData | Value)) { \
195 } \
196 } \
197 void unset##Name() { \
198 auto InputData = Flags.load(); \
199 while (!Flags.compare_exchange_weak(InputData, InputData & ~Value)) { \
200 } \
201 }
202
203 /// DIE is a part of the linked output.
205
206 /// DIE has children which are part of the linked output.
207 SINGLE_FLAG_METHODS_SET(KeepChildren, 0x10)
208
209 /// DIE is referenced by other DIE.
210 SINGLE_FLAG_METHODS_SET(ReferrencedBy, 0x20)
211
212 /// DIE is in module scope.
213 SINGLE_FLAG_METHODS_SET(IsInMouduleScope, 0x40)
214
215 /// DIE is in function scope.
216 SINGLE_FLAG_METHODS_SET(IsInFunctionScope, 0x80)
217
219 auto InputData = Flags.load();
220 while (!Flags.compare_exchange_weak(
221 InputData, InputData & ~(0x7 | 0x8 | 0x10 | 0x20))) {
222 }
223 }
224
225 /// Erase all flags.
226 void eraseData() { Flags = 0; }
227
228#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
230#endif
231 };
232
233 /// \defgroup Group of functions returning DIE info.
234 ///
235 /// @{
236
237 /// \p Idx index of the DIE.
238 /// \returns DieInfo descriptor.
239 DIEInfo &getDIEInfo(unsigned Idx) { return DieInfoArray[Idx]; }
240
241 /// \p Idx index of the DIE.
242 /// \returns DieInfo descriptor.
243 const DIEInfo &getDIEInfo(unsigned Idx) const { return DieInfoArray[Idx]; }
244
245 /// \p Idx index of the DIE.
246 /// \returns DieInfo descriptor.
248 return DieInfoArray[getOrigUnit().getDIEIndex(Entry)];
249 }
250
251 /// \p Idx index of the DIE.
252 /// \returns DieInfo descriptor.
253 const DIEInfo &getDIEInfo(const DWARFDebugInfoEntry *Entry) const {
254 return DieInfoArray[getOrigUnit().getDIEIndex(Entry)];
255 }
256
257 /// \p Die
258 /// \returns PlainDieInfo descriptor.
260 return DieInfoArray[getOrigUnit().getDIEIndex(Die)];
261 }
262
263 /// \p Die
264 /// \returns PlainDieInfo descriptor.
265 const DIEInfo &getDIEInfo(const DWARFDie &Die) const {
266 return DieInfoArray[getOrigUnit().getDIEIndex(Die)];
267 }
268
269 /// \p Idx index of the DIE.
270 /// \returns DieInfo descriptor.
272 return reinterpret_cast<std::atomic<uint64_t> *>(&OutDieOffsetArray[Idx])
273 ->load();
274 }
275
276 /// \p Idx index of the DIE.
277 /// \returns DieInfo descriptor.
279 reinterpret_cast<std::atomic<uint64_t> *>(&OutDieOffsetArray[Idx])
280 ->store(Offset);
281 }
282
283 /// @}
284
285 /// Returns value of DW_AT_low_pc attribute.
286 std::optional<uint64_t> getLowPc() const { return LowPc; }
287
288 /// Returns value of DW_AT_high_pc attribute.
289 uint64_t getHighPc() const { return HighPc; }
290
291 /// Returns true if there is a label corresponding to the specified \p Addr.
292 bool hasLabelAt(uint64_t Addr) const { return Labels.count(Addr); }
293
294 /// Add the low_pc of a label that is relocated by applying
295 /// offset \p PCOffset.
296 void addLabelLowPc(uint64_t LabelLowPc, int64_t PcOffset);
297
298 /// Resolve the DIE attribute reference that has been extracted in \p
299 /// RefValue. The resulting DIE might be in another CompileUnit.
300 /// \returns referenced die and corresponding compilation unit.
301 /// compilation unit is null if reference could not be resolved.
302 std::optional<std::pair<CompileUnit *, uint32_t>>
303 resolveDIEReference(const DWARFFormValue &RefValue,
304 ResolveInterCUReferencesMode CanResolveInterCUReferences);
305 /// @}
306
307 /// Add a function range [\p LowPC, \p HighPC) that is relocated by applying
308 /// offset \p PCOffset.
309 void addFunctionRange(uint64_t LowPC, uint64_t HighPC, int64_t PCOffset);
310
311 /// Returns function ranges of this unit.
312 const RangesTy &getFunctionRanges() const { return Ranges; }
313
314 /// Clone and emit this compilation unit.
315 Error cloneAndEmit(std::optional<Triple> TargetTriple);
316
317 /// Clone and emit debug locations(.debug_loc/.debug_loclists).
319
320 /// Clone and emit ranges.
322
323 /// Clone and emit debug macros(.debug_macinfo/.debug_macro).
325
326 // Clone input DIE entry.
327 DIE *cloneDIE(const DWARFDebugInfoEntry *InputDieEntry, uint64_t OutOffset,
328 std::optional<int64_t> FuncAddressAdjustment,
329 std::optional<int64_t> VarAddressAdjustment,
331
332 // Clone and emit line table.
333 Error cloneAndEmitLineTable(Triple &TargetTriple);
334
335 /// Clone attribute location axpression.
336 void cloneDieAttrExpression(const DWARFExpression &InputExpression,
337 SmallVectorImpl<uint8_t> &OutputExpression,
338 SectionDescriptor &Section,
339 std::optional<int64_t> VarAddressAdjustment,
340 OffsetsPtrVector &PatchesOffsets);
341
342 /// Returns index(inside .debug_addr) of an address.
344 return DebugAddrIndexMap.getValueIndex(Addr);
345 }
346
347 /// Returns index(inside .debug_str_offsets) of specified string.
349 return DebugStringIndexMap.getValueIndex(String);
350 }
351
352 /// \defgroup Helper methods to access OrigUnit.
353 ///
354 /// @{
355
356 /// Returns paired compile unit from input DWARF.
358 assert(OrigUnit != nullptr);
359 return *OrigUnit;
360 }
361
362 const DWARFDebugInfoEntry *
364 assert(OrigUnit != nullptr);
365 return OrigUnit->getFirstChildEntry(Die);
366 }
367
368 const DWARFDebugInfoEntry *
370 assert(OrigUnit != nullptr);
371 return OrigUnit->getSiblingEntry(Die);
372 }
373
375 assert(OrigUnit != nullptr);
376 return OrigUnit->getParent(Die);
377 }
378
380 assert(OrigUnit != nullptr);
381 return OrigUnit->getDIEAtIndex(Index);
382 }
383
385 assert(OrigUnit != nullptr);
386 return OrigUnit->getDebugInfoEntry(Index);
387 }
388
389 DWARFDie getUnitDIE(bool ExtractUnitDIEOnly = true) {
390 assert(OrigUnit != nullptr);
391 return OrigUnit->getUnitDIE(ExtractUnitDIEOnly);
392 }
393
395 assert(OrigUnit != nullptr);
396 return DWARFDie(OrigUnit, Die);
397 }
398
400 assert(OrigUnit != nullptr);
401 return OrigUnit->getDIEIndex(Die);
402 }
403
404 uint32_t getDIEIndex(const DWARFDie &Die) const {
405 assert(OrigUnit != nullptr);
406 return OrigUnit->getDIEIndex(Die);
407 }
408
409 std::optional<DWARFFormValue> find(uint32_t DieIdx,
410 ArrayRef<dwarf::Attribute> Attrs) const {
411 assert(OrigUnit != nullptr);
412 return find(OrigUnit->getDebugInfoEntry(DieIdx), Attrs);
413 }
414
415 std::optional<DWARFFormValue> find(const DWARFDebugInfoEntry *Die,
416 ArrayRef<dwarf::Attribute> Attrs) const {
417 if (!Die)
418 return std::nullopt;
419 auto AbbrevDecl = Die->getAbbreviationDeclarationPtr();
420 if (AbbrevDecl) {
421 for (auto Attr : Attrs) {
422 if (auto Value = AbbrevDecl->getAttributeValue(Die->getOffset(), Attr,
423 *OrigUnit))
424 return Value;
425 }
426 }
427 return std::nullopt;
428 }
429
430 std::optional<uint32_t> getDIEIndexForOffset(uint64_t Offset) {
431 return OrigUnit->getDIEIndexForOffset(Offset);
432 }
433
434 /// @}
435
436 /// \defgroup Methods used for reporting warnings and errors:
437 ///
438 /// @{
439
440 void warn(const Twine &Warning, const DWARFDie *DIE = nullptr) {
442 }
443
444 void warn(Error Warning, const DWARFDie *DIE = nullptr) {
445 handleAllErrors(std::move(Warning), [&](ErrorInfoBase &Info) {
446 GlobalData.warn(Info.message(), getUnitName(), DIE);
447 });
448 }
449
450 void warn(const Twine &Warning, const DWARFDebugInfoEntry *DieEntry) {
451 if (DieEntry != nullptr) {
452 DWARFDie DIE(&getOrigUnit(), DieEntry);
454 return;
455 }
456
458 }
459
460 void error(const Twine &Err, const DWARFDie *DIE = nullptr) {
462 }
463
464 void error(Error Err, const DWARFDie *DIE = nullptr) {
465 handleAllErrors(std::move(Err), [&](ErrorInfoBase &Info) {
466 GlobalData.error(Info.message(), getUnitName(), DIE);
467 });
468 }
469
470 /// @}
471
472private:
473 /// Navigate DWARF tree recursively and set die properties.
474 void analyzeDWARFStructureRec(const DWARFDebugInfoEntry *DieEntry,
475 bool IsInModule, bool IsInFunction);
476
477 struct LinkedLocationExpressionsWithOffsetPatches {
479 OffsetsPtrVector Patches;
480 };
481 using LinkedLocationExpressionsVector =
483
484 /// Emit debug locations.
485 void emitLocations(DebugSectionKind LocationSectionKind);
486
487 /// Emit location list header.
488 uint64_t emitLocListHeader(SectionDescriptor &OutLocationSection);
489
490 /// Emit location list fragment.
491 uint64_t emitLocListFragment(
492 const LinkedLocationExpressionsVector &LinkedLocationExpression,
493 SectionDescriptor &OutLocationSection);
494
495 /// Emit the .debug_addr section fragment for current unit.
496 Error emitDebugAddrSection();
497
498 /// Emit the .debug_str_offsets section for current unit.
499 Error emitDebugStringOffsetSection();
500
501 /// Emit .debug_aranges.
502 void emitAranges(AddressRanges &LinkedFunctionRanges);
503
504 /// Clone and emit .debug_ranges/.debug_rnglists.
505 void cloneAndEmitRangeList(DebugSectionKind RngSectionKind,
506 AddressRanges &LinkedFunctionRanges);
507
508 /// Emit range list header.
509 uint64_t emitRangeListHeader(SectionDescriptor &OutRangeSection);
510
511 /// Emit range list fragment.
512 void emitRangeListFragment(const AddressRanges &LinkedRanges,
513 SectionDescriptor &OutRangeSection);
514
515 /// Insert the new line info sequence \p Seq into the current
516 /// set of already linked line info \p Rows.
517 void insertLineSequence(std::vector<DWARFDebugLine::Row> &Seq,
518 std::vector<DWARFDebugLine::Row> &Rows);
519
520 /// Emits body for both macro sections.
521 void emitMacroTableImpl(const DWARFDebugMacro *MacroTable,
522 uint64_t OffsetToMacroTable, bool hasDWARFv5Header);
523
524 /// Store accelerator information for the \p InputDieEntry.
525 void rememberAcceleratorEntries(const DWARFDebugInfoEntry *InputDieEntry,
526 uint64_t OutOffset, AttributesInfo &AttrInfo);
527
528 /// Store ObjC accelerator information for the \p InputDieEntry.
529 void rememberObjCAccelerator(const DWARFDebugInfoEntry *InputDieEntry,
530 uint64_t OutOffset, AttributesInfo &AttrInfo);
531
532 /// DWARFFile containing this compile unit.
533 DWARFFile &File;
534
535 /// Pointer to the paired compile unit from the input DWARF.
536 DWARFUnit *OrigUnit = nullptr;
537
538 /// Line table for this unit.
539 const DWARFDebugLine::LineTable *LineTablePtr = nullptr;
540
541 /// Cached resolved paths from the line table.
542 /// The key is <UniqueUnitID, FileIdx>.
543 using ResolvedPathsMap = DenseMap<unsigned, StringEntry *>;
544 ResolvedPathsMap ResolvedFullPaths;
545 StringMap<StringEntry *> ResolvedParentPaths;
546
547 /// Maps an address into the index inside .debug_addr section.
548 IndexedValuesMap<uint64_t> DebugAddrIndexMap;
549
550 /// Maps a string into the index inside .debug_str_offsets section.
551 IndexedValuesMap<const StringEntry *> DebugStringIndexMap;
552
553 /// \defgroup Data Members accessed asinchroniously.
554 ///
555 /// @{
556 OffsetToUnitTy getUnitFromOffset;
557
558 std::optional<uint64_t> LowPc;
559 uint64_t HighPc = 0;
560
561 /// The ranges in that map are the PC ranges for functions in this unit,
562 /// associated with the PC offset to apply to the addresses to get
563 /// the linked address.
564 RangesTy Ranges;
565 std::mutex RangesMutex;
566
567 /// The DW_AT_low_pc of each DW_TAG_label.
569 std::mutex LabelsMutex;
570
571 /// This field keeps current stage of overall compile unit processing.
572 std::atomic<Stage> Stage;
573
574 /// DIE info indexed by DIE index.
575 SmallVector<DIEInfo> DieInfoArray;
576 SmallVector<uint64_t> OutDieOffsetArray;
577 /// @}
578};
579
580} // end of namespace dwarflinker_parallel
581} // end namespace llvm
582
583#endif // LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERCOMPILEUNIT_H
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:510
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
uint64_t Addr
Branch Probability Basic Block Placement
Basic Register Allocator
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
AddressRangesMap class maps values to the address ranges.
The AddressRanges class helps normalize address range collections.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:66
A structured debug information entry.
Definition: DIE.h:819
DWARFDebugInfoEntry - A DIE with only the minimum required data.
const DWARFAbbreviationDeclaration * getAbbreviationDeclarationPtr() const
Utility class that carries the DWARF compile/type unit and the debug info entry in an object.
Definition: DWARFDie.h:42
std::optional< DWARFFormValue > find(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE.
Definition: DWARFDie.cpp:247
const char * getName(DINameKind Kind) const
Return the DIE name resolving DW_AT_specification or DW_AT_abstract_origin references if necessary.
Definition: DWARFDie.cpp:442
This class represents DWARF information for source file and its address map.
Definition: DWARFLinker.h:268
const DWARFDebugInfoEntry * getDebugInfoEntry(unsigned Index) const
Return DWARFDebugInfoEntry for the specified index Index.
Definition: DWARFUnit.h:274
const DWARFDebugInfoEntry * getSiblingEntry(const DWARFDebugInfoEntry *Die) const
Definition: DWARFUnit.cpp:919
DWARFDie getUnitDIE(bool ExtractUnitDIEOnly=true)
Definition: DWARFUnit.h:441
DWARFDie getParent(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:889
std::optional< uint32_t > getDIEIndexForOffset(uint64_t Offset)
Return the DIE index for a given offset Offset inside the unit's DIE vector.
Definition: DWARFUnit.h:540
uint32_t getDIEIndex(const DWARFDebugInfoEntry *Die) const
Return the index of a Die entry inside the unit's DIE vector.
Definition: DWARFUnit.h:267
const DWARFDebugInfoEntry * getFirstChildEntry(const DWARFDebugInfoEntry *Die) const
Definition: DWARFUnit.cpp:980
DWARFDie getDIEAtIndex(unsigned Index)
Return the DIE object at the given index Index.
Definition: DWARFUnit.h:519
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: DenseMap.h:151
Base class for error info classes.
Definition: Error.h:45
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
Class representing an expression and its matching format.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:577
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:112
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:222
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
LLVM Value Representation.
Definition: Value.h:74
Stores all information related to a compile unit, be it in its original instance of the object file o...
Error cloneAndEmitDebugLocations()
Clone and emit debug locations(.debug_loc/.debug_loclists).
void cloneDieAttrExpression(const DWARFExpression &InputExpression, SmallVectorImpl< uint8_t > &OutputExpression, SectionDescriptor &Section, std::optional< int64_t > VarAddressAdjustment, OffsetsPtrVector &PatchesOffsets)
Clone attribute location axpression.
void maybeResetToLoadedStage()
Reset compile units data(results of liveness analysis, clonning) if current stage greater than Stage:...
uint64_t getDebugStrIndex(const StringEntry *String)
Returns index(inside .debug_str_offsets) of specified string.
void analyzeImportedModule(const DWARFDebugInfoEntry *DieEntry)
Collect references to parseable Swift interfaces in imported DW_TAG_module blocks.
Stage
The stages of new compile unit processing.
@ CreatedNotLoaded
Created, linked with input DWARF file.
@ PatchesUpdated
Offsets inside patch records are updated.
@ Cleaned
Resources(Input DWARF, Output DWARF tree) are released.
@ LivenessAnalysisDone
Input DWARF is analysed(DIEs pointing to the real code section are discovered,...
uint64_t getHighPc() const
Returns value of DW_AT_high_pc attribute.
void cleanupDataAfterClonning()
Cleanup unneeded resources after compile unit is cloned.
DieOutputPlacement
Kinds of placement for the output die.
@ Parent
Corresponding DIE needs to examine parent to determine the point of placement.
@ TypeTable
Corresponding DIE goes to the type table only.
@ PlainDwarf
Corresponding DIE goes to the plain dwarf only.
@ Both
Corresponding DIE goes to type table and to plain dwarf.
Error cloneAndEmit(std::optional< Triple > TargetTriple)
Clone and emit this compilation unit.
CompileUnit(LinkingGlobalData &GlobalData, DWARFUnit &OrigUnit, unsigned ID, StringRef ClangModuleName, DWARFFile &File, OffsetToUnitTy UnitFromOffset, dwarf::FormParams Format, support::endianness Endianess)
void addFunctionRange(uint64_t LowPC, uint64_t HighPC, int64_t PCOffset)
Add a function range [LowPC, HighPC) that is relocated by applying offset PCOffset.
std::optional< std::pair< CompileUnit *, uint32_t > > resolveDIEReference(const DWARFFormValue &RefValue, ResolveInterCUReferencesMode CanResolveInterCUReferences)
Resolve the DIE attribute reference that has been extracted in RefValue.
Error cloneAndEmitRanges()
Clone and emit ranges.
Stage getStage() const
Returns stage of overall processing.
const RangesTy & getFunctionRanges() const
Returns function ranges of this unit.
DIE * cloneDIE(const DWARFDebugInfoEntry *InputDieEntry, uint64_t OutOffset, std::optional< int64_t > FuncAddressAdjustment, std::optional< int64_t > VarAddressAdjustment, BumpPtrAllocator &Allocator)
void updateDieRefPatchesWithClonedOffsets()
After cloning stage the output DIEs offsets are deallocated.
bool loadInputDIEs()
Load DIEs of input compilation unit.
void setStage(Stage Stage)
Set stage of overall processing.
std::optional< uint64_t > getLowPc() const
Returns value of DW_AT_low_pc attribute.
Error cloneAndEmitDebugMacro()
Clone and emit debug macros(.debug_macinfo/.debug_macro).
uint64_t getDebugAddrIndex(uint64_t Addr)
Returns index(inside .debug_addr) of an address.
const DWARFFile & getContaingFile() const
Returns DWARFFile containing this compile unit.
bool hasLabelAt(uint64_t Addr) const
Returns true if there is a label corresponding to the specified Addr.
void addLabelLowPc(uint64_t LabelLowPc, int64_t PcOffset)
Add the low_pc of a label that is relocated by applying offset PCOffset.
void analyzeDWARFStructure()
Navigate DWARF tree and set die properties.
CompileUnit(LinkingGlobalData &GlobalData, unsigned ID, StringRef ClangModuleName, DWARFFile &File, OffsetToUnitTy UnitFromOffset, dwarf::FormParams Format, support::endianness Endianess)
StringEntry * getFileName(unsigned FileIdx, StringPool &GlobalStrings)
Returns name of the file for the FileIdx from the unit`s line table.
This class represents DWARF information for source file and it's address map.
Definition: DWARFFile.h:26
Base class for all Dwarf units(Compile unit/Type table unit).
std::string UnitName
The name of this unit.
std::string ClangModuleName
If this is a Clang module, this holds the module's name.
StringRef getUnitName() const
Returns this unit name.
uint16_t Language
The DW_AT_language of this unit.
std::string SysRoot
The DW_AT_LLVM_sysroot of this unit.
This class keeps data and services common for the whole linking process.
void error(const Twine &Err, StringRef Context, const DWARFDie *DIE=nullptr)
Report error.
void warn(const Twine &Warning, StringRef Context, const DWARFDie *DIE=nullptr)
Report warning.
void setOutputFormat(dwarf::FormParams Format, support::endianness Endianness)
Sets output format for all keeping sections.
dwarf::FormParams Format
Format for sections.
uint64_t getDieOutOffset(uint32_t Idx)
Idx index of the DIE.
DIEInfo & getDIEInfo(const DWARFDebugInfoEntry *Entry)
Idx index of the DIE.
DIEInfo & getDIEInfo(unsigned Idx)
Idx index of the DIE.
const DIEInfo & getDIEInfo(const DWARFDie &Die) const
Die
DIEInfo & getDIEInfo(const DWARFDie &Die)
Die
const DIEInfo & getDIEInfo(unsigned Idx) const
Idx index of the DIE.
void rememberDieOutOffset(uint32_t Idx, uint64_t Offset)
Idx index of the DIE.
const DIEInfo & getDIEInfo(const DWARFDebugInfoEntry *Entry) const
Idx index of the DIE.
const DWARFDebugInfoEntry * getDebugInfoEntry(unsigned Index) const
uint32_t getDIEIndex(const DWARFDie &Die) const
std::optional< DWARFFormValue > find(const DWARFDebugInfoEntry *Die, ArrayRef< dwarf::Attribute > Attrs) const
const DWARFDebugInfoEntry * getSiblingEntry(const DWARFDebugInfoEntry *Die) const
DWARFDie getParent(const DWARFDebugInfoEntry *Die)
DWARFDie getUnitDIE(bool ExtractUnitDIEOnly=true)
uint32_t getDIEIndex(const DWARFDebugInfoEntry *Die) const
std::optional< uint32_t > getDIEIndexForOffset(uint64_t Offset)
std::optional< DWARFFormValue > find(uint32_t DieIdx, ArrayRef< dwarf::Attribute > Attrs) const
const DWARFDebugInfoEntry * getFirstChildEntry(const DWARFDebugInfoEntry *Die) const
DWARFDie getDIE(const DWARFDebugInfoEntry *Die)
DWARFUnit & getOrigUnit() const
Returns paired compile unit from input DWARF.
void warn(const Twine &Warning, const DWARFDebugInfoEntry *DieEntry)
void error(const Twine &Err, const DWARFDie *DIE=nullptr)
void error(Error Err, const DWARFDie *DIE=nullptr)
void warn(const Twine &Warning, const DWARFDie *DIE=nullptr)
void warn(Error Warning, const DWARFDie *DIE=nullptr)
#define SINGLE_FLAG_METHODS_SET(Name, Value)
StringRef toStringRef(const std::optional< DWARFFormValue > &V, StringRef Default={})
Take an optional DWARFFormValue and try to extract a string value from it.
std::optional< uint64_t > toUnsigned(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an unsigned constant.
DebugSectionKind
List of tracked debug tables.
function_ref< CompileUnit *(uint64_t Offset)> OffsetToUnitTy
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:440
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
Definition: Error.h:970
@ Other
Any other memory.
@ Keep
No function return thunk.
Represents a single DWARF expression, whose value is location-dependent.
A helper struct providing information about the byte size of DW_FORM values that vary in size dependi...
Definition: Dwarf.h:743
Information gathered and exchanged between the various clone*Attr helpers about the attributes of a p...
Information gathered about source DIEs.
void unsetPlacement()
Unsets Placement kind for the corresponding die.
bool setPlacementIfUnset(DieOutputPlacement Placement)
Sets Placement kind for the corresponding die.
void unsetFlagsWhichSetDuringLiveAnalysis()
DIE is a part of the linked output.
void setPlacement(DieOutputPlacement Placement)
Sets Placement kind for the corresponding die.
std::atomic< uint16_t > Flags
Data member keeping various flags.
This structure is used to keep data of the concrete section.