LLVM: include/llvm/DWARFLinker/AddressesMap.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9#ifndef LLVM_DWARFLINKER_ADDRESSESMAP_H
10#define LLVM_DWARFLINKER_ADDRESSESMAP_H
11
17#include
18
19namespace llvm {
21
22
23
25
26
27
28
29
31public:
33
34
35
37
38
39
40
41
42
43
47
48
49
50
51
52
53
54
55 virtual std::optional<int64_t>
57
58
60
61
62
63
64
66 bool IsLittleEndian) = 0;
67
68
70
71
74 int64_t LinkedOffset,
77
78
79
81 uint64_t OutputUnitOffset) = 0;
82
83
85
86
87
88
89
90
91
92 std::pair<bool, std::optional<int64_t>>
95 DIE.getTag() == dwarf::DW_TAG_constant) &&
96 "Wrong type of input die");
97
98 const auto *Abbrev = DIE.getAbbreviationDeclarationPtr();
99
100
102 std::optional<uint32_t> LocationIdx =
103 Abbrev->findAttributeIndex(dwarf::DW_AT_location);
104 if (!LocationIdx)
105 return std::make_pair(false, std::nullopt);
106
107
109 Abbrev->getAttributeOffsetFromIndex(*LocationIdx, DIE.getOffset(), *U);
110
111
112 std::optional LocationValue =
113 Abbrev->getAttributeValueFromOffset(*LocationIdx, AttrOffset, *U);
114 if (!LocationValue)
115 return std::make_pair(false, std::nullopt);
116
117
118
119
120 std::optional<ArrayRef<uint8_t>> Expr = LocationValue->getAsBlock();
121 if (!Expr)
122 return std::make_pair(false, std::nullopt);
123
124
126 U->getAddressByteSize());
128 U->getFormParams().Format);
129
130 bool HasLocationAddress = false;
135 ++NextIt;
136
138 switch (Op.getCode()) {
139 case dwarf::DW_OP_const2u:
140 case dwarf::DW_OP_const4u:
141 case dwarf::DW_OP_const8u:
142 case dwarf::DW_OP_const2s:
143 case dwarf::DW_OP_const4s:
144 case dwarf::DW_OP_const8s:
146 break;
147 [[fallthrough]];
148 case dwarf::DW_OP_addr: {
149 HasLocationAddress = true;
150
151 if (std::optional<int64_t> RelocAdjustment =
153 *U, Op, AttrOffset + CurExprOffset,
154 AttrOffset + Op.getEndOffset(), Verbose))
155 return std::make_pair(HasLocationAddress, *RelocAdjustment);
156 } break;
157 case dwarf::DW_OP_constx:
158 case dwarf::DW_OP_addrx: {
159 HasLocationAddress = true;
160 if (std::optional<uint64_t> AddressOffset =
161 DIE.getDwarfUnit()->getIndexedAddressOffset(
162 Op.getRawOperand(0))) {
163
164 if (std::optional<int64_t> RelocAdjustment =
166 *U, Op, *AddressOffset,
167 *AddressOffset + DIE.getDwarfUnit()->getAddressByteSize(),
169 return std::make_pair(HasLocationAddress, *RelocAdjustment);
170 }
171 } break;
172 default: {
173
174 } break;
175 }
176 CurExprOffset = Op.getEndOffset();
177 }
178
179 return std::make_pair(HasLocationAddress, std::nullopt);
180 }
181
182protected:
184 return DW_OP_Code == dwarf::DW_OP_form_tls_address ||
185 DW_OP_Code == dwarf::DW_OP_GNU_push_tls_address;
186 }
187};
188
189}
190}
191
192#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AddressRangesMap class maps values to the address ranges.
A structured debug information entry.
unsigned getOffset() const
Get the compile/type unit relative offset of this DIE.
dwarf::Tag getTag() const
Utility class that carries the DWARF compile/type unit and the debug info entry in an object.
This class represents an Operation in the Expression.
An iterator to go through the expression operations.
Class representing an expression and its matching format.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
AddressesMap represents information about valid addresses used by debug information.
Definition AddressesMap.h:30
virtual bool hasValidRelocs()=0
Checks that there are valid relocations in the .debug_info section.
virtual void updateAndSaveValidRelocs(bool IsDWARF5, uint64_t OriginalUnitOffset, int64_t LinkedOffset, uint64_t StartOffset, uint64_t EndOffset)=0
Update and save relocation values to be serialized.
virtual void clear()=0
Erases all data.
virtual bool needToSaveValidRelocs()=0
Check if the linker needs to gather and save relocation info.
virtual std::optional< StringRef > getLibraryInstallName()=0
virtual ~AddressesMap()=default
bool isTlsAddressCode(uint8_t DW_OP_Code)
Definition AddressesMap.h:183
virtual bool applyValidRelocs(MutableArrayRef< char > Data, uint64_t BaseOffset, bool IsLittleEndian)=0
Apply the valid relocations to the buffer Data, taking into account that Data is at BaseOffset in the...
virtual std::optional< int64_t > getExprOpAddressRelocAdjustment(DWARFUnit &U, const DWARFExpression::Operation &Op, uint64_t StartOffset, uint64_t EndOffset, bool Verbose)=0
Checks that the specified DWARF expression operand Op references live code section and returns the re...
virtual void updateRelocationsWithUnitOffset(uint64_t OriginalUnitOffset, uint64_t OutputUnitOffset)=0
Update the valid relocations that used OriginalUnitOffset as the compile unit offset,...
std::pair< bool, std::optional< int64_t > > getVariableRelocAdjustment(const DWARFDie &DIE, bool Verbose)
This function checks whether variable has DWARF expression containing operation referencing live addr...
Definition AddressesMap.h:93
virtual std::optional< int64_t > getSubprogramRelocAdjustment(const DWARFDie &DIE, bool Verbose)=0
Checks that the specified subprogram DIE references the live code section and returns the relocation ...
AddressRangesMap RangesTy
Mapped value in the address map is the offset to apply to the linked address.
Definition AddressesMap.h:24
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
DWARFExpression::Operation Op
StringRef toStringRef(bool B)
Construct a string ref from a boolean.