LLVM 24.0.0git
DIEAttributeCloner.h
Go to the documentation of this file.
1//===- DIEAttributeCloner.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_DIEATTRIBUTECLONER_H
10#define LLVM_LIB_DWARFLINKER_PARALLEL_DIEATTRIBUTECLONER_H
11
12#include "ArrayList.h"
13#include "DIEGenerator.h"
16#include "DWARFLinkerTypeUnit.h"
17
18namespace llvm {
19namespace dwarf_linker {
20namespace parallel {
21
22/// Information gathered and exchanged between the various
23/// clone*Attr helpers about the attributes of a particular DIE.
25 /// Short Name.
26 StringEntry *Name = nullptr;
27
28 /// Mangled Name.
30
31 /// Does the DIE have an address pointing to live code section?
32 bool HasLiveAddress = false;
33
34 /// Is this DIE only a declaration?
35 bool IsDeclaration = false;
36
37 /// Does the DIE have a ranges attribute?
38 bool HasRanges = false;
39
40 /// Does the DIE have a string offset attribute?
42
43 /// Does the DIE have an address base attribute?
44 bool HasAddrBaseAttr = false;
45
46 /// Does the DIE have a DW_AT_APPLE_origin attribute?
47 bool HasAppleOrigin = false;
48};
49
50/// This class creates clones of input DIE attributes.
51/// It enumerates attributes of input DIE, creates clone for each
52/// attribute, adds cloned attribute to the output DIE.
54public:
66
78
79 /// Clone attributes of input DIE.
80 void clone();
81
82 /// Create abbreviations for the output DIE after all attributes are cloned.
83 unsigned finalizeAbbreviations(bool HasChildrenToClone);
84
85 /// Cannot be used concurrently.
87
88 unsigned getOutOffset() { return AttrOutOffset; }
89
90protected:
95 std::optional<int64_t> FuncAddressAdjustment,
96 std::optional<int64_t> VarAddressAdjustment,
100 OutUnit->getSectionDescriptor(DebugSectionKind::DebugInfo)),
105 InputDIEIdx = InUnit.getDIEIndex(InputDieEntry);
106
107 // A type unit is shared by compile units, so has no relocations of its own.
108 SaveRelocs = OutUnit.isCompileUnit() &&
109 InUnit.getContainingFile().Addresses->needToSaveValidRelocs();
110
111 // Use DW_FORM_strp form for string attributes for DWARF version less than 5
112 // or if output unit is type unit and attributes are cloned in parallel
113 // (debug_str_offsets ordering would be non-deterministic otherwise).
114 Use_DW_FORM_strp = (InUnit.getVersion() < 5) ||
115 (OutUnit.isTypeUnit() &&
116 InUnit.getGlobalData().getOptions().Threads != 1);
117 }
118
119 /// Clone string attribute.
120 size_t
123
124 /// Add the string attribute \p Attr, in the string form of the unit.
126
127 /// Clone attribute referencing another DIE.
128 size_t
131
132 /// Clone scalar attribute.
133 size_t
136
137 /// Clone block or exprloc attribute.
138 size_t
141
142 /// Clone address attribute.
143 size_t
146
147 /// Returns the input DIE's DW_AT_high_pc value \p HighPC, constrained so the
148 /// code range it ends stays clear of the symbol the linker places next. \p
149 /// IsLength tells whether high_pc is encoded as a length rather than an
150 /// address.
151 ///
152 /// A scope nested in a function inherits the overrun of the function, so it
153 /// is constrained as well.
154 uint64_t constrainHighPC(uint64_t HighPC, bool IsLength);
155
156 /// Returns true if attribute should be skipped.
157 bool
159
160 /// Output DIE.
161 DIE *OutDIE = nullptr;
162
163 /// Input compilation unit.
165
166 /// Output unit(either "plain" compilation unit, either artificial type unit).
168
169 /// .debug_info section descriptor.
171
172 /// Input DIE entry.
174
175 /// Input DIE index.
177
178 /// Output DIE generator.
180
181 /// Relocation adjustment for the function address ranges.
182 std::optional<int64_t> FuncAddressAdjustment;
183
184 /// Relocation adjustment for the variable locations.
185 std::optional<int64_t> VarAddressAdjustment;
186
187 /// Indicates whether InputDieEntry has an location attribute
188 /// containg address expression.
190
191 /// Output offset after all attributes.
192 unsigned AttrOutOffset = 0;
193
194 /// Patches for the cloned attributes.
196
198
199 bool SaveRelocs = false;
200
201 /// This flag forces using DW_FORM_strp for string attributes.
202 bool Use_DW_FORM_strp = false;
203};
204
205} // end of namespace parallel
206} // end of namespace dwarf_linker
207} // end of namespace llvm
208
209#endif // LLVM_LIB_DWARFLINKER_PARALLEL_DIEATTRIBUTECLONER_H
uint64_t uint64_t
A structured debug information entry.
Definition DIE.h:835
DWARFDebugInfoEntry - A DIE with only the minimum required data.
Stores all information related to a compile unit, be it in its original instance of the object file o...
size_t cloneBlockAttr(const DWARFFormValue &Val, const DWARFAbbreviationDeclaration::AttributeSpec &AttrSpec)
Clone block or exprloc attribute.
AttributesInfo AttrInfo
Cannot be used concurrently.
CompileUnit & InUnit
Input compilation unit.
bool HasLocationExpressionAddress
Indicates whether InputDieEntry has an location attribute containg address expression.
SectionDescriptor & DebugInfoOutputSection
.debug_info section descriptor.
size_t addStringAttr(dwarf::Attribute Attr, StringEntry *String)
Add the string attribute Attr, in the string form of the unit.
unsigned finalizeAbbreviations(bool HasChildrenToClone)
Create abbreviations for the output DIE after all attributes are cloned.
unsigned AttrOutOffset
Output offset after all attributes.
DIEGenerator & Generator
Output DIE generator.
size_t cloneScalarAttr(const DWARFFormValue &Val, const DWARFAbbreviationDeclaration::AttributeSpec &AttrSpec)
Clone scalar attribute.
OffsetsPtrVector PatchesOffsets
Patches for the cloned attributes.
size_t cloneDieRefAttr(const DWARFFormValue &Val, const DWARFAbbreviationDeclaration::AttributeSpec &AttrSpec)
Clone attribute referencing another DIE.
DIEAttributeCloner(DIE *OutDIE, CompileUnit &InUnit, CompileUnit *OutUnit, const DWARFDebugInfoEntry *InputDieEntry, DIEGenerator &Generator, std::optional< int64_t > FuncAddressAdjustment, std::optional< int64_t > VarAddressAdjustment, bool HasLocationExpressionAddress)
bool shouldSkipAttribute(DWARFAbbreviationDeclaration::AttributeSpec AttrSpec)
Returns true if attribute should be skipped.
size_t cloneStringAttr(const DWARFFormValue &Val, const DWARFAbbreviationDeclaration::AttributeSpec &AttrSpec)
Clone string attribute.
DIEAttributeCloner(DIE *OutDIE, CompileUnit &InUnit, CompileUnit::OutputUnitVariantPtr OutUnit, const DWARFDebugInfoEntry *InputDieEntry, DIEGenerator &Generator, std::optional< int64_t > FuncAddressAdjustment, std::optional< int64_t > VarAddressAdjustment, bool HasLocationExpressionAddress)
const DWARFDebugInfoEntry * InputDieEntry
Input DIE entry.
std::optional< int64_t > FuncAddressAdjustment
Relocation adjustment for the function address ranges.
CompileUnit::OutputUnitVariantPtr OutUnit
Output unit(either "plain" compilation unit, either artificial type unit).
size_t cloneAddressAttr(const DWARFFormValue &Val, const DWARFAbbreviationDeclaration::AttributeSpec &AttrSpec)
Clone address attribute.
std::optional< int64_t > VarAddressAdjustment
Relocation adjustment for the variable locations.
uint64_t constrainHighPC(uint64_t HighPC, bool IsLength)
Returns the input DIE's DW_AT_high_pc value HighPC, constrained so the code range it ends stays clear...
bool Use_DW_FORM_strp
This flag forces using DW_FORM_strp for string attributes.
DIEAttributeCloner(DIE *OutDIE, CompileUnit &InUnit, TypeUnit *OutUnit, const DWARFDebugInfoEntry *InputDieEntry, DIEGenerator &Generator, std::optional< int64_t > FuncAddressAdjustment, std::optional< int64_t > VarAddressAdjustment, bool HasLocationExpressionAddress)
This class is a helper to create output DIE tree.
Type Unit is used to represent an artificial compilation unit which keeps all type information.
SmallVector< uint64_t * > OffsetsPtrVector
Type for list of pointers to patches offsets.
DebugSectionKind
List of tracked debug tables.
StringMapEntry< EmptyStringSetTag > StringEntry
StringEntry keeps data of the string: the length, external offset and a string body which is placed r...
Definition StringPool.h:23
Attribute
Attributes.
Definition Dwarf.h:125
This is an optimization pass for GlobalISel generic memory operations.
What an attribute being cloned was cloned from.
Information gathered and exchanged between the various clone*Attr helpers about the attributes of a p...
bool IsDeclaration
Is this DIE only a declaration?
bool HasRanges
Does the DIE have a ranges attribute?
bool HasLiveAddress
Does the DIE have an address pointing to live code section?
bool HasAppleOrigin
Does the DIE have a DW_AT_APPLE_origin attribute?
bool HasStringOffsetBaseAttr
Does the DIE have a string offset attribute?
bool HasAddrBaseAttr
Does the DIE have an address base attribute?
This structure is used to keep data of the concrete section.