9#ifndef LLVM_DWARFLINKER_ADDRESSESMAP_H
10#define LLVM_DWARFLINKER_ADDRESSESMAP_H
59 std::optional<uint64_t> AddrOffset =
60 U.getIndexedAddressOffset(
Op.getRawOperand(0));
64 U,
Op, *AddrOffset, *AddrOffset + U.getAddressByteSize(),
Verbose);
74 virtual std::optional<int64_t>
85 bool IsLittleEndian) = 0;
120 virtual std::optional<uint64_t>
133 int64_t Adjustment) {
137 assert(Symbol->LowPC <= LowPC && LowPC < Symbol->HighPC &&
138 "Symbol range must contain the address it was looked up for");
139 uint64_t LinkedSymbolHighPC = Symbol->HighPC + Adjustment;
140 assert(LinkedSymbolHighPC > Symbol->LowPC + Adjustment &&
141 "Adjusting a symbol range must preserve its order");
142 std::optional<uint64_t> NextStart =
146 assert(*NextStart >= LinkedSymbolHighPC &&
147 "A range must never be cut short of its own symbol");
148 return std::min(HighPC, *NextStart - Adjustment);
157 std::pair<bool, std::optional<int64_t>>
160 DIE.
getTag() == dwarf::DW_TAG_constant) &&
161 "Wrong type of input die");
163 const auto *Abbrev =
DIE.getAbbreviationDeclarationPtr();
167 std::optional<uint32_t> LocationIdx =
168 Abbrev->findAttributeIndex(dwarf::DW_AT_location);
170 return std::make_pair(
false, std::nullopt);
174 Abbrev->getAttributeOffsetFromIndex(*LocationIdx,
DIE.
getOffset(), *U);
177 std::optional<DWARFFormValue> LocationValue =
178 Abbrev->getAttributeValueFromOffset(*LocationIdx, AttrOffset, *U);
180 return std::make_pair(
false, std::nullopt);
185 std::optional<ArrayRef<uint8_t>> Expr = LocationValue->getAsBlock();
187 return std::make_pair(
false, std::nullopt);
192 U->getFormParams().Format);
194 bool HasLocationAddress =
false;
202 switch (
Op.getCode()) {
203 case dwarf::DW_OP_const2u:
204 case dwarf::DW_OP_const4u:
205 case dwarf::DW_OP_const8u:
206 case dwarf::DW_OP_const2s:
207 case dwarf::DW_OP_const4s:
208 case dwarf::DW_OP_const8s:
213 case dwarf::DW_OP_addr: {
214 HasLocationAddress =
true;
216 if (std::optional<int64_t> RelocAdjustment =
218 *U,
Op, AttrOffset + CurExprOffset,
219 AttrOffset +
Op.getEndOffset(),
Verbose))
220 return std::make_pair(HasLocationAddress, *RelocAdjustment);
222 case dwarf::DW_OP_constx:
223 case dwarf::DW_OP_addrx: {
224 HasLocationAddress =
true;
225 if (std::optional<uint64_t> AddressOffset =
226 DIE.getDwarfUnit()->getIndexedAddressOffset(
227 Op.getRawOperand(0))) {
229 if (std::optional<int64_t> RelocAdjustment =
231 *U,
Op, *AddressOffset,
232 *AddressOffset +
DIE.getDwarfUnit()->getAddressByteSize(),
234 return std::make_pair(HasLocationAddress, *RelocAdjustment);
241 CurExprOffset =
Op.getEndOffset();
244 return std::make_pair(HasLocationAddress, std::nullopt);
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.
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
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 clear()=0
Erases all data.
virtual std::optional< uint64_t > getNextLinkedSymbolStart(uint64_t LinkedAddr)
Returns the linked address of the first symbol placed at or after LinkedAddr, if one is known.
virtual bool needToSaveValidRelocs()=0
Check if the linker needs to gather and save relocation info.
virtual std::optional< StringRef > getLibraryInstallName()=0
virtual ~AddressesMap()=default
std::optional< int64_t > getAddrIndexRelocAdjustment(DWARFUnit &U, const DWARFExpression::Operation &Op, bool Verbose)
Returns the relocation adjustment value for the .debug_addr entry that the DW_OP_addrx or DW_OP_const...
uint64_t constrainCodeRangeHighPC(uint64_t LowPC, uint64_t HighPC, int64_t Adjustment)
Constrains the end of the code range starting at LowPC, whose addresses shift by Adjustment in the ou...
virtual std::optional< SymbolRange > getSymbolRangeForAddress(uint64_t Addr)
Returns the symbol range [LowPC, HighPC) containing Addr, if known.
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 bool updateAndSaveValidRelocs(RelocSectionKind InSection, RelocSectionKind OutSection, uint64_t OriginalUnitOffset, int64_t LinkedOffset, uint64_t StartOffset, uint64_t EndOffset)=0
Save the valid relocations in [StartOffset, EndOffset) of InSection, moved by LinkedOffset into OutSe...
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...
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.
RelocSectionKind
The debug sections holding relocations which the linker can save.
bool isTlsAddressOp(uint8_t O)
This is an optimization pass for GlobalISel generic memory operations.
DWARFExpression::Operation Op
SymbolRange(uint64_t LowPC, uint64_t HighPC)