LLVM 20.0.0git
DWARFLinkerUnit.h
Go to the documentation of this file.
1//===- DWARFLinkerUnit.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_DWARFLINKER_PARALLEL_DWARFLINKERUNIT_H
10#define LLVM_LIB_DWARFLINKER_PARALLEL_DWARFLINKERUNIT_H
11
13#include "OutputSections.h"
14#include "llvm/CodeGen/DIE.h"
19#include "llvm/Support/LEB128.h"
20
21namespace llvm {
22namespace dwarf_linker {
23namespace parallel {
24
25class DwarfUnit;
27
28/// Base class for all Dwarf units(Compile unit/Type table unit).
29class DwarfUnit : public OutputSections {
30public:
31 virtual ~DwarfUnit() {}
35 OutUnitDIE(nullptr) {}
36
37 /// Unique id of the unit.
38 unsigned getUniqueID() const { return ID; }
39
40 /// Returns size of this(newly generated) compile unit.
41 uint64_t getUnitSize() const { return UnitSize; }
42
43 /// Returns this unit name.
44 StringRef getUnitName() const { return UnitName; }
45
46 /// Return the DW_AT_LLVM_sysroot of the compile unit or an empty StringRef.
48
49 /// Return true if this compile unit is from Clang module.
50 bool isClangModule() const { return !ClangModuleName.empty(); }
51
52 /// Return Clang module name;
53 const std::string &getClangModuleName() const { return ClangModuleName; }
54
55 /// Return global data.
57
58 /// Returns true if unit is inter-connected(it references/referenced by other
59 /// unit).
60 bool isInterconnectedCU() const { return IsInterconnectedCU; }
61
62 /// Mark this unit as inter-connected(it references/referenced by other unit).
64
65 /// Adds \p Abbrev into unit`s abbreviation table.
66 void assignAbbrev(DIEAbbrev &Abbrev);
67
68 /// Returns abbreviations for this compile unit.
69 const std::vector<std::unique_ptr<DIEAbbrev>> &getAbbreviations() const {
70 return Abbreviations;
71 }
72
73 /// Returns output unit DIE.
75
76 /// Set output unit DIE.
77 void setOutUnitDIE(DIE *UnitDie) {
78 OutUnitDIE = UnitDie;
79
80 if (OutUnitDIE != nullptr) {
83 }
84 }
85
86 /// Returns unit DWARF tag.
87 dwarf::Tag getTag() const { return UnitTag; }
88
89 /// \defgroup Methods used to emit unit's debug info:
90 ///
91 /// @{
92 /// Emit unit's abbreviations.
94
95 /// Emit .debug_info section for unit DIEs.
96 Error emitDebugInfo(const Triple &TargetTriple);
97
98 /// Emit .debug_line section.
99 Error emitDebugLine(const Triple &TargetTriple,
100 const DWARFDebugLine::LineTable &OutLineTable);
101
102 /// Emit the .debug_str_offsets section for current unit.
104 /// @}
105
106 /// \defgroup Methods used for reporting warnings and errors:
107 ///
108 /// @{
110
111 void error(const Twine &Err) { GlobalData.warn(Err, getUnitName()); }
112 /// @}
113
114 /// \defgroup Methods and data members used for building accelerator tables:
115 ///
116 /// @{
117
119
120 /// This structure keeps fields which would be used for creating accelerator
121 /// table.
122 struct AccelInfo {
124 AvoidForPubSections = false;
126 }
127
128 /// Name of the entry.
129 StringEntry *String = nullptr;
130
131 /// Output offset of the DIE this entry describes.
133
134 /// Hash of the fully qualified name.
136
137 /// Tag of the DIE this entry describes.
138 dwarf::Tag Tag = dwarf::DW_TAG_null;
139
140 /// Type of this accelerator record.
142
143 /// Avoid emitting this entry for pub sections.
145
146 /// Is this an ObjC class implementation?
148 };
149
150 /// Emit .debug_pubnames and .debug_pubtypes for \p Unit.
151 void emitPubAccelerators();
152
153 /// Enumerates accelerator data.
154 virtual void
156
157 /// @}
158
159 /// Returns index(inside .debug_str_offsets) of specified string.
161 return DebugStringIndexMap.getValueIndex(String);
162 }
163
164protected:
165 /// Emit single abbreviation entry.
166 void emitDwarfAbbrevEntry(const DIEAbbrev &Abbrev,
167 SectionDescriptor &AbbrevSection);
168
169 /// Emit single pubnames/pubtypes accelerator entry.
170 std::optional<uint64_t>
171 emitPubAcceleratorEntry(SectionDescriptor &OutSection, const AccelInfo &Info,
172 std::optional<uint64_t> LengthOffset);
173
174 /// Unique ID for the unit.
175 unsigned ID = 0;
176
177 /// The name of this unit.
178 std::string UnitName;
179
180 /// The DW_AT_LLVM_sysroot of this unit.
181 std::string SysRoot;
182
183 /// If this is a Clang module, this holds the module's name.
184 std::string ClangModuleName;
185
187
188 /// DWARF unit tag.
189 dwarf::Tag UnitTag = dwarf::DW_TAG_null;
190
191 /// true if current unit references_to/is_referenced by other unit.
192 std::atomic<bool> IsInterconnectedCU = {false};
193
194 /// FoldingSet that uniques the abbreviations.
196
197 /// Storage for the unique Abbreviations.
198 std::vector<std::unique_ptr<DIEAbbrev>> Abbreviations;
199
200 /// Output unit DIE.
201 DIE *OutUnitDIE = nullptr;
202
203 /// Cache for file names for this unit.
207
208 /// Maps a string into the index inside .debug_str_offsets section.
210};
211
212inline bool isODRLanguage(uint16_t Language) {
213 switch (Language) {
214 case dwarf::DW_LANG_C_plus_plus:
215 case dwarf::DW_LANG_C_plus_plus_03:
216 case dwarf::DW_LANG_C_plus_plus_11:
217 case dwarf::DW_LANG_C_plus_plus_14:
218 case dwarf::DW_LANG_ObjC_plus_plus:
219 return true;
220 default:
221 return false;
222 };
223
224 return false;
225}
226
227} // end of namespace parallel
228} // end of namespace dwarf_linker
229} // end of namespace llvm
230
231#endif // LLVM_LIB_DWARFLINKER_PARALLEL_DWARFLINKERUNIT_H
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
Dwarf abbreviation, describes the organization of a debug information object.
Definition: DIE.h:79
A structured debug information entry.
Definition: DIE.h:819
unsigned getSize() const
Definition: DIE.h:862
dwarf::Tag getTag() const
Definition: DIE.h:855
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
FoldingSet - This template class is used to instantiate a specialized implementation of the folding s...
Definition: FoldingSet.h:536
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
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
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
This class stores values sequentually and assigns index to the each value.
Base class for all Dwarf units(Compile unit/Type table unit).
unsigned getUniqueID() const
Unique id of the unit.
std::string UnitName
The name of this unit.
LinkingGlobalData & getGlobalData()
Return global data.
std::vector< std::unique_ptr< DIEAbbrev > > Abbreviations
Storage for the unique Abbreviations.
dwarf::Tag getTag() const
Returns unit DWARF tag.
std::string SysRoot
The DW_AT_LLVM_sysroot of this unit.
bool isClangModule() const
Return true if this compile unit is from Clang module.
uint64_t getUnitSize() const
Returns size of this(newly generated) compile unit.
void assignAbbrev(DIEAbbrev &Abbrev)
Adds Abbrev into unit`s abbreviation table.
void setInterconnectedCU()
Mark this unit as inter-connected(it references/referenced by other unit).
IndexedValuesMap< const StringEntry * > DebugStringIndexMap
Maps a string into the index inside .debug_str_offsets section.
std::optional< uint64_t > emitPubAcceleratorEntry(SectionDescriptor &OutSection, const AccelInfo &Info, std::optional< uint64_t > LengthOffset)
Emit single pubnames/pubtypes accelerator entry.
unsigned ID
Unique ID for the unit.
StringRef getUnitName() const
Returns this unit name.
const std::string & getClangModuleName() const
Return Clang module name;.
std::atomic< bool > IsInterconnectedCU
true if current unit references_to/is_referenced by other unit.
void setOutUnitDIE(DIE *UnitDie)
Set output unit DIE.
DwarfUnit(LinkingGlobalData &GlobalData, unsigned ID, StringRef ClangModuleName)
std::string ClangModuleName
If this is a Clang module, this holds the module's name.
bool isInterconnectedCU() const
Returns true if unit is inter-connected(it references/referenced by other unit).
virtual uint64_t getDebugStrIndex(const StringEntry *String)
Returns index(inside .debug_str_offsets) of specified string.
const std::vector< std::unique_ptr< DIEAbbrev > > & getAbbreviations() const
Returns abbreviations for this compile unit.
void emitDwarfAbbrevEntry(const DIEAbbrev &Abbrev, SectionDescriptor &AbbrevSection)
Emit single abbreviation entry.
FoldingSet< DIEAbbrev > AbbreviationsSet
FoldingSet that uniques the abbreviations.
StringRef getSysRoot()
Return the DW_AT_LLVM_sysroot of the compile unit or an empty StringRef.
DIE * getOutUnitDIE()
Returns output unit DIE.
This class keeps data and services common for the whole linking process.
void warn(const Twine &Warning, StringRef Context, const DWARFDie *DIE=nullptr)
Report warning.
This class keeps contents and offsets to the debug sections.
uint16_t getDebugInfoHeaderSize() const
Return size of header of debug_info table.
An efficient, type-erasing, non-owning reference to a callable.
Error emitDebugInfo(const Triple &TargetTriple)
Emit .debug_info section for unit DIEs.
Error emitDebugStringOffsetSection()
Emit the .debug_str_offsets section for current unit.
virtual void forEachAcceleratorRecord(function_ref< void(AccelInfo &)> Handler)=0
Enumerates accelerator data.
void emitPubAccelerators()
Emit .debug_pubnames and .debug_pubtypes for Unit.
Error emitDebugLine(const Triple &TargetTriple, const DWARFDebugLine::LineTable &OutLineTable)
Emit .debug_line section.
bool isODRLanguage(uint16_t Language)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
This structure keeps fields which would be used for creating accelerator table.
bool AvoidForPubSections
Avoid emitting this entry for pub sections.
uint64_t OutOffset
Output offset of the DIE this entry describes.
uint32_t QualifiedNameHash
Hash of the fully qualified name.
bool ObjcClassImplementation
Is this an ObjC class implementation?
dwarf::Tag Tag
Tag of the DIE this entry describes.
This structure is used to keep data of the concrete section.