[llvm] 1358df4 - [DWARFLinkerParallel] add AddressesMap interface.

Alexey Lapshin via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 15 10:45:05 PDT 2023


Author: Alexey Lapshin
Date: 2023-03-15T18:43:45+01:00
New Revision: 1358df4dc4a9f8193767f2bd03ef4d8e9f04ace6

URL: https://github.com/llvm/llvm-project/commit/1358df4dc4a9f8193767f2bd03ef4d8e9f04ace6
DIFF: https://github.com/llvm/llvm-project/commit/1358df4dc4a9f8193767f2bd03ef4d8e9f04ace6.diff

LOG: [DWARFLinkerParallel] add AddressesMap interface.

This patch is extracted from D96035. It adds AddressesMap map interface
to the DWARFLinkerParallel library. This interface mostly match with the
paired interface from the DWARFLinker library, except that it does
not depend on DIEInfo class.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D140788

Added: 
    llvm/include/llvm/DWARFLinkerParallel/AddressesMap.h

Modified: 
    llvm/include/llvm/DWARFLinkerParallel/DWARFLinker.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/DWARFLinkerParallel/AddressesMap.h b/llvm/include/llvm/DWARFLinkerParallel/AddressesMap.h
new file mode 100644
index 0000000000000..eadd7120f70c7
--- /dev/null
+++ b/llvm/include/llvm/DWARFLinkerParallel/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_DWARFLINKERPARALLEL_ADDRESSESMAP_H
+#define LLVM_DWARFLINKERPARALLEL_ADDRESSESMAP_H
+
+#include "llvm/ADT/AddressRanges.h"
+#include "llvm/DebugInfo/DWARF/DWARFDie.h"
+#include <cstdint>
+
+namespace llvm {
+namespace dwarflinker_parallel {
+
+/// 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 in the .debug_info
+  /// section.
+  virtual bool hasValidRelocs() = 0;
+
+  /// Checks that the specified variable \p DIE references the live code
+  /// section and returns the relocation adjustment value (to get the linked
+  /// address this value might be added to the source variable address).
+  /// Allowed kinds of input DIE: DW_TAG_variable, DW_TAG_constant.
+  /// \returns relocation adjustment value or std::nullopt if there is no
+  /// corresponding live address.
+  virtual std::optional<int64_t>
+  getVariableRelocAdjustment(const DWARFDie &DIE) = 0;
+
+  /// Checks that the specified subprogram \p DIE references the live code
+  /// section and returns the relocation adjustment value (to get the linked
+  /// address this value might be added to the source subprogram address).
+  /// Allowed kinds of input DIE: DW_TAG_subprogram, DW_TAG_label.
+  /// \returns relocation adjustment value or std::nullopt if there is no
+  /// corresponding live address.
+  virtual std::optional<int64_t>
+  getSubprogramRelocAdjustment(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<char> Data, uint64_t BaseOffset,
+                                bool IsLittleEndian) = 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_parallel
+} // end namespace llvm
+
+#endif // LLVM_DWARFLINKERPARALLEL_ADDRESSESMAP_H

diff  --git a/llvm/include/llvm/DWARFLinkerParallel/DWARFLinker.h b/llvm/include/llvm/DWARFLinkerParallel/DWARFLinker.h
index b1169fdd85412..b7f9b94dca0e6 100644
--- a/llvm/include/llvm/DWARFLinkerParallel/DWARFLinker.h
+++ b/llvm/include/llvm/DWARFLinkerParallel/DWARFLinker.h
@@ -9,6 +9,8 @@
 #ifndef LLVM_DWARFLINKERPARALLEL_DWARFLINKER_H
 #define LLVM_DWARFLINKERPARALLEL_DWARFLINKER_H
 
+#include "llvm/DWARFLinkerParallel/AddressesMap.h"
+
 namespace llvm {
 namespace dwarflinker_parallel {} // end namespace dwarflinker_parallel
 } // end namespace llvm


        


More information about the llvm-commits mailing list