LLVM 19.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)
82 }
83
84 /// \defgroup Methods used to emit unit's debug info:
85 ///
86 /// @{
87 /// Emit unit's abbreviations.
89
90 /// Emit .debug_info section for unit DIEs.
91 Error emitDebugInfo(const Triple &TargetTriple);
92
93 /// Emit .debug_line section.
94 Error emitDebugLine(const Triple &TargetTriple,
95 const DWARFDebugLine::LineTable &OutLineTable);
96
97 /// Emit the .debug_str_offsets section for current unit.
99 /// @}
100
101 /// \defgroup Methods used for reporting warnings and errors:
102 ///
103 /// @{
105
106 void error(const Twine &Err) { GlobalData.warn(Err, getUnitName()); }
107 /// @}
108
109 /// \defgroup Methods and data members used for building accelerator tables:
110 ///
111 /// @{
112
113 enum class AccelType : uint8_t { None, Name, Namespace, ObjC, Type };
114
115 /// This structure keeps fields which would be used for creating accelerator
116 /// table.
117 struct AccelInfo {
119 AvoidForPubSections = false;
121 }
122
123 /// Name of the entry.
124 StringEntry *String = nullptr;
125
126 /// Output offset of the DIE this entry describes.
128
129 /// Hash of the fully qualified name.
131
132 /// Tag of the DIE this entry describes.
133 dwarf::Tag Tag = dwarf::DW_TAG_null;
134
135 /// Type of this accelerator record.
137
138 /// Avoid emitting this entry for pub sections.
140
141 /// Is this an ObjC class implementation?
143 };
144
145 /// Emit .debug_pubnames and .debug_pubtypes for \p Unit.
146 void emitPubAccelerators();
147
148 /// Enumerates accelerator data.
149 virtual void
151
152 /// @}
153
154 /// Returns index(inside .debug_str_offsets) of specified string.
156 return DebugStringIndexMap.getValueIndex(String);
157 }
158
159protected:
160 /// Emit single abbreviation entry.
161 void emitDwarfAbbrevEntry(const DIEAbbrev &Abbrev,
162 SectionDescriptor &AbbrevSection);
163
164 /// Emit single pubnames/pubtypes accelerator entry.
165 std::optional<uint64_t>
166 emitPubAcceleratorEntry(SectionDescriptor &OutSection, const AccelInfo &Info,
167 std::optional<uint64_t> LengthOffset);
168
169 /// Unique ID for the unit.
170 unsigned ID = 0;
171
172 /// The name of this unit.
173 std::string UnitName;
174
175 /// The DW_AT_LLVM_sysroot of this unit.
176 std::string SysRoot;
177
178 /// If this is a Clang module, this holds the module's name.
179 std::string ClangModuleName;
180
182
183 /// true if current unit references_to/is_referenced by other unit.
184 std::atomic<bool> IsInterconnectedCU = {false};
185
186 /// FoldingSet that uniques the abbreviations.
188
189 /// Storage for the unique Abbreviations.
190 std::vector<std::unique_ptr<DIEAbbrev>> Abbreviations;
191
192 /// Output unit DIE.
193 DIE *OutUnitDIE = nullptr;
194
195 /// Cache for file names for this unit.
199
200 /// Maps a string into the index inside .debug_str_offsets section.
202};
203
204inline bool isODRLanguage(uint16_t Language) {
205 switch (Language) {
206 case dwarf::DW_LANG_C_plus_plus:
207 case dwarf::DW_LANG_C_plus_plus_03:
208 case dwarf::DW_LANG_C_plus_plus_11:
209 case dwarf::DW_LANG_C_plus_plus_14:
210 case dwarf::DW_LANG_ObjC_plus_plus:
211 return true;
212 default:
213 return false;
214 };
215
216 return false;
217}
218
219} // end of namespace parallel
220} // end of namespace dwarf_linker
221} // end of namespace llvm
222
223#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
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:529
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:50
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.
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?
This structure is used to keep data of the concrete section.