[llvm] [dsymutil][DWARFLinker] Refactor handling mergeable libraries. (PR #80615)

Alexey Lapshin via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 28 13:24:28 PDT 2024


https://github.com/avl-llvm updated https://github.com/llvm/llvm-project/pull/80615

>From 8ca3625183f66d208a1a0fb5286eec0da47223b4 Mon Sep 17 00:00:00 2001
From: Alexey Lapshin <a.v.lapshin at mail.ru>
Date: Thu, 1 Feb 2024 22:29:49 +0300
Subject: [PATCH] [dsymutil][DWARFLinker] Refactor handling mergeable
 libraries.

This patch refactors working with mergeable libraries.
Instead of storing relocations pointing to address attributes
of mergeable libraries, this patch links address attributes
through the new debug map. This solution significantly simplifies
attributes handling(no need to track attribute offsets), minimizes
size of dSYM bundle and run-time memory requirements:

1. Link mergeable library as usual. Do not create new set of relocations.
2. When linked mergeable library is used as part of another library -
   read address attribute, link it through the new debug map,
   store linked value.
---
 llvm/include/llvm/DWARFLinker/AddressesMap.h  |  23 +-
 llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp  |  33 +--
 .../DWARFLinker/Parallel/DWARFLinkerImpl.cpp  |   4 +-
 llvm/tools/dsymutil/CMakeLists.txt            |   1 -
 llvm/tools/dsymutil/DebugMap.cpp              |   8 +-
 llvm/tools/dsymutil/DebugMap.h                |  37 ++-
 llvm/tools/dsymutil/DwarfLinkerForBinary.cpp  | 226 +++++++-----------
 llvm/tools/dsymutil/DwarfLinkerForBinary.h    | 120 +++-------
 llvm/tools/dsymutil/MachODebugMapParser.cpp   |  36 +--
 llvm/tools/dsymutil/RelocationMap.cpp         |  92 -------
 llvm/tools/dsymutil/RelocationMap.h           | 160 -------------
 llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp |  12 +-
 12 files changed, 172 insertions(+), 580 deletions(-)
 delete mode 100644 llvm/tools/dsymutil/RelocationMap.cpp
 delete mode 100644 llvm/tools/dsymutil/RelocationMap.h

diff --git a/llvm/include/llvm/DWARFLinker/AddressesMap.h b/llvm/include/llvm/DWARFLinker/AddressesMap.h
index a232aafadc5ce9..a521cc808c2783 100644
--- a/llvm/include/llvm/DWARFLinker/AddressesMap.h
+++ b/llvm/include/llvm/DWARFLinker/AddressesMap.h
@@ -31,9 +31,8 @@ class AddressesMap {
 public:
   virtual ~AddressesMap() = default;
 
-  /// Checks that there are valid relocations in the .debug_info
-  /// section.
-  virtual bool hasValidRelocs() = 0;
+  /// Check if we can quickly detect that there is no any live debug info.
+  virtual bool hasLiveDebugInfo() = 0;
 
   /// Checks that the specified DWARF expression operand \p Op references live
   /// code section and returns the relocation adjustment value (to get the
@@ -65,24 +64,6 @@ class AddressesMap {
   virtual bool applyValidRelocs(MutableArrayRef<char> Data, uint64_t BaseOffset,
                                 bool IsLittleEndian) = 0;
 
-  /// Check if the linker needs to gather and save relocation info.
-  virtual bool needToSaveValidRelocs() = 0;
-
-  /// Update and save relocation values to be serialized
-  virtual void updateAndSaveValidRelocs(bool IsDWARF5,
-                                        uint64_t OriginalUnitOffset,
-                                        int64_t LinkedOffset,
-                                        uint64_t StartOffset,
-                                        uint64_t EndOffset) = 0;
-
-  /// Update the valid relocations that used OriginalUnitOffset as the compile
-  /// unit offset, and update their values to reflect OutputUnitOffset.
-  virtual void updateRelocationsWithUnitOffset(uint64_t OriginalUnitOffset,
-                                               uint64_t OutputUnitOffset) = 0;
-
-  /// Erases all data.
-  virtual void clear() = 0;
-
   /// This function checks whether variable has DWARF expression containing
   /// operation referencing live address(f.e. DW_OP_addr, DW_OP_addrx...).
   /// \returns first is true if the expression has an operation referencing an
diff --git a/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp b/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
index 60f664ece7eef9..8b8a486f350158 100644
--- a/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
+++ b/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
@@ -1653,12 +1653,6 @@ shouldSkipAttribute(bool Update,
   }
 }
 
-struct AttributeLinkedOffsetFixup {
-  int64_t LinkedOffsetFixupVal;
-  uint64_t InputAttrStartOffset;
-  uint64_t InputAttrEndOffset;
-};
-
 DIE *DWARFLinker::DIECloner::cloneDIE(const DWARFDie &InputDIE,
                                       const DWARFFile &File, CompileUnit &Unit,
                                       int64_t PCOffset, uint32_t OutOffset,
@@ -1744,7 +1738,6 @@ DIE *DWARFLinker::DIECloner::cloneDIE(const DWARFDie &InputDIE,
 
   std::optional<StringRef> LibraryInstallName =
       ObjFile.Addresses->getLibraryInstallName();
-  SmallVector<AttributeLinkedOffsetFixup> AttributesFixups;
   for (const auto &AttrSpec : Abbrev->attributes()) {
     if (shouldSkipAttribute(Update, AttrSpec, Flags & TF_SkipPC)) {
       DWARFFormValue::skipValue(AttrSpec.Form, Data, &Offset,
@@ -1752,22 +1745,14 @@ DIE *DWARFLinker::DIECloner::cloneDIE(const DWARFDie &InputDIE,
       continue;
     }
 
-    AttributeLinkedOffsetFixup CurAttrFixup;
-    CurAttrFixup.InputAttrStartOffset = InputDIE.getOffset() + Offset;
-    CurAttrFixup.LinkedOffsetFixupVal =
-        Unit.getStartOffset() + OutOffset - CurAttrFixup.InputAttrStartOffset;
-
     DWARFFormValue Val = AttrSpec.getFormValue();
     uint64_t AttrSize = Offset;
     Val.extractValue(Data, &Offset, U.getFormParams(), &U);
-    CurAttrFixup.InputAttrEndOffset = InputDIE.getOffset() + Offset;
     AttrSize = Offset - AttrSize;
 
     uint64_t FinalAttrSize =
         cloneAttribute(*Die, InputDIE, File, Unit, Val, AttrSpec, AttrSize,
                        AttrInfo, IsLittleEndian);
-    if (FinalAttrSize != 0 && ObjFile.Addresses->needToSaveValidRelocs())
-      AttributesFixups.push_back(CurAttrFixup);
 
     OutOffset += FinalAttrSize;
   }
@@ -1860,15 +1845,6 @@ DIE *DWARFLinker::DIECloner::cloneDIE(const DWARFDie &InputDIE,
   // Add the size of the abbreviation number to the output offset.
   OutOffset += AbbrevNumberSize;
 
-  // Update fixups with the size of the abbreviation number
-  for (AttributeLinkedOffsetFixup &F : AttributesFixups)
-    F.LinkedOffsetFixupVal += AbbrevNumberSize;
-
-  for (AttributeLinkedOffsetFixup &F : AttributesFixups)
-    ObjFile.Addresses->updateAndSaveValidRelocs(
-        Unit.getOrigUnit().getVersion() >= 5, Unit.getOrigUnit().getOffset(),
-        F.LinkedOffsetFixupVal, F.InputAttrStartOffset, F.InputAttrEndOffset);
-
   if (!HasChildren) {
     // Update our size.
     Die->setSize(OutOffset - Die->getOffset());
@@ -2718,12 +2694,9 @@ Error DWARFLinker::link() {
     if (Options.VerifyInputDWARF)
       verifyInput(OptContext.File);
 
-    // Look for relocations that correspond to address map entries.
-
-    // there was findvalidrelocations previously ... probably we need to gather
-    // info here
+    // Check if we can skip linking.
     if (LLVM_LIKELY(!Options.Update) &&
-        !OptContext.File.Addresses->hasValidRelocs()) {
+        !OptContext.File.Addresses->hasLiveDebugInfo()) {
       if (Options.Verbose)
         outs() << "No valid relocations found. Skipping.\n";
 
@@ -2853,7 +2826,7 @@ Error DWARFLinker::link() {
     // The calls to applyValidRelocs inside cloneDIE will walk the reloc
     // array again (in the same way findValidRelocsInDebugInfo() did). We
     // need to reset the NextValidReloc index to the beginning.
-    if (OptContext.File.Addresses->hasValidRelocs() ||
+    if (OptContext.File.Addresses->hasLiveDebugInfo() ||
         LLVM_UNLIKELY(Options.Update)) {
       SizeByObject[OptContext.File.FileName].Input =
           getDebugInfoSize(*OptContext.File.Dwarf);
diff --git a/llvm/lib/DWARFLinker/Parallel/DWARFLinkerImpl.cpp b/llvm/lib/DWARFLinker/Parallel/DWARFLinkerImpl.cpp
index e68bf0c227a0a0..ffaab729f21568 100644
--- a/llvm/lib/DWARFLinker/Parallel/DWARFLinkerImpl.cpp
+++ b/llvm/lib/DWARFLinker/Parallel/DWARFLinkerImpl.cpp
@@ -461,7 +461,7 @@ Error DWARFLinkerImpl::LinkContext::link(TypeUnit *ArtificialTypeUnit) {
   // Check for live relocations. If there is no any live relocation then we
   // can skip entire object file.
   if (!GlobalData.getOptions().UpdateIndexTablesOnly &&
-      !InputDWARFFile.Addresses->hasValidRelocs()) {
+      !InputDWARFFile.Addresses->hasLiveDebugInfo()) {
     if (GlobalData.getOptions().Verbose)
       outs() << "No valid relocations found. Skipping.\n";
     return Error::success();
@@ -668,7 +668,7 @@ void DWARFLinkerImpl::LinkContext::linkSingleCompileUnit(
           // Clone input compile unit.
           if (CU.isClangModule() ||
               GlobalData.getOptions().UpdateIndexTablesOnly ||
-              CU.getContaingFile().Addresses->hasValidRelocs()) {
+              CU.getContaingFile().Addresses->hasLiveDebugInfo()) {
             if (Error Err = CU.cloneAndEmit(GlobalData.getTargetTriple(),
                                             ArtificialTypeUnit))
               return std::move(Err);
diff --git a/llvm/tools/dsymutil/CMakeLists.txt b/llvm/tools/dsymutil/CMakeLists.txt
index efe28bda68ebf1..b4251ca5931f1c 100644
--- a/llvm/tools/dsymutil/CMakeLists.txt
+++ b/llvm/tools/dsymutil/CMakeLists.txt
@@ -31,7 +31,6 @@ add_llvm_tool(dsymutil
   MachODebugMapParser.cpp
   MachOUtils.cpp
   Reproducer.cpp
-  RelocationMap.cpp
 
   DEPENDS
   intrinsics_gen
diff --git a/llvm/tools/dsymutil/DebugMap.cpp b/llvm/tools/dsymutil/DebugMap.cpp
index 8724b70422f326..a69f0c919db3b8 100644
--- a/llvm/tools/dsymutil/DebugMap.cpp
+++ b/llvm/tools/dsymutil/DebugMap.cpp
@@ -58,10 +58,6 @@ bool DebugMapObject::addSymbol(StringRef Name,
   return InsertResult.second;
 }
 
-void DebugMapObject::setRelocationMap(dsymutil::RelocationMap &RM) {
-  RelocMap.emplace(RM);
-}
-
 void DebugMapObject::setInstallName(StringRef IN) { InstallName.emplace(IN); }
 
 void DebugMapObject::print(raw_ostream &OS) const {
@@ -169,8 +165,8 @@ struct MappingTraits<dsymutil::DebugMapObject>::YamlDMO {
   std::vector<dsymutil::DebugMapObject::YAMLSymbolMapping> Entries;
 };
 
-void MappingTraits<std::pair<std::string, SymbolMapping>>::mapping(
-    IO &io, std::pair<std::string, SymbolMapping> &s) {
+void MappingTraits<std::pair<std::string, DebugMapObject::SymbolMapping>>::
+    mapping(IO &io, std::pair<std::string, DebugMapObject::SymbolMapping> &s) {
   io.mapRequired("sym", s.first);
   io.mapOptional("objAddr", s.second.ObjectAddress);
   io.mapRequired("binAddr", s.second.BinaryAddress);
diff --git a/llvm/tools/dsymutil/DebugMap.h b/llvm/tools/dsymutil/DebugMap.h
index 9c3a698fa1191d..9ef7fdf16cb1e4 100644
--- a/llvm/tools/dsymutil/DebugMap.h
+++ b/llvm/tools/dsymutil/DebugMap.h
@@ -21,7 +21,6 @@
 #ifndef LLVM_TOOLS_DSYMUTIL_DEBUGMAP_H
 #define LLVM_TOOLS_DSYMUTIL_DEBUGMAP_H
 
-#include "RelocationMap.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
@@ -135,6 +134,22 @@ class DebugMap {
 /// linked binary for all the linked atoms in this object file.
 class DebugMapObject {
 public:
+  struct SymbolMapping {
+    std::optional<yaml::Hex64> ObjectAddress;
+    yaml::Hex64 BinaryAddress;
+    yaml::Hex32 Size;
+
+    SymbolMapping(std::optional<uint64_t> ObjectAddr, uint64_t BinaryAddress,
+                  uint32_t Size)
+        : BinaryAddress(BinaryAddress), Size(Size) {
+      if (ObjectAddr)
+        ObjectAddress = *ObjectAddr;
+    }
+
+    /// For YAML IO support
+    SymbolMapping() = default;
+  };
+
   using YAMLSymbolMapping = std::pair<std::string, SymbolMapping>;
   using DebugMapEntry = StringMapEntry<SymbolMapping>;
 
@@ -167,11 +182,6 @@ class DebugMapObject {
   }
   const std::vector<std::string> &getWarnings() const { return Warnings; }
 
-  const std::optional<RelocationMap> &getRelocationMap() const {
-    return RelocMap;
-  }
-  void setRelocationMap(dsymutil::RelocationMap &RM);
-
   const std::optional<std::string> &getInstallName() const {
     return InstallName;
   }
@@ -191,11 +201,10 @@ class DebugMapObject {
 
   std::string Filename;
   sys::TimePoint<std::chrono::seconds> Timestamp;
-  StringMap<struct SymbolMapping> Symbols;
+  StringMap<SymbolMapping> Symbols;
   DenseMap<uint64_t, DebugMapEntry *> AddressToMapping;
   uint8_t Type;
 
-  std::optional<RelocationMap> RelocMap;
   std::optional<std::string> InstallName;
 
   std::vector<std::string> Warnings;
@@ -223,8 +232,10 @@ namespace yaml {
 
 using namespace llvm::dsymutil;
 
-template <> struct MappingTraits<std::pair<std::string, SymbolMapping>> {
-  static void mapping(IO &io, std::pair<std::string, SymbolMapping> &s);
+template <>
+struct MappingTraits<std::pair<std::string, DebugMapObject::SymbolMapping>> {
+  static void mapping(IO &io,
+                      std::pair<std::string, DebugMapObject::SymbolMapping> &s);
   static const bool flow = true;
 };
 
@@ -233,6 +244,12 @@ template <> struct MappingTraits<dsymutil::DebugMapObject> {
   static void mapping(IO &io, dsymutil::DebugMapObject &DMO);
 };
 
+template <> struct ScalarTraits<Triple> {
+  static void output(const Triple &val, void *, raw_ostream &out);
+  static StringRef input(StringRef scalar, void *, Triple &value);
+  static QuotingType mustQuote(StringRef) { return QuotingType::Single; }
+};
+
 template <>
 struct SequenceTraits<std::vector<std::unique_ptr<dsymutil::DebugMapObject>>> {
   static size_t
diff --git a/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp b/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
index 677dfc44c54a40..495f5bd4a5ec3f 100644
--- a/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
+++ b/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
@@ -188,42 +188,6 @@ static Error remarksErrorHandler(const DebugMapObject &DMO,
 
   return createFileError(FE->getFileName(), std::move(NewE));
 }
-Error DwarfLinkerForBinary::emitRelocations(
-    const DebugMap &DM, std::vector<ObjectWithRelocMap> &ObjectsForLinking) {
-  // Return early if the "Resources" directory is not being written to.
-  if (!Options.ResourceDir)
-    return Error::success();
-
-  RelocationMap RM(DM.getTriple(), DM.getBinaryPath());
-  for (auto &Obj : ObjectsForLinking) {
-    if (!Obj.OutRelocs->isInitialized())
-      continue;
-    Obj.OutRelocs->addValidRelocs(RM);
-  }
-
-  SmallString<128> InputPath;
-  SmallString<128> Path;
-  // Create the "Relocations" directory in the "Resources" directory, and
-  // create an architecture-specific directory in the "Relocations" directory.
-  StringRef ArchName = Triple::getArchName(RM.getTriple().getArch(),
-                                           RM.getTriple().getSubArch());
-  sys::path::append(Path, *Options.ResourceDir, "Relocations", ArchName);
-  if (std::error_code EC = sys::fs::create_directories(Path.str(), true,
-                                                       sys::fs::perms::all_all))
-    return errorCodeToError(EC);
-
-  // Append the file name.
-  sys::path::append(Path, sys::path::filename(DM.getBinaryPath()));
-  Path.append(".yml");
-
-  std::error_code EC;
-  raw_fd_ostream OS(Path.str(), EC, sys::fs::OF_Text);
-  if (EC)
-    return errorCodeToError(EC);
-
-  RM.print(OS);
-  return Error::success();
-}
 
 static Error emitRemarks(const LinkOptions &Options, StringRef BinaryPath,
                          StringRef ArchName, const remarks::RemarkLinker &RL) {
@@ -263,10 +227,10 @@ static Error emitRemarks(const LinkOptions &Options, StringRef BinaryPath,
   return Error::success();
 }
 
-ErrorOr<std::unique_ptr<DWARFFile>> DwarfLinkerForBinary::loadObject(
-    const DebugMapObject &Obj, const DebugMap &DebugMap,
-    remarks::RemarkLinker &RL,
-    std::shared_ptr<DwarfLinkerForBinaryRelocationMap> DLBRM) {
+ErrorOr<std::unique_ptr<DWARFFile>>
+DwarfLinkerForBinary::loadObject(const DebugMapObject &Obj,
+                                 const DebugMap &DebugMap,
+                                 remarks::RemarkLinker &RL) {
   auto ErrorOrObj = loadObject(Obj, DebugMap.getTriple());
   std::unique_ptr<DWARFFile> Res;
 
@@ -284,10 +248,9 @@ ErrorOr<std::unique_ptr<DWARFFile>> DwarfLinkerForBinary::loadObject(
             reportWarning(Info.message());
           });
         });
-    DLBRM->init(*Context);
     Res = std::make_unique<DWARFFile>(
         Obj.getObjectFilename(), std::move(Context),
-        std::make_unique<AddressManager>(*this, *ErrorOrObj, Obj, DLBRM),
+        std::make_unique<AddressManager>(*this, *ErrorOrObj, Obj),
         [&](StringRef FileName) { BinHolder.eraseObjectEntry(FileName); });
 
     Error E = RL.link(*ErrorOrObj);
@@ -630,7 +593,7 @@ template <typename Linker>
 bool DwarfLinkerForBinary::linkImpl(
     const DebugMap &Map, typename Linker::OutputFileType ObjectType) {
 
-  std::vector<ObjectWithRelocMap> ObjectsForLinking;
+  std::vector<std::unique_ptr<DWARFFile>> ObjectsForLinking;
 
   DebugMap DebugMap(Map.getTriple(), Map.getBinaryPath());
 
@@ -697,11 +660,10 @@ bool DwarfLinkerForBinary::linkImpl(
     auto &Obj = DebugMap.addDebugMapObject(
         Path, sys::TimePoint<std::chrono::seconds>(), MachO::N_OSO);
 
-    auto DLBRelocMap = std::make_shared<DwarfLinkerForBinaryRelocationMap>();
     if (ErrorOr<std::unique_ptr<DWARFFile>> ErrorOrObj =
-            loadObject(Obj, DebugMap, RL, DLBRelocMap)) {
-      ObjectsForLinking.emplace_back(std::move(*ErrorOrObj), DLBRelocMap);
-      return *ObjectsForLinking.back().Object;
+            loadObject(Obj, DebugMap, RL)) {
+      ObjectsForLinking.emplace_back(std::move(*ErrorOrObj));
+      return *ObjectsForLinking.back();
     } else {
       // Try and emit more helpful warnings by applying some heuristics.
       StringRef ObjFile = ContainerName;
@@ -812,18 +774,15 @@ bool DwarfLinkerForBinary::linkImpl(
       continue;
     }
 
-    auto DLBRelocMap = std::make_shared<DwarfLinkerForBinaryRelocationMap>();
     if (ErrorOr<std::unique_ptr<DWARFFile>> ErrorOrObj =
-            loadObject(*Obj, Map, RL, DLBRelocMap)) {
-      ObjectsForLinking.emplace_back(std::move(*ErrorOrObj), DLBRelocMap);
-      GeneralLinker->addObjectFile(*ObjectsForLinking.back().Object, Loader,
+            loadObject(*Obj, Map, RL)) {
+      ObjectsForLinking.emplace_back(std::move(*ErrorOrObj));
+      GeneralLinker->addObjectFile(*ObjectsForLinking.back(), Loader,
                                    OnCUDieLoaded);
     } else {
-      ObjectsForLinking.push_back(
-          {std::make_unique<DWARFFile>(Obj->getObjectFilename(), nullptr,
-                                       nullptr),
-           DLBRelocMap});
-      GeneralLinker->addObjectFile(*ObjectsForLinking.back().Object);
+      ObjectsForLinking.push_back({std::make_unique<DWARFFile>(
+          Obj->getObjectFilename(), nullptr, nullptr)});
+      GeneralLinker->addObjectFile(*ObjectsForLinking.back());
     }
   }
 
@@ -848,9 +807,6 @@ bool DwarfLinkerForBinary::linkImpl(
   if (Options.NoOutput)
     return true;
 
-  if (Error E = emitRelocations(Map, ObjectsForLinking))
-    return error(toString(std::move(E)));
-
   if (Options.ResourceDir && !ParseableSwiftInterfaces.empty()) {
     StringRef ArchName = Triple::getArchTypeName(Map.getTriple().getArch());
     if (auto E = copySwiftInterfaces(ArchName))
@@ -935,14 +891,12 @@ void DwarfLinkerForBinary::AddressManager::findValidRelocsMachO(
         continue;
       }
       if (const auto *Mapping = DMO.lookupSymbol(*SymbolName))
-        ValidRelocs.emplace_back(Offset64, RelocSize, Addend, Mapping->getKey(),
-                                 Mapping->getValue());
+        ValidRelocs.emplace_back(Offset64, RelocSize, Addend, Mapping);
     } else if (const auto *Mapping = DMO.lookupObjectAddress(SymAddress)) {
       // Do not store the addend. The addend was the address of the symbol in
       // the object file, the address in the binary that is stored in the debug
       // map doesn't need to be offset.
-      ValidRelocs.emplace_back(Offset64, RelocSize, SymOffset,
-                               Mapping->getKey(), Mapping->getValue());
+      ValidRelocs.emplace_back(Offset64, RelocSize, SymOffset, Mapping);
     }
   }
 }
@@ -996,13 +950,18 @@ bool DwarfLinkerForBinary::AddressManager::findValidRelocsInDebugSections(
   return FoundValidRelocs;
 }
 
-std::vector<ValidReloc> DwarfLinkerForBinary::AddressManager::getRelocations(
-    const std::vector<ValidReloc> &Relocs, uint64_t StartPos, uint64_t EndPos) {
-  std::vector<ValidReloc> Res;
-
-  auto CurReloc = partition_point(Relocs, [StartPos](const ValidReloc &Reloc) {
-    return (uint64_t)Reloc.Offset < StartPos;
-  });
+std::vector<DwarfLinkerForBinary::AddressManager::ValidReloc>
+DwarfLinkerForBinary::AddressManager::getRelocations(
+    const std::vector<DwarfLinkerForBinary::AddressManager::ValidReloc> &Relocs,
+    uint64_t StartPos, uint64_t EndPos) {
+  std::vector<DwarfLinkerForBinary::AddressManager::ValidReloc> Res;
+
+  auto CurReloc = partition_point(
+      Relocs,
+      [StartPos](
+          const DwarfLinkerForBinary::AddressManager::ValidReloc &Reloc) {
+        return (uint64_t)Reloc.Offset < StartPos;
+      });
 
   while (CurReloc != Relocs.end() && CurReloc->Offset >= StartPos &&
          (uint64_t)CurReloc->Offset < EndPos) {
@@ -1013,22 +972,46 @@ std::vector<ValidReloc> DwarfLinkerForBinary::AddressManager::getRelocations(
   return Res;
 }
 
-void DwarfLinkerForBinary::AddressManager::printReloc(const ValidReloc &Reloc) {
-  const auto &Mapping = Reloc.SymbolMapping;
-  const uint64_t ObjectAddress = Mapping.ObjectAddress
-                                     ? uint64_t(*Mapping.ObjectAddress)
+void DwarfLinkerForBinary::AddressManager::printReloc(
+    const DwarfLinkerForBinary::AddressManager::ValidReloc &Reloc) {
+  printMapping(Reloc.Mapping->getKey(), Reloc.Mapping->getValue());
+}
+
+void DwarfLinkerForBinary::AddressManager::printMapping(
+    StringRef SymName, const DebugMapObject::SymbolMapping &SymMapping) {
+  const uint64_t ObjectAddress = SymMapping.ObjectAddress
+                                     ? uint64_t(*SymMapping.ObjectAddress)
                                      : std::numeric_limits<uint64_t>::max();
 
-  outs() << "Found valid debug map entry: " << Reloc.SymbolName << "\t"
+  outs() << "Found valid debug map entry: " << SymName << "\t"
          << format("0x%016" PRIx64 " => 0x%016" PRIx64 "\n", ObjectAddress,
-                   uint64_t(Mapping.BinaryAddress));
+                   uint64_t(SymMapping.BinaryAddress));
 }
 
 int64_t
 DwarfLinkerForBinary::AddressManager::getRelocValue(const ValidReloc &Reloc) {
   int64_t AddrAdjust = relocate(Reloc);
-  if (Reloc.SymbolMapping.ObjectAddress)
-    AddrAdjust -= uint64_t(*Reloc.SymbolMapping.ObjectAddress);
+  if (Reloc.Mapping->getValue().ObjectAddress)
+    AddrAdjust -= uint64_t(*Reloc.Mapping->getValue().ObjectAddress);
+  return AddrAdjust;
+}
+
+std::optional<int64_t>
+DwarfLinkerForBinary::AddressManager::linkAddrValue(uint64_t Address,
+                                                    bool Verbose) {
+  const DebugMapObject::DebugMapEntry *Mapping =
+      DMO.lookupObjectAddress(Address);
+  if (!Mapping)
+    return std::nullopt;
+
+  const DebugMapObject::SymbolMapping &SymMapping = Mapping->getValue();
+  if (Verbose)
+    printMapping(Mapping->getKey(), SymMapping);
+
+  int64_t AddrAdjust = SymMapping.BinaryAddress;
+  if (SymMapping.ObjectAddress)
+    AddrAdjust -= uint64_t(*SymMapping.ObjectAddress);
+
   return AddrAdjust;
 }
 
@@ -1083,13 +1066,21 @@ DwarfLinkerForBinary::AddressManager::getExprOpAddressRelocAdjustment(
   case dwarf::DW_OP_const4s:
   case dwarf::DW_OP_const8s:
   case dwarf::DW_OP_addr: {
-    return hasValidRelocationAt(ValidDebugInfoRelocs, StartOffset, EndOffset,
-                                Verbose);
+    if (DMO.getType() == MachO::N_LIB)
+      return linkAddrValue(Op.getRawOperand(0), Verbose);
+    else
+      return hasValidRelocationAt(ValidDebugInfoRelocs, StartOffset, EndOffset,
+                                  Verbose);
   } break;
   case dwarf::DW_OP_constx:
   case dwarf::DW_OP_addrx: {
-    return hasValidRelocationAt(ValidDebugAddrRelocs, StartOffset, EndOffset,
-                                Verbose);
+    if (DMO.getType() == MachO::N_LIB) {
+      if (std::optional<object::SectionedAddress> SA =
+              U.getAddrOffsetSectionItem(Op.getRawOperand(0)))
+        return linkAddrValue(SA->Address, Verbose);
+    } else
+      return hasValidRelocationAt(ValidDebugAddrRelocs, StartOffset, EndOffset,
+                                  Verbose);
   } break;
   }
 
@@ -1099,6 +1090,20 @@ DwarfLinkerForBinary::AddressManager::getExprOpAddressRelocAdjustment(
 std::optional<int64_t>
 DwarfLinkerForBinary::AddressManager::getSubprogramRelocAdjustment(
     const DWARFDie &DIE, bool Verbose) {
+  // Check for MachO::N_LIB. We need to relink addresses from N_LIB
+  // differently. Relocations are already resolved for N_LIB, thus we
+  // need to take attribute value and pass it through debug map.
+  if (DMO.getType() == MachO::N_LIB) {
+    if (std::optional<DWARFFormValue> AttrVal = DIE.find(dwarf::DW_AT_low_pc)) {
+      if (std::optional<uint64_t> Address = AttrVal->getAsAddress())
+        if (std::optional<int64_t> AddrAdjust =
+                linkAddrValue(*Address, Verbose))
+          return *AddrAdjust;
+    }
+
+    return std::nullopt;
+  }
+
   const auto *Abbrev = DIE.getAbbreviationDeclarationPtr();
 
   std::optional<uint32_t> LowPcIdx =
@@ -1145,25 +1150,9 @@ DwarfLinkerForBinary::AddressManager::getLibraryInstallName() {
 
 uint64_t
 DwarfLinkerForBinary::AddressManager::relocate(const ValidReloc &Reloc) const {
-  return Reloc.SymbolMapping.BinaryAddress + Reloc.Addend;
+  return Reloc.Mapping->getValue().BinaryAddress + Reloc.Addend;
 }
 
-void DwarfLinkerForBinary::AddressManager::updateAndSaveValidRelocs(
-    bool IsDWARF5, uint64_t OriginalUnitOffset, int64_t LinkedOffset,
-    uint64_t StartOffset, uint64_t EndOffset) {
-  std::vector<ValidReloc> InRelocs =
-      getRelocations(ValidDebugInfoRelocs, StartOffset, EndOffset);
-  if (IsDWARF5)
-    InRelocs = getRelocations(ValidDebugAddrRelocs, StartOffset, EndOffset);
-  DwarfLinkerRelocMap->updateAndSaveValidRelocs(
-      IsDWARF5, InRelocs, OriginalUnitOffset, LinkedOffset);
-}
-
-void DwarfLinkerForBinary::AddressManager::updateRelocationsWithUnitOffset(
-    uint64_t OriginalUnitOffset, uint64_t OutputUnitOffset) {
-  DwarfLinkerRelocMap->updateRelocationsWithUnitOffset(OriginalUnitOffset,
-                                                       OutputUnitOffset);
-}
 /// Apply the valid relocations found by findValidRelocs() to
 /// the buffer \p Data, taking into account that Data is at \p BaseOffset
 /// in the debug_info section.
@@ -1193,44 +1182,5 @@ bool DwarfLinkerForBinary::AddressManager::applyValidRelocs(
   return Relocs.size() > 0;
 }
 
-void DwarfLinkerForBinaryRelocationMap::init(DWARFContext &Context) {
-  for (const std::unique_ptr<DWARFUnit> &CU : Context.compile_units())
-    StoredValidDebugInfoRelocsMap.insert(
-        std::make_pair(CU->getOffset(), std::vector<ValidReloc>()));
-  // FIXME: Support relocations debug_addr (DWARF5).
-}
-
-void DwarfLinkerForBinaryRelocationMap::addValidRelocs(RelocationMap &RM) {
-  for (const auto &DebugInfoRelocs : StoredValidDebugInfoRelocsMap) {
-    for (const auto &InfoReloc : DebugInfoRelocs.second)
-      RM.addRelocationMapEntry(InfoReloc);
-  }
-  // FIXME: Support relocations debug_addr (DWARF5).
-}
-
-void DwarfLinkerForBinaryRelocationMap::updateRelocationsWithUnitOffset(
-    uint64_t OriginalUnitOffset, uint64_t OutputUnitOffset) {
-  std::vector<ValidReloc> &StoredValidDebugInfoRelocs =
-      StoredValidDebugInfoRelocsMap[OriginalUnitOffset];
-  for (ValidReloc &R : StoredValidDebugInfoRelocs) {
-    R.Offset = (uint64_t)R.Offset + OutputUnitOffset;
-  }
-  // FIXME: Support relocations debug_addr (DWARF5).
-}
-
-void DwarfLinkerForBinaryRelocationMap::updateAndSaveValidRelocs(
-    bool IsDWARF5, std::vector<ValidReloc> &InRelocs, uint64_t UnitOffset,
-    int64_t LinkedOffset) {
-  std::vector<ValidReloc> &OutRelocs =
-      StoredValidDebugInfoRelocsMap[UnitOffset];
-  if (IsDWARF5)
-    OutRelocs = StoredValidDebugAddrRelocsMap[UnitOffset];
-
-  for (ValidReloc &R : InRelocs) {
-    OutRelocs.emplace_back(R.Offset + LinkedOffset, R.Size, R.Addend,
-                           R.SymbolName, R.SymbolMapping);
-  }
-}
-
 } // namespace dsymutil
 } // namespace llvm
diff --git a/llvm/tools/dsymutil/DwarfLinkerForBinary.h b/llvm/tools/dsymutil/DwarfLinkerForBinary.h
index 53f9e183ebe88d..e2fc1e6d302bf0 100644
--- a/llvm/tools/dsymutil/DwarfLinkerForBinary.h
+++ b/llvm/tools/dsymutil/DwarfLinkerForBinary.h
@@ -13,7 +13,6 @@
 #include "DebugMap.h"
 #include "LinkUtils.h"
 #include "MachOUtils.h"
-#include "RelocationMap.h"
 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
 #include "llvm/Remarks/RemarkFormat.h"
 #include "llvm/Remarks/RemarkLinker.h"
@@ -25,43 +24,6 @@ using namespace dwarf_linker;
 
 namespace dsymutil {
 
-/// DwarfLinkerForBinaryRelocationMap contains the logic to handle the
-/// relocations and to store them inside an associated RelocationMap.
-class DwarfLinkerForBinaryRelocationMap {
-public:
-  void init(DWARFContext &Context);
-
-  bool isInitialized() {
-    return StoredValidDebugInfoRelocsMap.getMemorySize() != 0;
-  }
-
-  void addValidRelocs(RelocationMap &RM);
-
-  void updateAndSaveValidRelocs(bool IsDWARF5,
-                                std::vector<ValidReloc> &InRelocs,
-                                uint64_t UnitOffset, int64_t LinkedOffset);
-
-  void updateRelocationsWithUnitOffset(uint64_t OriginalUnitOffset,
-                                       uint64_t OutputUnitOffset);
-
-  /// Map compilation unit offset to the valid relocations to store
-  /// @{
-  DenseMap<uint64_t, std::vector<ValidReloc>> StoredValidDebugInfoRelocsMap;
-  DenseMap<uint64_t, std::vector<ValidReloc>> StoredValidDebugAddrRelocsMap;
-  /// @}
-
-  DwarfLinkerForBinaryRelocationMap() = default;
-};
-
-struct ObjectWithRelocMap {
-  ObjectWithRelocMap(
-      std::unique_ptr<DWARFFile> Object,
-      std::shared_ptr<DwarfLinkerForBinaryRelocationMap> OutRelocs)
-      : Object(std::move(Object)), OutRelocs(OutRelocs) {}
-  std::unique_ptr<DWARFFile> Object;
-  std::shared_ptr<DwarfLinkerForBinaryRelocationMap> OutRelocs;
-};
-
 /// The core of the Dsymutil Dwarf linking logic.
 ///
 /// The link of the dwarf information from the object files will be
@@ -103,6 +65,21 @@ class DwarfLinkerForBinary {
 
   /// Keeps track of relocations.
   class AddressManager : public dwarf_linker::AddressesMap {
+    struct ValidReloc {
+      uint64_t Offset = 0;
+      uint32_t Size = 0;
+      uint64_t Addend = 0;
+      const DebugMapObject::DebugMapEntry *Mapping = nullptr;
+
+      ValidReloc(uint64_t Offset, uint32_t Size, uint64_t Addend,
+                 const DebugMapObject::DebugMapEntry *Mapping)
+          : Offset(Offset), Size(Size), Addend(Addend), Mapping(Mapping) {}
+
+      bool operator<(const ValidReloc &RHS) const {
+        return Offset < RHS.Offset;
+      }
+      bool operator<(uint64_t RHS) const { return Offset < RHS; }
+    };
 
     const DwarfLinkerForBinary &Linker;
 
@@ -115,9 +92,7 @@ class DwarfLinkerForBinary {
 
     StringRef SrcFileName;
 
-    uint8_t DebugMapObjectType;
-
-    std::shared_ptr<DwarfLinkerForBinaryRelocationMap> DwarfLinkerRelocMap;
+    const DebugMapObject &DMO;
 
     std::optional<std::string> LibInstallName;
 
@@ -137,39 +112,33 @@ class DwarfLinkerForBinary {
     /// \returns value for the specified \p Reloc.
     int64_t getRelocValue(const ValidReloc &Reloc);
 
-    /// Print contents of debug map entry for the specified \p Reloc.
+    /// Link specified \p Address through debug map.
+    /// \returns Address adjustment value.
+    std::optional<int64_t> linkAddrValue(uint64_t Address, bool Verbose);
+
+    /// Print content of debug map entry for the specified \p Reloc.
     void printReloc(const ValidReloc &Reloc);
 
+    /// Print content of debug map entry for the specifed \p Mapping.
+    void printMapping(StringRef SymName,
+                      const DebugMapObject::SymbolMapping &SymMapping);
+
   public:
     AddressManager(DwarfLinkerForBinary &Linker, const object::ObjectFile &Obj,
-                   const DebugMapObject &DMO,
-                   std::shared_ptr<DwarfLinkerForBinaryRelocationMap> DLBRM)
-        : Linker(Linker), SrcFileName(DMO.getObjectFilename()),
-          DebugMapObjectType(MachO::N_OSO), DwarfLinkerRelocMap(DLBRM) {
-      if (DMO.getRelocationMap().has_value()) {
-        DebugMapObjectType = MachO::N_LIB;
-        LibInstallName.emplace(DMO.getInstallName().value());
-        const RelocationMap &RM = DMO.getRelocationMap().value();
-        for (const auto &Reloc : RM.relocations()) {
-          const auto *DebugMapEntry = DMO.lookupSymbol(Reloc.SymbolName);
-          if (!DebugMapEntry)
-            continue;
-          std::optional<uint64_t> ObjAddress;
-          ObjAddress.emplace(DebugMapEntry->getValue().ObjectAddress.value());
-          ValidDebugInfoRelocs.emplace_back(
-              Reloc.Offset, Reloc.Size, Reloc.Addend, Reloc.SymbolName,
-              SymbolMapping(ObjAddress, DebugMapEntry->getValue().BinaryAddress,
-                            DebugMapEntry->getValue().Size));
-          // FIXME: Support relocations debug_addr.
-        }
-      } else {
-        findValidRelocsInDebugSections(Obj, DMO);
-      }
+                   const DebugMapObject &DMO)
+        : Linker(Linker), SrcFileName(DMO.getObjectFilename()), DMO(DMO) {
+      findValidRelocsInDebugSections(Obj, DMO);
     }
     ~AddressManager() override { clear(); }
 
-    bool hasValidRelocs() override {
-      return !ValidDebugInfoRelocs.empty() || !ValidDebugAddrRelocs.empty();
+    bool hasLiveDebugInfo() override {
+      // We can detect if object file can be linked not going long way of
+      // linking. If it does not have any relocation then all debug info can be
+      // quickly removed instead of doing linking. The MachO::N_LIB is a special
+      // case(all relocations are already resolved), but we still want to link
+      // it.
+      return DMO.getType() == MachO::N_LIB || !ValidDebugInfoRelocs.empty() ||
+             !ValidDebugAddrRelocs.empty();
     }
 
     /// \defgroup FindValidRelocations Translate debug map into a list
@@ -212,16 +181,7 @@ class DwarfLinkerForBinary {
     bool applyValidRelocs(MutableArrayRef<char> Data, uint64_t BaseOffset,
                           bool IsLittleEndian) override;
 
-    bool needToSaveValidRelocs() override { return true; }
-
-    void updateAndSaveValidRelocs(bool IsDWARF5, uint64_t OriginalUnitOffset,
-                                  int64_t LinkedOffset, uint64_t StartOffset,
-                                  uint64_t EndOffset) override;
-
-    void updateRelocationsWithUnitOffset(uint64_t OriginalUnitOffset,
-                                         uint64_t OutputUnitOffset) override;
-
-    void clear() override {
+    void clear() {
       ValidDebugInfoRelocs.clear();
       ValidDebugAddrRelocs.clear();
     }
@@ -242,8 +202,7 @@ class DwarfLinkerForBinary {
                                                  const Triple &triple);
   ErrorOr<std::unique_ptr<dwarf_linker::DWARFFile>>
   loadObject(const DebugMapObject &Obj, const DebugMap &DebugMap,
-             remarks::RemarkLinker &RL,
-             std::shared_ptr<DwarfLinkerForBinaryRelocationMap> DLBRM);
+             remarks::RemarkLinker &RL);
 
   void collectRelocationsToApplyToSwiftReflectionSections(
       const object::SectionRef &Section, StringRef &Contents,
@@ -266,9 +225,6 @@ class DwarfLinkerForBinary {
   bool linkImpl(const DebugMap &Map,
                 typename Linker::OutputFileType ObjectType);
 
-  Error emitRelocations(const DebugMap &DM,
-                        std::vector<ObjectWithRelocMap> &ObjectsForLinking);
-
   raw_fd_ostream &OutFile;
   BinaryHolder &BinHolder;
   LinkOptions Options;
diff --git a/llvm/tools/dsymutil/MachODebugMapParser.cpp b/llvm/tools/dsymutil/MachODebugMapParser.cpp
index 6a9f25681cdd1c..23202f80037dac 100644
--- a/llvm/tools/dsymutil/MachODebugMapParser.cpp
+++ b/llvm/tools/dsymutil/MachODebugMapParser.cpp
@@ -9,7 +9,6 @@
 #include "BinaryHolder.h"
 #include "DebugMap.h"
 #include "MachOUtils.h"
-#include "RelocationMap.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/Object/MachO.h"
@@ -257,6 +256,9 @@ void MachODebugMapParser::switchToNewLibDebugMapObject(
   }
 
   for (auto DSYMSearchPath : DSYMSearchPaths) {
+    addCommonSymbols();
+    resetParserState();
+
     SmallString<256> Path(DSYMSearchPath);
     SmallString<256> FallbackPath(Path);
 
@@ -271,6 +273,12 @@ void MachODebugMapParser::switchToNewLibDebugMapObject(
       sys::path::append(Path, DSYMPath, LeafName);
     }
 
+    if (CurrentDebugMapObject &&
+        CurrentDebugMapObject->getType() == MachO::N_LIB &&
+        CurrentDebugMapObject->getObjectFilename().compare(Path.str()) == 0) {
+      return;
+    }
+
     auto ObjectEntry = BinHolder.getObjectEntry(Path, Timestamp);
     if (!ObjectEntry) {
       auto Err = ObjectEntry.takeError();
@@ -299,37 +307,11 @@ void MachODebugMapParser::switchToNewLibDebugMapObject(
       continue;
     }
 
-    if (CurrentDebugMapObject &&
-        CurrentDebugMapObject->getType() == MachO::N_LIB &&
-        CurrentDebugMapObject->getObjectFilename().compare(Path.str()) == 0) {
-      return;
-    }
-
-    addCommonSymbols();
-    resetParserState();
-
     CurrentDebugMapObject =
         &Result->addDebugMapObject(Path, Timestamp, MachO::N_LIB);
 
     CurrentDebugMapObject->setInstallName(Filename);
 
-    SmallString<256> RMPath(DSYMSearchPath);
-    sys::path::append(RMPath, ProductName);
-    RMPath.append(".dSYM");
-    StringRef ArchName = Triple::getArchName(Result->getTriple().getArch(),
-                                             Result->getTriple().getSubArch());
-    sys::path::append(RMPath, "Contents", "Resources", "Relocations", ArchName);
-    sys::path::append(RMPath, LeafName);
-    RMPath.append(".yml");
-    const auto &RelocMapPtrOrErr =
-        RelocationMap::parseYAMLRelocationMap(RMPath, PathPrefix);
-    if (auto EC = RelocMapPtrOrErr.getError()) {
-      Warning("cannot parse relocation map file: " + EC.message(),
-              RMPath.str());
-      return;
-    }
-    CurrentDebugMapObject->setRelocationMap(*RelocMapPtrOrErr->get());
-
     loadCurrentObjectFileSymbols(*Object);
 
     // Found and loaded new dSYM file
diff --git a/llvm/tools/dsymutil/RelocationMap.cpp b/llvm/tools/dsymutil/RelocationMap.cpp
deleted file mode 100644
index 5921e7c9c24952..00000000000000
--- a/llvm/tools/dsymutil/RelocationMap.cpp
+++ /dev/null
@@ -1,92 +0,0 @@
-//===- tools/dsymutil/RelocationMap.cpp - Relocation map representation---===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "RelocationMap.h"
-
-namespace llvm {
-
-namespace dsymutil {
-
-void RelocationMap::print(raw_ostream &OS) const {
-  yaml::Output yout(OS, /* Ctxt = */ nullptr, /* WrapColumn = */ 0);
-  yout << const_cast<RelocationMap &>(*this);
-}
-
-#ifndef NDEBUG
-void RelocationMap::dump() const { print(errs()); }
-#endif
-
-void RelocationMap::addRelocationMapEntry(const ValidReloc &Relocation) {
-  Relocations.push_back(Relocation);
-}
-
-namespace {
-
-struct YAMLContext {
-  StringRef PrependPath;
-  Triple BinaryTriple;
-};
-
-} // end anonymous namespace
-
-ErrorOr<std::unique_ptr<RelocationMap>>
-RelocationMap::parseYAMLRelocationMap(StringRef InputFile,
-                                      StringRef PrependPath) {
-  auto ErrOrFile = MemoryBuffer::getFileOrSTDIN(InputFile);
-  if (auto Err = ErrOrFile.getError())
-    return Err;
-
-  YAMLContext Ctxt;
-
-  Ctxt.PrependPath = PrependPath;
-
-  std::unique_ptr<RelocationMap> Result;
-  yaml::Input yin((*ErrOrFile)->getBuffer(), &Ctxt);
-  yin >> Result;
-
-  if (auto EC = yin.error())
-    return EC;
-  return std::move(Result);
-}
-
-} // end namespace dsymutil
-
-namespace yaml {
-
-void MappingTraits<dsymutil::ValidReloc>::mapping(IO &io,
-                                                  dsymutil::ValidReloc &VR) {
-  io.mapRequired("offset", VR.Offset);
-  io.mapRequired("size", VR.Size);
-  io.mapRequired("addend", VR.Addend);
-  io.mapRequired("symName", VR.SymbolName);
-  io.mapOptional("symObjAddr", VR.SymbolMapping.ObjectAddress);
-  io.mapRequired("symBinAddr", VR.SymbolMapping.BinaryAddress);
-  io.mapRequired("symSize", VR.SymbolMapping.Size);
-}
-
-void MappingTraits<dsymutil::RelocationMap>::mapping(
-    IO &io, dsymutil::RelocationMap &RM) {
-  io.mapRequired("triple", RM.BinaryTriple);
-  io.mapRequired("binary-path", RM.BinaryPath);
-  if (void *Ctxt = io.getContext())
-    reinterpret_cast<YAMLContext *>(Ctxt)->BinaryTriple = RM.BinaryTriple;
-  io.mapRequired("relocations", RM.Relocations);
-}
-
-void MappingTraits<std::unique_ptr<dsymutil::RelocationMap>>::mapping(
-    IO &io, std::unique_ptr<dsymutil::RelocationMap> &RM) {
-  if (!RM)
-    RM.reset(new RelocationMap());
-  io.mapRequired("triple", RM->BinaryTriple);
-  io.mapRequired("binary-path", RM->BinaryPath);
-  if (void *Ctxt = io.getContext())
-    reinterpret_cast<YAMLContext *>(Ctxt)->BinaryTriple = RM->BinaryTriple;
-  io.mapRequired("relocations", RM->Relocations);
-}
-} // end namespace yaml
-} // end namespace llvm
diff --git a/llvm/tools/dsymutil/RelocationMap.h b/llvm/tools/dsymutil/RelocationMap.h
deleted file mode 100644
index 3d851acf2b8926..00000000000000
--- a/llvm/tools/dsymutil/RelocationMap.h
+++ /dev/null
@@ -1,160 +0,0 @@
-//===- tools/dsymutil/RelocationMap.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
-//
-//===----------------------------------------------------------------------===//
-//
-/// \file
-///
-/// This file contains the class declaration of the RelocationMap
-/// entity. RelocationMap lists all the relocations of all the
-/// atoms used in the object files linked together to
-/// produce an executable.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_TOOLS_DSYMUTIL_RELOCATIONMAP_H
-#define LLVM_TOOLS_DSYMUTIL_RELOCATIONMAP_H
-
-#include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/iterator_range.h"
-#include "llvm/Support/YAMLTraits.h"
-#include "llvm/TargetParser/Triple.h"
-
-#include <optional>
-#include <string>
-#include <vector>
-
-namespace llvm {
-
-class raw_ostream;
-
-namespace dsymutil {
-
-struct SymbolMapping {
-  std::optional<yaml::Hex64> ObjectAddress;
-  yaml::Hex64 BinaryAddress;
-  yaml::Hex32 Size;
-
-  SymbolMapping(std::optional<uint64_t> ObjectAddr, uint64_t BinaryAddress,
-                uint32_t Size)
-      : BinaryAddress(BinaryAddress), Size(Size) {
-    if (ObjectAddr)
-      ObjectAddress = *ObjectAddr;
-  }
-
-  /// For YAML IO support
-  SymbolMapping() = default;
-};
-
-/// ValidReloc represents one relocation entry described by the RelocationMap.
-/// It contains a list of DWARF relocations to apply to a linked binary.
-class ValidReloc {
-public:
-  yaml::Hex64 Offset;
-  yaml::Hex32 Size;
-  yaml::Hex64 Addend;
-  std::string SymbolName;
-  struct SymbolMapping SymbolMapping;
-
-  struct SymbolMapping getSymbolMapping() const { return SymbolMapping; }
-
-  ValidReloc(uint64_t Offset, uint32_t Size, uint64_t Addend,
-             StringRef SymbolName, struct SymbolMapping SymbolMapping)
-      : Offset(Offset), Size(Size), Addend(Addend), SymbolName(SymbolName),
-        SymbolMapping(SymbolMapping) {}
-
-  bool operator<(const ValidReloc &RHS) const { return Offset < RHS.Offset; }
-
-  /// For YAMLIO support.
-  ValidReloc() = default;
-};
-
-/// The RelocationMap object stores the list of relocation entries for a binary
-class RelocationMap {
-  Triple BinaryTriple;
-  std::string BinaryPath;
-  using RelocContainer = std::vector<ValidReloc>;
-
-  RelocContainer Relocations;
-
-  /// For YAML IO support.
-  ///@{
-  friend yaml::MappingTraits<std::unique_ptr<RelocationMap>>;
-  friend yaml::MappingTraits<RelocationMap>;
-
-  RelocationMap() = default;
-  ///@}
-
-public:
-  RelocationMap(const Triple &BinaryTriple, StringRef BinaryPath)
-      : BinaryTriple(BinaryTriple), BinaryPath(std::string(BinaryPath)) {}
-
-  using const_iterator = RelocContainer::const_iterator;
-
-  iterator_range<const_iterator> relocations() const {
-    return make_range(begin(), end());
-  }
-
-  const_iterator begin() const { return Relocations.begin(); }
-
-  const_iterator end() const { return Relocations.end(); }
-
-  size_t getNumberOfEntries() const { return Relocations.size(); }
-
-  /// This function adds a ValidReloc to the list owned by this
-  /// relocation map.
-  void addRelocationMapEntry(const ValidReloc &Relocation);
-
-  const Triple &getTriple() const { return BinaryTriple; }
-
-  StringRef getBinaryPath() const { return BinaryPath; }
-
-  void print(raw_ostream &OS) const;
-
-#ifndef NDEBUG
-  void dump() const;
-#endif
-
-  /// Read a relocation map from \a InputFile.
-  static ErrorOr<std::unique_ptr<RelocationMap>>
-  parseYAMLRelocationMap(StringRef InputFile, StringRef PrependPath);
-};
-
-} // end namespace dsymutil
-} // end namespace llvm
-
-LLVM_YAML_IS_SEQUENCE_VECTOR(dsymutil::ValidReloc)
-
-namespace llvm {
-namespace yaml {
-
-using namespace llvm::dsymutil;
-
-template <> struct MappingTraits<dsymutil::ValidReloc> {
-  static void mapping(IO &io, dsymutil::ValidReloc &VR);
-  static const bool flow = true;
-};
-
-template <> struct MappingTraits<dsymutil::RelocationMap> {
-  struct YamlRM;
-  static void mapping(IO &io, dsymutil::RelocationMap &RM);
-};
-
-template <> struct MappingTraits<std::unique_ptr<dsymutil::RelocationMap>> {
-  struct YamlRM;
-  static void mapping(IO &io, std::unique_ptr<dsymutil::RelocationMap> &RM);
-};
-
-template <> struct ScalarTraits<Triple> {
-  static void output(const Triple &val, void *, raw_ostream &out);
-  static StringRef input(StringRef scalar, void *, Triple &value);
-  static QuotingType mustQuote(StringRef) { return QuotingType::Single; }
-};
-
-} // end namespace yaml
-} // end namespace llvm
-
-#endif // LLVM_TOOLS_DSYMUTIL_RELOCATIONMAP_H
diff --git a/llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp b/llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp
index 285dcf75ecd9d3..a03c695d7fa851 100644
--- a/llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp
+++ b/llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp
@@ -78,7 +78,7 @@ class ObjFileAddressMap : public AddressesMap {
   }
 
   // should be renamed into has valid address ranges
-  bool hasValidRelocs() override { return HasValidAddressRanges; }
+  bool hasLiveDebugInfo() override { return HasValidAddressRanges; }
 
   std::optional<int64_t> getSubprogramRelocAdjustment(const DWARFDie &DIE,
                                                       bool Verbose) override {
@@ -142,16 +142,6 @@ class ObjFileAddressMap : public AddressesMap {
     return false;
   }
 
-  bool needToSaveValidRelocs() override { return false; }
-
-  void updateAndSaveValidRelocs(bool, uint64_t, int64_t, uint64_t,
-                                uint64_t) override {}
-
-  void updateRelocationsWithUnitOffset(uint64_t OriginalUnitOffset,
-                                       uint64_t OutputUnitOffset) override {}
-
-  void clear() override {}
-
 protected:
   // returns true if specified address range is inside address ranges
   // of executable sections.



More information about the llvm-commits mailing list