9#ifndef LLVM_DWARFLINKER_ADDRESSESMAP_H
10#define LLVM_DWARFLINKER_ADDRESSESMAP_H
55 virtual std::optional<int64_t>
66 bool IsLittleEndian) = 0;
92 std::pair<bool, std::optional<int64_t>>
95 DIE.
getTag() == dwarf::DW_TAG_constant) &&
96 "Wrong type of input die");
98 const auto *Abbrev =
DIE.getAbbreviationDeclarationPtr();
102 std::optional<uint32_t> LocationIdx =
103 Abbrev->findAttributeIndex(dwarf::DW_AT_location);
105 return std::make_pair(
false, std::nullopt);
109 Abbrev->getAttributeOffsetFromIndex(*LocationIdx,
DIE.
getOffset(), *U);
112 std::optional<DWARFFormValue> LocationValue =
113 Abbrev->getAttributeValueFromOffset(*LocationIdx, AttrOffset, *U);
115 return std::make_pair(
false, std::nullopt);
120 std::optional<ArrayRef<uint8_t>> Expr = LocationValue->getAsBlock();
122 return std::make_pair(
false, std::nullopt);
126 U->getAddressByteSize());
128 U->getFormParams().Format);
130 bool HasLocationAddress =
false;
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:
148 case dwarf::DW_OP_addr: {
149 HasLocationAddress =
true;
151 if (std::optional<int64_t> RelocAdjustment =
153 *U,
Op, AttrOffset + CurExprOffset,
154 AttrOffset +
Op.getEndOffset(),
Verbose))
155 return std::make_pair(HasLocationAddress, *RelocAdjustment);
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))) {
164 if (std::optional<int64_t> RelocAdjustment =
166 *U,
Op, *AddressOffset,
167 *AddressOffset +
DIE.getDwarfUnit()->getAddressByteSize(),
169 return std::make_pair(HasLocationAddress, *RelocAdjustment);
176 CurExprOffset =
Op.getEndOffset();
179 return std::make_pair(HasLocationAddress, std::nullopt);
184 return DW_OP_Code == dwarf::DW_OP_form_tls_address ||
185 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 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.