9#ifndef LLVM_DWARFLINKER_ADDRESSESMAP_H
10#define LLVM_DWARFLINKER_ADDRESSESMAP_H
55 virtual std::optional<int64_t>
66 bool IsLittleEndian) = 0;
97 virtual std::optional<AssemblyRange>
108 std::pair<bool, std::optional<int64_t>>
111 DIE.
getTag() == dwarf::DW_TAG_constant) &&
112 "Wrong type of input die");
114 const auto *Abbrev =
DIE.getAbbreviationDeclarationPtr();
118 std::optional<uint32_t> LocationIdx =
119 Abbrev->findAttributeIndex(dwarf::DW_AT_location);
121 return std::make_pair(
false, std::nullopt);
125 Abbrev->getAttributeOffsetFromIndex(*LocationIdx,
DIE.
getOffset(), *U);
128 std::optional<DWARFFormValue> LocationValue =
129 Abbrev->getAttributeValueFromOffset(*LocationIdx, AttrOffset, *U);
131 return std::make_pair(
false, std::nullopt);
136 std::optional<ArrayRef<uint8_t>> Expr = LocationValue->getAsBlock();
138 return std::make_pair(
false, std::nullopt);
142 U->getAddressByteSize());
144 U->getFormParams().Format);
146 bool HasLocationAddress =
false;
154 switch (
Op.getCode()) {
155 case dwarf::DW_OP_const2u:
156 case dwarf::DW_OP_const4u:
157 case dwarf::DW_OP_const8u:
158 case dwarf::DW_OP_const2s:
159 case dwarf::DW_OP_const4s:
160 case dwarf::DW_OP_const8s:
164 case dwarf::DW_OP_addr: {
165 HasLocationAddress =
true;
167 if (std::optional<int64_t> RelocAdjustment =
169 *U,
Op, AttrOffset + CurExprOffset,
170 AttrOffset +
Op.getEndOffset(),
Verbose))
171 return std::make_pair(HasLocationAddress, *RelocAdjustment);
173 case dwarf::DW_OP_constx:
174 case dwarf::DW_OP_addrx: {
175 HasLocationAddress =
true;
176 if (std::optional<uint64_t> AddressOffset =
177 DIE.getDwarfUnit()->getIndexedAddressOffset(
178 Op.getRawOperand(0))) {
180 if (std::optional<int64_t> RelocAdjustment =
182 *U,
Op, *AddressOffset,
183 *AddressOffset +
DIE.getDwarfUnit()->getAddressByteSize(),
185 return std::make_pair(HasLocationAddress, *RelocAdjustment);
192 CurExprOffset =
Op.getEndOffset();
195 return std::make_pair(HasLocationAddress, std::nullopt);
200 return DW_OP_Code == dwarf::DW_OP_form_tls_address ||
201 DW_OP_Code == dwarf::DW_OP_GNU_push_tls_address;
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.
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)
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 std::optional< AssemblyRange > getAssemblyRangeForAddress(uint64_t Addr)
Returns the address range containing Addr if available.
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...
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.
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.
AssemblyRange(uint64_t LowPC, uint64_t HighPC)