diff --git a/llvm/include/llvm/DWARFLinkerNext/AddressesMap.h b/llvm/include/llvm/DWARFLinkerNext/AddressesMap.h new file mode 100644 --- /dev/null +++ b/llvm/include/llvm/DWARFLinkerNext/AddressesMap.h @@ -0,0 +1,71 @@ +//===- AddressesMap.h -------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DWARFLINKERNEXT_ADDRESSESMAP_H +#define LLVM_DWARFLINKERNEXT_ADDRESSESMAP_H + +#include "llvm/ADT/AddressRanges.h" +#include "llvm/DebugInfo/DWARF/DWARFDie.h" +#include + +namespace llvm { +namespace dwarflinker { + +/// Mapped value in the address map is the offset to apply to the +/// linked address. +using RangesTy = AddressRangesMap; + +/// AddressesMap represents information about valid addresses used +/// by debug information. Valid addresses are those which points to +/// live code sections. i.e. relocations for these addresses point +/// into sections which would be/are placed into resulting binary. +class AddressesMap { +public: + virtual ~AddressesMap() = default; + + /// Checks that there are valid relocations against a .debug_info + /// section. + virtual bool hasValidRelocs() = 0; + + /// Checks that the specified variable \p DIE references live code section + /// and returns variable address. Allowed kind of input die: DW_TAG_variable, + /// DW_TAG_constant. + /// \returns address value or std::nullopt if there is not corresponding live + /// address. + virtual std::optional getVariableAddress(const DWARFDie &DIE) = 0; + + /// Checks that the specified subprogram \p DIE references live code section + /// and returns subprogram address. Allowed kind of input die: + /// DW_TAG_subprogram, DW_TAG_label. + /// \returns address value or std::nullopt if there is not corresponding live + /// address. + virtual std::optional getSubprogramAddress(const DWARFDie &DIE) = 0; + + /// Apply the valid relocations to the buffer \p Data, taking into + /// account that Data is at \p BaseOffset in the .debug_info section. + /// + /// \returns true whether any reloc has been applied. + virtual bool applyValidRelocs(MutableArrayRef Data, uint64_t BaseOffset, + bool IsLittleEndian) = 0; + + /// Relocate the given address offset if a valid relocation exists. + virtual llvm::Expected relocateIndexedAddr(uint64_t StartOffset, + uint64_t EndOffset) = 0; + + /// Returns all valid functions address ranges(i.e., those ranges + /// which points to sections with code). + virtual RangesTy &getValidAddressRanges() = 0; + + /// Erases all data. + virtual void clear() = 0; +}; + +} // end of namespace dwarflinker +} // end namespace llvm + +#endif // LLVM_DWARFLINKERNEXT_ADDRESSESMAP_H