[PATCH] D140788: [DWARFLinkerNext] add AddressesMap interface.

Alexey Lapshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 30 12:33:51 PST 2022


avl created this revision.
avl added reviewers: JDevlieghere, clayborg, aprantl, dblaikie.
Herald added a project: All.
avl requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This patch is extracted from D96035 <https://reviews.llvm.org/D96035>. It adds AddressesMap map interface
to the DWARFLinkerNext library. This interface fully match with the
paired interface from the DWARFLinker library, except that it does
not depend on DIEInfo class.

Depends on D140787 <https://reviews.llvm.org/D140787>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140788

Files:
  llvm/include/llvm/DWARFLinkerNext/AddressesMap.h


Index: llvm/include/llvm/DWARFLinkerNext/AddressesMap.h
===================================================================
--- /dev/null
+++ llvm/include/llvm/DWARFLinkerNext/AddressesMap.h
@@ -0,0 +1,67 @@
+//===- 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 <cstdint>
+
+namespace llvm {
+namespace dwarflinker {
+
+/// Mapped value in the address map is the offset to apply to the
+/// linked address.
+using RangesTy = AddressRangesMap<int64_t>;
+
+/// 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.
+  /// Allowed kind of input die: DW_TAG_variable, DW_TAG_constant.
+  /// \returns true and sets AddrAdjust if it is the case.
+  virtual bool isLiveVariable(const DWARFDie &DIE, int64_t &AddrAdjust) = 0;
+
+  /// Checks that the specified subprogram \p DIE references live code section.
+  /// Allowed kind of input die: DW_TAG_subprogram, DW_TAG_label.
+  /// \returns true and sets AddrAdjust if it is the case.
+  virtual bool isLiveSubprogram(const DWARFDie &DIE, int64_t &AddrAdjust) = 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<char> Data, uint64_t BaseOffset,
+                                bool IsLittleEndian) = 0;
+
+  /// Relocate the given address offset if a valid relocation exists.
+  virtual llvm::Expected<uint64_t> 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140788.485724.patch
Type: text/x-patch
Size: 2922 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221230/f93722aa/attachment.bin>


More information about the llvm-commits mailing list