1 //===- DIEAttributeCloner.h -------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIB_DWARFLINKERPARALLEL_DIEATTRIBUTECLONER_H
10 #define LLVM_LIB_DWARFLINKERPARALLEL_DIEATTRIBUTECLONER_H
12 #include "ArrayList.h"
13 #include "DIEGenerator.h"
14 #include "DWARFLinkerCompileUnit.h"
15 #include "DWARFLinkerGlobalData.h"
18 namespace dwarflinker_parallel
{
20 /// Information gathered and exchanged between the various
21 /// clone*Attr helpers about the attributes of a particular DIE.
22 struct AttributesInfo
{
24 StringEntry
*Name
= nullptr;
27 StringEntry
*MangledName
= nullptr;
29 /// Does the DIE have an address pointing to live code section?
30 bool HasLiveAddress
= false;
32 /// Is this DIE only a declaration?
33 bool IsDeclaration
= false;
35 /// Does the DIE have a ranges attribute?
36 bool HasRanges
= false;
38 /// Does the DIE have a string offset attribute?
39 bool HasStringOffsetBaseAttr
= false;
42 /// This class creates clones of input DIE attributes.
43 /// It enumerates attributes of input DIE, creates clone for each
44 /// attribute, adds cloned attribute to the output DIE.
45 class DIEAttributeCloner
{
47 DIEAttributeCloner(DIE
*OutDIE
, CompileUnit
&CU
,
48 const DWARFDebugInfoEntry
*InputDieEntry
,
49 DIEGenerator
&Generator
,
50 std::optional
<int64_t> FuncAddressAdjustment
,
51 std::optional
<int64_t> VarAddressAdjustment
,
52 bool HasLocationExpressionAddress
)
53 : OutDIE(OutDIE
), CU(CU
),
54 DebugInfoOutputSection(
55 CU
.getOrCreateSectionDescriptor(DebugSectionKind::DebugInfo
)),
56 InputDieEntry(InputDieEntry
), Generator(Generator
),
57 FuncAddressAdjustment(FuncAddressAdjustment
),
58 VarAddressAdjustment(VarAddressAdjustment
),
59 HasLocationExpressionAddress(HasLocationExpressionAddress
) {
60 InputDIEIdx
= CU
.getDIEIndex(InputDieEntry
);
63 /// Clone attributes of input DIE.
66 /// Create abbreviations for the output DIE after all attributes are cloned.
67 unsigned finalizeAbbreviations(bool HasChildrenToClone
);
69 /// Cannot be used concurrently.
70 AttributesInfo AttrInfo
;
73 /// Clone string attribute.
75 cloneStringAttr(const DWARFFormValue
&Val
,
76 const DWARFAbbreviationDeclaration::AttributeSpec
&AttrSpec
);
78 /// Clone attribute referencing another DIE.
80 cloneDieRefAttr(const DWARFFormValue
&Val
,
81 const DWARFAbbreviationDeclaration::AttributeSpec
&AttrSpec
);
83 /// Clone scalar attribute.
85 cloneScalarAttr(const DWARFFormValue
&Val
,
86 const DWARFAbbreviationDeclaration::AttributeSpec
&AttrSpec
);
88 /// Clone block or exprloc attribute.
90 cloneBlockAttr(const DWARFFormValue
&Val
,
91 const DWARFAbbreviationDeclaration::AttributeSpec
&AttrSpec
);
93 /// Clone address attribute.
95 cloneAddressAttr(const DWARFFormValue
&Val
,
96 const DWARFAbbreviationDeclaration::AttributeSpec
&AttrSpec
);
98 /// Returns true if attribute should be skipped.
100 shouldSkipAttribute(DWARFAbbreviationDeclaration::AttributeSpec AttrSpec
);
102 /// Update patches offsets with the size of abbreviation number.
104 updatePatchesWithSizeOfAbbreviationNumber(unsigned SizeOfAbbreviationNumber
) {
105 for (uint64_t *OffsetPtr
: PatchesOffsets
)
106 *OffsetPtr
+= SizeOfAbbreviationNumber
;
110 DIE
*OutDIE
= nullptr;
112 /// Compile unit for the output DIE.
115 /// .debug_info section descriptor.
116 SectionDescriptor
&DebugInfoOutputSection
;
119 const DWARFDebugInfoEntry
*InputDieEntry
= nullptr;
122 uint32_t InputDIEIdx
= 0;
124 /// Output DIE generator.
125 DIEGenerator
&Generator
;
127 /// Relocation adjustment for the function address ranges.
128 std::optional
<int64_t> FuncAddressAdjustment
;
130 /// Relocation adjustment for the variable locations.
131 std::optional
<int64_t> VarAddressAdjustment
;
133 /// Indicates whether InputDieEntry has an location attribute
134 /// containg address expression.
135 bool HasLocationExpressionAddress
= false;
137 /// Output offset after all attributes.
138 unsigned AttrOutOffset
= 0;
140 /// Patches for the cloned attributes.
141 OffsetsPtrVector PatchesOffsets
;
144 } // end of namespace dwarflinker_parallel
145 } // end namespace llvm
147 #endif // LLVM_LIB_DWARFLINKERPARALLEL_DIEATTRIBUTECLONER_H