[llvm] [DWARFLinker][DWARFLinkerParallel][NFC] Refactor DWARFLinker&DWARFLinkerParallel to have a common library. Part 1. (PR #75925)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 2 05:33:03 PST 2024


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

>From 52fabddfb83db116853e7520f368a1fba37c111c Mon Sep 17 00:00:00 2001
From: Alexey Lapshin <a.v.lapshin at mail.ru>
Date: Mon, 18 Dec 2023 15:49:29 +0300
Subject: [PATCH 1/3] [DWARFLinker][DWARFLinkerParallel][NFC] Refactor
 DWARFLinker&DWARFLinkerParallel to have a common library. Part 1.

This patch creates DWARFLinkerBase library, places DWARFLinker code into
DWARFLinker\Apple, places DWARFLinkerParallel into DWARFLinker\LLVM.
This patch is NFC.
---
 bolt/lib/Rewrite/CMakeLists.txt               |   1 +
 bolt/lib/Rewrite/DWARFRewriter.cpp            |  12 +-
 .../AddressesMap.h                            |  10 +-
 .../DWARFLinker/{ => Apple}/DWARFLinker.h     | 214 +++++-------------
 .../{ => Apple}/DWARFLinkerCompileUnit.h      |   8 +-
 .../{ => Apple}/DWARFLinkerDeclContext.h      |   8 +-
 .../DWARFLinker/{ => Apple}/DWARFStreamer.h   |  16 +-
 .../DWARFFile.h                               |  17 +-
 .../llvm/DWARFLinker/DWARFLinkerBase.h        |  98 ++++++++
 .../LLVM}/DWARFLinker.h                       | 102 +--------
 .../StringPool.h                              |  10 +-
 .../llvm/DebugInfo/DWARF/DWARFDebugMacro.h    |   7 +-
 llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h |   4 +-
 llvm/lib/CMakeLists.txt                       |   1 -
 llvm/lib/DWARFLinker/Apple/CMakeLists.txt     |  24 ++
 .../DWARFLinker/{ => Apple}/DWARFLinker.cpp   |  65 +++---
 .../{ => Apple}/DWARFLinkerCompileUnit.cpp    |   6 +-
 .../{ => Apple}/DWARFLinkerDeclContext.cpp    |   6 +-
 .../DWARFLinker/{ => Apple}/DWARFStreamer.cpp |   9 +-
 llvm/lib/DWARFLinker/CMakeLists.txt           |  15 +-
 .../LLVM}/AcceleratorRecordsSaver.cpp         |   8 +-
 .../LLVM}/AcceleratorRecordsSaver.h           |   8 +-
 .../LLVM}/ArrayList.h                         |   8 +-
 .../LLVM}/CMakeLists.txt                      |   3 +-
 .../LLVM}/DIEAttributeCloner.cpp              |   8 +-
 .../LLVM}/DIEAttributeCloner.h                |   8 +-
 .../LLVM}/DIEGenerator.h                      |   8 +-
 .../LLVM}/DWARFEmitterImpl.cpp                |  10 +-
 .../LLVM}/DWARFEmitterImpl.h                  |  10 +-
 .../LLVM}/DWARFLinker.cpp                     |  12 +-
 .../LLVM}/DWARFLinkerCompileUnit.cpp          |   5 +-
 .../LLVM}/DWARFLinkerCompileUnit.h            |  10 +-
 .../LLVM}/DWARFLinkerGlobalData.h             |  10 +-
 .../LLVM}/DWARFLinkerImpl.cpp                 | 192 ++++++++--------
 .../LLVM}/DWARFLinkerImpl.h                   |  12 +-
 .../LLVM}/DWARFLinkerTypeUnit.cpp             |   3 +-
 .../LLVM}/DWARFLinkerTypeUnit.h               |   8 +-
 .../LLVM}/DWARFLinkerUnit.cpp                 |  33 ++-
 .../LLVM}/DWARFLinkerUnit.h                   |  12 +-
 .../LLVM}/DebugLineSectionEmitter.h           |  12 +-
 .../LLVM}/DependencyTracker.cpp               |   8 +-
 .../LLVM}/DependencyTracker.h                 |   8 +-
 .../LLVM}/IndexedValuesMap.h                  |   8 +-
 .../LLVM}/OutputSections.cpp                  |  23 +-
 .../LLVM}/OutputSections.h                    |  26 ++-
 .../StringEntryToDwarfStringPoolEntryMap.h    |  10 +-
 .../LLVM}/SyntheticTypeNameBuilder.cpp        |   8 +-
 .../LLVM}/SyntheticTypeNameBuilder.h          |   8 +-
 .../LLVM}/TypePool.h                          |   8 +-
 .../LLVM}/Utils.h                             |   8 +-
 .../StringPool.cpp => DWARFLinker/Utils.cpp}  |   4 +-
 llvm/lib/DWARFLinkerParallel/DWARFFile.cpp    |  17 --
 llvm/tools/dsymutil/CMakeLists.txt            |   1 +
 llvm/tools/dsymutil/DwarfLinkerForBinary.cpp  | 143 +++++-------
 llvm/tools/dsymutil/DwarfLinkerForBinary.h    |  30 ++-
 llvm/tools/dsymutil/LinkUtils.h               |   7 +-
 llvm/tools/dsymutil/dsymutil.cpp              |   1 +
 llvm/tools/llvm-dwarfutil/CMakeLists.txt      |   1 +
 llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp |  33 ++-
 .../DWARFLinkerParallel/StringPoolTest.cpp    |   4 +-
 60 files changed, 637 insertions(+), 732 deletions(-)
 rename llvm/include/llvm/{DWARFLinkerParallel => DWARFLinker}/AddressesMap.h (97%)
 rename llvm/include/llvm/DWARFLinker/{ => Apple}/DWARFLinker.h (81%)
 rename llvm/include/llvm/DWARFLinker/{ => Apple}/DWARFLinkerCompileUnit.h (98%)
 rename llvm/include/llvm/DWARFLinker/{ => Apple}/DWARFLinkerDeclContext.h (96%)
 rename llvm/include/llvm/DWARFLinker/{ => Apple}/DWARFStreamer.h (98%)
 rename llvm/include/llvm/{DWARFLinkerParallel => DWARFLinker}/DWARFFile.h (79%)
 create mode 100644 llvm/include/llvm/DWARFLinker/DWARFLinkerBase.h
 rename llvm/include/llvm/{DWARFLinkerParallel => DWARFLinker/LLVM}/DWARFLinker.h (59%)
 rename llvm/include/llvm/{DWARFLinkerParallel => DWARFLinker}/StringPool.h (91%)
 create mode 100644 llvm/lib/DWARFLinker/Apple/CMakeLists.txt
 rename llvm/lib/DWARFLinker/{ => Apple}/DWARFLinker.cpp (98%)
 rename llvm/lib/DWARFLinker/{ => Apple}/DWARFLinkerCompileUnit.cpp (97%)
 rename llvm/lib/DWARFLinker/{ => Apple}/DWARFLinkerDeclContext.cpp (98%)
 rename llvm/lib/DWARFLinker/{ => Apple}/DWARFStreamer.cpp (99%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/AcceleratorRecordsSaver.cpp (98%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/AcceleratorRecordsSaver.h (91%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/ArrayList.h (96%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/CMakeLists.txt (94%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/DIEAttributeCloner.cpp (99%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/DIEAttributeCloner.h (96%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/DIEGenerator.h (97%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/DWARFEmitterImpl.cpp (98%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/DWARFEmitterImpl.h (95%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/DWARFLinker.cpp (65%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/DWARFLinkerCompileUnit.cpp (99%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/DWARFLinkerCompileUnit.h (98%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/DWARFLinkerGlobalData.h (94%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/DWARFLinkerImpl.cpp (92%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/DWARFLinkerImpl.h (97%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/DWARFLinkerTypeUnit.cpp (99%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/DWARFLinkerTypeUnit.h (95%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/DWARFLinkerUnit.cpp (89%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/DWARFLinkerUnit.h (95%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/DebugLineSectionEmitter.h (97%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/DependencyTracker.cpp (99%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/DependencyTracker.h (97%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/IndexedValuesMap.h (85%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/OutputSections.cpp (95%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/OutputSections.h (95%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/StringEntryToDwarfStringPoolEntryMap.h (88%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/SyntheticTypeNameBuilder.cpp (99%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/SyntheticTypeNameBuilder.h (96%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/TypePool.h (96%)
 rename llvm/lib/{DWARFLinkerParallel => DWARFLinker/LLVM}/Utils.h (87%)
 rename llvm/lib/{DWARFLinkerParallel/StringPool.cpp => DWARFLinker/Utils.cpp} (68%)
 delete mode 100644 llvm/lib/DWARFLinkerParallel/DWARFFile.cpp

diff --git a/bolt/lib/Rewrite/CMakeLists.txt b/bolt/lib/Rewrite/CMakeLists.txt
index b0e2b7f46bef4c..fb21c13c654b3e 100644
--- a/bolt/lib/Rewrite/CMakeLists.txt
+++ b/bolt/lib/Rewrite/CMakeLists.txt
@@ -5,6 +5,7 @@ set(LLVM_LINK_COMPONENTS
   MC
   Object
   Support
+  DWARFLinkerBase
   DWARFLinker
   AsmPrinter
   TargetParser
diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp
index 05fb3e8fafe2f7..8dd2ac342ee455 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -21,7 +21,7 @@
 #include "llvm/BinaryFormat/Dwarf.h"
 #include "llvm/CodeGen/AsmPrinter.h"
 #include "llvm/CodeGen/DIE.h"
-#include "llvm/DWARFLinker/DWARFStreamer.h"
+#include "llvm/DWARFLinker/Apple/DWARFStreamer.h"
 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
 #include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
 #include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
@@ -181,7 +181,7 @@ translateInputToOutputLocationList(const BinaryFunction &BF,
 namespace llvm {
 namespace bolt {
 /// Emits debug information into .debug_info or .debug_types section.
-class DIEStreamer : public DwarfStreamer {
+class DIEStreamer : public dwarflinker::DwarfStreamer {
   DIEBuilder *DIEBldr;
   DWARFRewriter &Rewriter;
 
@@ -278,10 +278,10 @@ class DIEStreamer : public DwarfStreamer {
 
 public:
   DIEStreamer(DIEBuilder *DIEBldr, DWARFRewriter &Rewriter,
-              DWARFLinker::OutputFileType OutFileType,
+              dwarflinker::DWARFLinker::OutputFileType OutFileType,
               raw_pwrite_stream &OutFile,
               std::function<StringRef(StringRef Input)> Translator,
-              DWARFLinker::messageHandler Warning)
+              dwarflinker::DWARFLinker::MessageHandlerTy Warning)
       : DwarfStreamer(OutFileType, OutFile, Translator, Warning),
         DIEBldr(DIEBldr), Rewriter(Rewriter){};
 
@@ -457,8 +457,8 @@ createDIEStreamer(const Triple &TheTriple, raw_pwrite_stream &OutFile,
                   DWARFRewriter &Rewriter) {
 
   std::unique_ptr<DIEStreamer> Streamer = std::make_unique<DIEStreamer>(
-      &DIEBldr, Rewriter, llvm::DWARFLinker::OutputFileType::Object, OutFile,
-      [](StringRef Input) -> StringRef { return Input; },
+      &DIEBldr, Rewriter, dwarflinker::DWARFLinker::OutputFileType::Object,
+      OutFile, [](StringRef Input) -> StringRef { return Input; },
       [&](const Twine &Warning, StringRef Context, const DWARFDie *) {});
   Error Err = Streamer->init(TheTriple, Swift5ReflectionSegmentName);
   if (Err)
diff --git a/llvm/include/llvm/DWARFLinkerParallel/AddressesMap.h b/llvm/include/llvm/DWARFLinker/AddressesMap.h
similarity index 97%
rename from llvm/include/llvm/DWARFLinkerParallel/AddressesMap.h
rename to llvm/include/llvm/DWARFLinker/AddressesMap.h
index b451fee4e0b723..dec95cd60af37f 100644
--- a/llvm/include/llvm/DWARFLinkerParallel/AddressesMap.h
+++ b/llvm/include/llvm/DWARFLinker/AddressesMap.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_DWARFLINKERPARALLEL_ADDRESSESMAP_H
-#define LLVM_DWARFLINKERPARALLEL_ADDRESSESMAP_H
+#ifndef LLVM_DWARFLINKER_ADDRESSESMAP_H
+#define LLVM_DWARFLINKER_ADDRESSESMAP_H
 
 #include "llvm/ADT/AddressRanges.h"
 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
@@ -17,7 +17,7 @@
 #include <cstdint>
 
 namespace llvm {
-namespace dwarflinker_parallel {
+namespace dwarflinker {
 
 /// Mapped value in the address map is the offset to apply to the
 /// linked address.
@@ -186,7 +186,7 @@ class AddressesMap {
   }
 };
 
-} // end of namespace dwarflinker_parallel
+} // end of namespace dwarflinker
 } // end namespace llvm
 
-#endif // LLVM_DWARFLINKERPARALLEL_ADDRESSESMAP_H
+#endif // LLVM_DWARFLINKER_ADDRESSESMAP_H
diff --git a/llvm/include/llvm/DWARFLinker/DWARFLinker.h b/llvm/include/llvm/DWARFLinker/Apple/DWARFLinker.h
similarity index 81%
rename from llvm/include/llvm/DWARFLinker/DWARFLinker.h
rename to llvm/include/llvm/DWARFLinker/Apple/DWARFLinker.h
index 2bd85e30d3b13b..05cee779179cda 100644
--- a/llvm/include/llvm/DWARFLinker/DWARFLinker.h
+++ b/llvm/include/llvm/DWARFLinker/Apple/DWARFLinker.h
@@ -6,14 +6,15 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_DWARFLINKER_DWARFLINKER_H
-#define LLVM_DWARFLINKER_DWARFLINKER_H
+#ifndef LLVM_DWARFLINKER_APPLE_DWARFLINKER_H
+#define LLVM_DWARFLINKER_APPLE_DWARFLINKER_H
 
 #include "llvm/ADT/AddressRanges.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/CodeGen/AccelTable.h"
 #include "llvm/CodeGen/NonRelocatableStringpool.h"
-#include "llvm/DWARFLinker/DWARFLinkerCompileUnit.h"
+#include "llvm/DWARFLinker/Apple/DWARFLinkerCompileUnit.h"
+#include "llvm/DWARFLinker/DWARFLinkerBase.h"
 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
 #include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
 #include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
@@ -25,73 +26,10 @@ namespace llvm {
 class DWARFExpression;
 class DWARFUnit;
 class DataExtractor;
-class DeclContextTree;
 template <typename T> class SmallVectorImpl;
 
-enum class DwarfLinkerClient { Dsymutil, LLD, General };
-
-/// 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();
-
-  /// Checks that there are valid relocations against a .debug_info
-  /// section.
-  virtual bool hasValidRelocs() = 0;
-
-  /// Checks that the specified DWARF expression operand \p Op references live
-  /// code section and returns the relocation adjustment value (to get the
-  /// linked address this value might be added to the source expression operand
-  /// address).
-  /// \returns relocation adjustment value or std::nullopt if there is no
-  /// corresponding live address.
-  virtual std::optional<int64_t>
-  getExprOpAddressRelocAdjustment(DWARFUnit &U,
-                                  const DWARFExpression::Operation &Op,
-                                  uint64_t StartOffset, uint64_t EndOffset) = 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;
-
-  /// Returns the file name associated to the AddessesMap
-  virtual std::optional<StringRef> getLibraryInstallName() = 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;
-
-  /// Check if the linker needs to gather and save relocation info.
-  virtual bool needToSaveValidRelocs() = 0;
-
-  /// Update and save original relocations located in between StartOffset and
-  /// EndOffset. LinkedOffset is the value which should be added to the original
-  /// relocation offset to get new relocation offset in linked binary.
-  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;
-};
+namespace dwarflinker {
+class DeclContextTree;
 
 using Offset2UnitMap = DenseMap<uint64_t, CompileUnit *>;
 
@@ -117,7 +55,7 @@ struct DebugDieValuePool {
 /// DwarfEmitter presents interface to generate all debug info tables.
 class DwarfEmitter {
 public:
-  virtual ~DwarfEmitter();
+  virtual ~DwarfEmitter() = default;
 
   /// Emit section named SecName with data SecData.
   virtual void emitSectionContents(StringRef SecData, StringRef SecName) = 0;
@@ -282,44 +220,6 @@ class DwarfEmitter {
 class DwarfStreamer;
 using UnitListTy = std::vector<std::unique_ptr<CompileUnit>>;
 
-/// This class represents DWARF information for source file
-/// and its address map.
-class DWARFFile {
-public:
-  using UnloadCallbackTy = std::function<void(StringRef FileName)>;
-  DWARFFile(StringRef Name, std::unique_ptr<DWARFContext> Dwarf,
-            std::unique_ptr<AddressesMap> Addresses,
-            UnloadCallbackTy UnloadFunc = nullptr)
-      : FileName(Name), Dwarf(std::move(Dwarf)),
-        Addresses(std::move(Addresses)), UnloadFunc(UnloadFunc) {}
-
-  /// The object file name.
-  StringRef FileName;
-
-  /// The source DWARF information.
-  std::unique_ptr<DWARFContext> Dwarf;
-
-  /// Helpful address information(list of valid address ranges, relocations).
-  std::unique_ptr<AddressesMap> Addresses;
-
-  /// Callback to the module keeping object file to unload.
-  UnloadCallbackTy UnloadFunc;
-
-  /// Unloads object file and corresponding AddressesMap and Dwarf Context.
-  void unload() {
-    Addresses.reset();
-    Dwarf.reset();
-
-    if (UnloadFunc)
-      UnloadFunc(FileName);
-  }
-};
-
-typedef std::map<std::string, std::string> swiftInterfacesMap;
-typedef std::map<std::string, std::string> objectPrefixMap;
-
-typedef function_ref<void(const DWARFUnit &Unit)> CompileUnitHandler;
-
 /// The core of the Dwarf linking logic.
 ///
 /// The generation of the dwarf information from the object files will be
@@ -334,41 +234,20 @@ typedef function_ref<void(const DWARFUnit &Unit)> CompileUnitHandler;
 /// a variable). These relocations are called ValidRelocs in the
 /// AddressesInfo and are gathered as a very first step when we start
 /// processing a object file.
-class DWARFLinker {
+class DWARFLinker : public DWARFLinkerBase {
 public:
-  typedef std::function<void(const Twine &Warning, StringRef Context,
-                             const DWARFDie *DIE)>
-      messageHandler;
-  DWARFLinker(messageHandler ErrorHandler, messageHandler WarningHandler,
+  DWARFLinker(MessageHandlerTy ErrorHandler, MessageHandlerTy WarningHandler,
               std::function<StringRef(StringRef)> StringsTranslator)
-      : DwarfLinkerClientID(DwarfLinkerClient::Dsymutil),
-        StringsTranslator(StringsTranslator), ErrorHandler(ErrorHandler),
+      : StringsTranslator(StringsTranslator), ErrorHandler(ErrorHandler),
         WarningHandler(WarningHandler) {}
 
   static std::unique_ptr<DWARFLinker> createLinker(
-      messageHandler ErrorHandler, messageHandler WarningHandler,
+      MessageHandlerTy ErrorHandler, MessageHandlerTy WarningHandler,
       std::function<StringRef(StringRef)> StringsTranslator = nullptr) {
     return std::make_unique<DWARFLinker>(ErrorHandler, WarningHandler,
                                          StringsTranslator);
   }
 
-  /// Type of output file.
-  enum class OutputFileType {
-    Object,
-    Assembly,
-  };
-
-  /// The kind of accelerator tables we should emit.
-  enum class AccelTableKind : uint8_t {
-    Apple,     ///< .apple_names, .apple_namespaces, .apple_types, .apple_objc.
-    Pub,       ///< .debug_pubnames, .debug_pubtypes
-    DebugNames ///< .debug_names.
-  };
-  typedef std::function<void(const DWARFFile &File, llvm::StringRef Output)> inputVerificationHandler;
-  typedef std::function<ErrorOr<DWARFFile &>(StringRef ContainerName,
-                                             StringRef Path)>
-      objFileLoader;
-
   Error createEmitter(const Triple &TheTriple, OutputFileType FileType,
                       raw_pwrite_stream &OutFile);
 
@@ -381,73 +260,84 @@ class DWARFLinker {
   ///
   /// \pre NoODR, Update options should be set before call to addObjectFile.
   void addObjectFile(
-      DWARFFile &File, objFileLoader Loader = nullptr,
-      CompileUnitHandler OnCUDieLoaded = [](const DWARFUnit &) {});
+      DWARFFile &File, ObjFileLoaderTy Loader = nullptr,
+      CompileUnitHandlerTy OnCUDieLoaded = [](const DWARFUnit &) {}) override;
 
   /// Link debug info for added objFiles. Object files are linked all together.
-  Error link();
+  Error link() override;
 
   /// A number of methods setting various linking options:
 
   /// Allows to generate log of linking process to the standard output.
-  void setVerbosity(bool Verbose) { Options.Verbose = Verbose; }
+  void setVerbosity(bool Verbose) override { Options.Verbose = Verbose; }
 
   /// Print statistics to standard output.
-  void setStatistics(bool Statistics) { Options.Statistics = Statistics; }
+  void setStatistics(bool Statistics) override {
+    Options.Statistics = Statistics;
+  }
 
   /// Verify the input DWARF.
-  void setVerifyInputDWARF(bool Verify) { Options.VerifyInputDWARF = Verify; }
+  void setVerifyInputDWARF(bool Verify) override {
+    Options.VerifyInputDWARF = Verify;
+  }
 
   /// Do not unique types according to ODR.
-  void setNoODR(bool NoODR) { Options.NoODR = NoODR; }
+  void setNoODR(bool NoODR) override { Options.NoODR = NoODR; }
 
   /// Update index tables only(do not modify rest of DWARF).
-  void setUpdateIndexTablesOnly(bool Update) { Options.Update = Update; }
+  void setUpdateIndexTablesOnly(bool Update) override {
+    Options.Update = Update;
+  }
 
   /// Allow generating valid, but non-deterministic output.
-  void setAllowNonDeterministicOutput(bool) { /* Nothing to do. */
+  void setAllowNonDeterministicOutput(bool) override { /* Nothing to do. */
   }
 
   /// Set whether to keep the enclosing function for a static variable.
-  void setKeepFunctionForStatic(bool KeepFunctionForStatic) {
+  void setKeepFunctionForStatic(bool KeepFunctionForStatic) override {
     Options.KeepFunctionForStatic = KeepFunctionForStatic;
   }
 
   /// Use specified number of threads for parallel files linking.
-  void setNumThreads(unsigned NumThreads) { Options.Threads = NumThreads; }
+  void setNumThreads(unsigned NumThreads) override {
+    Options.Threads = NumThreads;
+  }
 
   /// Add kind of accelerator tables to be generated.
-  void addAccelTableKind(AccelTableKind Kind) {
+  void addAccelTableKind(AccelTableKind Kind) override {
     assert(!llvm::is_contained(Options.AccelTables, Kind));
     Options.AccelTables.emplace_back(Kind);
   }
 
   /// Set prepend path for clang modules.
-  void setPrependPath(const std::string &Ppath) { Options.PrependPath = Ppath; }
+  void setPrependPath(const std::string &Ppath) override {
+    Options.PrependPath = Ppath;
+  }
 
   /// Set estimated objects files amount, for preliminary data allocation.
-  void setEstimatedObjfilesAmount(unsigned ObjFilesNum) {
+  void setEstimatedObjfilesAmount(unsigned ObjFilesNum) override {
     ObjectContexts.reserve(ObjFilesNum);
   }
 
   /// Set verification handler which would be used to report verification
   /// errors.
-  void setInputVerificationHandler(inputVerificationHandler Handler) {
+  void
+  setInputVerificationHandler(InputVerificationHandlerTy Handler) override {
     Options.InputVerificationHandler = Handler;
   }
 
   /// Set map for Swift interfaces.
-  void setSwiftInterfacesMap(swiftInterfacesMap *Map) {
+  void setSwiftInterfacesMap(SwiftInterfacesMapTy *Map) override {
     Options.ParseableSwiftInterfaces = Map;
   }
 
   /// Set prefix map for objects.
-  void setObjectPrefixMap(objectPrefixMap *Map) {
+  void setObjectPrefixMap(ObjectPrefixMapTy *Map) override {
     Options.ObjectPrefixMap = Map;
   }
 
   /// Set target DWARF version.
-  Error setTargetDWARFVersion(uint16_t TargetDWARFVersion) {
+  Error setTargetDWARFVersion(uint16_t TargetDWARFVersion) override {
     if ((TargetDWARFVersion < 1) || (TargetDWARFVersion > 5))
       return createStringError(std::errc::invalid_argument,
                                "unsupported DWARF version: %d",
@@ -619,16 +509,17 @@ class DWARFLinker {
   /// pointing to the module, and a DW_AT_gnu_dwo_id with the module
   /// hash.
   bool registerModuleReference(const DWARFDie &CUDie, LinkContext &Context,
-                               objFileLoader Loader,
-                               CompileUnitHandler OnCUDieLoaded,
+                               ObjFileLoaderTy Loader,
+                               CompileUnitHandlerTy OnCUDieLoaded,
                                unsigned Indent = 0);
 
   /// Recursively add the debug info in this clang module .pcm
   /// file (and all the modules imported by it in a bottom-up fashion)
   /// to ModuleUnits.
-  Error loadClangModule(objFileLoader Loader, const DWARFDie &CUDie,
+  Error loadClangModule(ObjFileLoaderTy Loader, const DWARFDie &CUDie,
                         const std::string &PCMFile, LinkContext &Context,
-                        CompileUnitHandler OnCUDieLoaded, unsigned Indent = 0);
+                        CompileUnitHandlerTy OnCUDieLoaded,
+                        unsigned Indent = 0);
 
   /// Clone specified Clang module unit \p Unit.
   Error cloneModuleUnit(LinkContext &Context, RefModuleUnit &Unit,
@@ -911,18 +802,16 @@ class DWARFLinker {
   /// Mapping the PCM filename to the DwoId.
   StringMap<uint64_t> ClangModules;
 
-  DwarfLinkerClient DwarfLinkerClientID;
-
   std::function<StringRef(StringRef)> StringsTranslator = nullptr;
 
   /// A unique ID that identifies each compile unit.
   unsigned UniqueUnitID = 0;
 
   // error handler
-  messageHandler ErrorHandler = nullptr;
+  MessageHandlerTy ErrorHandler = nullptr;
 
   // warning handler
-  messageHandler WarningHandler = nullptr;
+  MessageHandlerTy WarningHandler = nullptr;
 
   /// linking options
   struct DWARFLinkerOptions {
@@ -958,20 +847,21 @@ class DWARFLinker {
     std::string PrependPath;
 
     // input verification handler
-    inputVerificationHandler InputVerificationHandler = nullptr;
+    InputVerificationHandlerTy InputVerificationHandler = nullptr;
 
     /// A list of all .swiftinterface files referenced by the debug
     /// info, mapping Module name to path on disk. The entries need to
     /// be uniqued and sorted and there are only few entries expected
     /// per compile unit, which is why this is a std::map.
     /// this is dsymutil specific fag.
-    swiftInterfacesMap *ParseableSwiftInterfaces = nullptr;
+    SwiftInterfacesMapTy *ParseableSwiftInterfaces = nullptr;
 
     /// A list of remappings to apply to file paths.
-    objectPrefixMap *ObjectPrefixMap = nullptr;
+    ObjectPrefixMapTy *ObjectPrefixMap = nullptr;
   } Options;
 };
 
+} // end namespace dwarflinker
 } // end namespace llvm
 
-#endif // LLVM_DWARFLINKER_DWARFLINKER_H
+#endif // LLVM_DWARFLINKER_APPLE_DWARFLINKER_H
diff --git a/llvm/include/llvm/DWARFLinker/DWARFLinkerCompileUnit.h b/llvm/include/llvm/DWARFLinker/Apple/DWARFLinkerCompileUnit.h
similarity index 98%
rename from llvm/include/llvm/DWARFLinker/DWARFLinkerCompileUnit.h
rename to llvm/include/llvm/DWARFLinker/Apple/DWARFLinkerCompileUnit.h
index 08ebd4bc70bc93..915fba7c0bacc2 100644
--- a/llvm/include/llvm/DWARFLinker/DWARFLinkerCompileUnit.h
+++ b/llvm/include/llvm/DWARFLinker/Apple/DWARFLinkerCompileUnit.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_DWARFLINKER_DWARFLINKERCOMPILEUNIT_H
-#define LLVM_DWARFLINKER_DWARFLINKERCOMPILEUNIT_H
+#ifndef LLVM_DWARFLINKER_APPLE_DWARFLINKERCOMPILEUNIT_H
+#define LLVM_DWARFLINKER_APPLE_DWARFLINKERCOMPILEUNIT_H
 
 #include "llvm/ADT/AddressRanges.h"
 #include "llvm/ADT/DenseMap.h"
@@ -16,6 +16,7 @@
 #include <optional>
 
 namespace llvm {
+namespace dwarflinker {
 
 class DeclContext;
 
@@ -327,6 +328,7 @@ class CompileUnit {
   std::string ClangModuleName;
 };
 
+} // end namespace dwarflinker
 } // end namespace llvm
 
-#endif // LLVM_DWARFLINKER_DWARFLINKERCOMPILEUNIT_H
+#endif // LLVM_DWARFLINKER_APPLE_DWARFLINKERCOMPILEUNIT_H
diff --git a/llvm/include/llvm/DWARFLinker/DWARFLinkerDeclContext.h b/llvm/include/llvm/DWARFLinker/Apple/DWARFLinkerDeclContext.h
similarity index 96%
rename from llvm/include/llvm/DWARFLinker/DWARFLinkerDeclContext.h
rename to llvm/include/llvm/DWARFLinker/Apple/DWARFLinkerDeclContext.h
index fb02b0fc1b4dfe..dd10deb6378a3d 100644
--- a/llvm/include/llvm/DWARFLinker/DWARFLinkerDeclContext.h
+++ b/llvm/include/llvm/DWARFLinker/Apple/DWARFLinkerDeclContext.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_DWARFLINKER_DWARFLINKERDECLCONTEXT_H
-#define LLVM_DWARFLINKER_DWARFLINKERDECLCONTEXT_H
+#ifndef LLVM_DWARFLINKER_APPLE_DWARFLINKERDECLCONTEXT_H
+#define LLVM_DWARFLINKER_APPLE_DWARFLINKERDECLCONTEXT_H
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseMapInfo.h"
@@ -21,6 +21,7 @@
 #include <atomic>
 
 namespace llvm {
+namespace dwarflinker {
 
 class CompileUnit;
 struct DeclMapInfo;
@@ -184,6 +185,7 @@ struct DeclMapInfo : private DenseMapInfo<DeclContext *> {
   }
 };
 
+} // end namespace dwarflinker
 } // end namespace llvm
 
-#endif // LLVM_DWARFLINKER_DWARFLINKERDECLCONTEXT_H
+#endif // LLVM_DWARFLINKER_APPLE_DWARFLINKERDECLCONTEXT_H
diff --git a/llvm/include/llvm/DWARFLinker/DWARFStreamer.h b/llvm/include/llvm/DWARFLinker/Apple/DWARFStreamer.h
similarity index 98%
rename from llvm/include/llvm/DWARFLinker/DWARFStreamer.h
rename to llvm/include/llvm/DWARFLinker/Apple/DWARFStreamer.h
index 18eb7277bfa2df..52a34ddf1950cb 100644
--- a/llvm/include/llvm/DWARFLinker/DWARFStreamer.h
+++ b/llvm/include/llvm/DWARFLinker/Apple/DWARFStreamer.h
@@ -9,9 +9,9 @@
 #ifndef LLVM_DWARFLINKER_DWARFSTREAMER_H
 #define LLVM_DWARFLINKER_DWARFSTREAMER_H
 
+#include "DWARFLinker.h"
 #include "llvm/BinaryFormat/Swift.h"
 #include "llvm/CodeGen/AsmPrinter.h"
-#include "llvm/DWARFLinker/DWARFLinker.h"
 #include "llvm/MC/MCAsmInfo.h"
 #include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCInstrInfo.h"
@@ -23,6 +23,11 @@
 namespace llvm {
 template <typename DataT> class AccelTable;
 
+class MCCodeEmitter;
+class DWARFDebugMacro;
+
+namespace dwarflinker {
+
 ///   User of DwarfStreamer should call initialization code
 ///   for AsmPrinter:
 ///
@@ -31,9 +36,6 @@ template <typename DataT> class AccelTable;
 ///   InitializeAllTargets();
 ///   InitializeAllAsmPrinters();
 
-class MCCodeEmitter;
-class DWARFDebugMacro;
-
 /// The Dwarf streaming logic.
 ///
 /// All interactions with the MC layer that is used to build the debug
@@ -43,9 +45,10 @@ class DwarfStreamer : public DwarfEmitter {
   DwarfStreamer(DWARFLinker::OutputFileType OutFileType,
                 raw_pwrite_stream &OutFile,
                 std::function<StringRef(StringRef Input)> Translator,
-                DWARFLinker::messageHandler Warning)
+                DWARFLinker::MessageHandlerTy Warning)
       : OutFile(OutFile), OutFileType(OutFileType), Translator(Translator),
         WarningHandler(Warning) {}
+  virtual ~DwarfStreamer() = default;
 
   Error init(Triple TheTriple, StringRef Swift5ReflectionSegmentName);
 
@@ -310,9 +313,10 @@ class DwarfStreamer : public DwarfEmitter {
                              const CompileUnit &Unit,
                              const std::vector<CompileUnit::AccelInfo> &Names);
 
-  DWARFLinker::messageHandler WarningHandler = nullptr;
+  DWARFLinkerBase::MessageHandlerTy WarningHandler = nullptr;
 };
 
+} // end namespace dwarflinker
 } // end namespace llvm
 
 #endif // LLVM_DWARFLINKER_DWARFSTREAMER_H
diff --git a/llvm/include/llvm/DWARFLinkerParallel/DWARFFile.h b/llvm/include/llvm/DWARFLinker/DWARFFile.h
similarity index 79%
rename from llvm/include/llvm/DWARFLinkerParallel/DWARFFile.h
rename to llvm/include/llvm/DWARFLinker/DWARFFile.h
index c320530569bb05..a6997260dcf22e 100644
--- a/llvm/include/llvm/DWARFLinkerParallel/DWARFFile.h
+++ b/llvm/include/llvm/DWARFLinker/DWARFFile.h
@@ -6,18 +6,17 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_DWARFLINKERPARALLEL_DWARFFILE_H
-#define LLVM_DWARFLINKERPARALLEL_DWARFFILE_H
+#ifndef LLVM_DWARFLINKER_DWARFFILE_H
+#define LLVM_DWARFLINKER_DWARFFILE_H
 
+#include "AddressesMap.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/DWARFLinkerParallel/AddressesMap.h"
 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
-#include "llvm/Support/Endian.h"
 #include <functional>
 #include <memory>
 
 namespace llvm {
-namespace dwarflinker_parallel {
+namespace dwarflinker {
 
 /// This class represents DWARF information for source file
 /// and it's address map.
@@ -29,7 +28,9 @@ class DWARFFile {
 
   DWARFFile(StringRef Name, std::unique_ptr<DWARFContext> Dwarf,
             std::unique_ptr<AddressesMap> Addresses,
-            UnloadCallbackTy UnloadFunc = nullptr);
+            UnloadCallbackTy UnloadFunc = nullptr)
+      : FileName(Name), Dwarf(std::move(Dwarf)),
+        Addresses(std::move(Addresses)), UnloadFunc(UnloadFunc) {}
 
   /// Object file name.
   StringRef FileName;
@@ -53,7 +54,7 @@ class DWARFFile {
   }
 };
 
-} // end namespace dwarflinker_parallel
+} // end namespace dwarflinker
 } // end namespace llvm
 
-#endif // LLVM_DWARFLINKERPARALLEL_DWARFFILE_H
+#endif // LLVM_DWARFLINKER_DWARFFILE_H
diff --git a/llvm/include/llvm/DWARFLinker/DWARFLinkerBase.h b/llvm/include/llvm/DWARFLinker/DWARFLinkerBase.h
new file mode 100644
index 00000000000000..a7dc77cb1a8a64
--- /dev/null
+++ b/llvm/include/llvm/DWARFLinker/DWARFLinkerBase.h
@@ -0,0 +1,98 @@
+//===- DWARFLinkerBase.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_DWARFLINKER_DWARFLINKERBASE_H
+#define LLVM_DWARFLINKER_DWARFLINKERBASE_H
+#include "AddressesMap.h"
+#include "DWARFFile.h"
+#include "llvm/ADT/AddressRanges.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/DebugInfo/DWARF/DWARFContext.h"
+#include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
+#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
+#include "llvm/DebugInfo/DWARF/DWARFDie.h"
+#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
+#include <map>
+namespace llvm {
+class DWARFUnit;
+
+namespace dwarflinker {
+
+/// The base interface for DWARFLinker implementations.
+class DWARFLinkerBase {
+public:
+  virtual ~DWARFLinkerBase() = default;
+  using MessageHandlerTy = std::function<void(
+      const Twine &Warning, StringRef Context, const DWARFDie *DIE)>;
+  using ObjFileLoaderTy = std::function<ErrorOr<DWARFFile &>(
+      StringRef ContainerName, StringRef Path)>;
+  using InputVerificationHandlerTy =
+      std::function<void(const DWARFFile &File, llvm::StringRef Output)>;
+  using ObjectPrefixMapTy = std::map<std::string, std::string>;
+  using CompileUnitHandlerTy = function_ref<void(const DWARFUnit &Unit)>;
+  using TranslatorFuncTy = std::function<StringRef(StringRef)>;
+  using SwiftInterfacesMapTy = std::map<std::string, std::string>;
+  /// Type of output file.
+  enum class OutputFileType : uint8_t {
+    Object,
+    Assembly,
+  };
+  /// The kind of accelerator tables we should emit.
+  enum class AccelTableKind : uint8_t {
+    Apple,     ///< .apple_names, .apple_namespaces, .apple_types, .apple_objc.
+    Pub,       ///< .debug_pubnames, .debug_pubtypes
+    DebugNames ///< .debug_names.
+  };
+  /// Add object file to be linked. Pre-load compile unit die. Call
+  /// \p OnCUDieLoaded for each compile unit die. If specified \p File
+  /// has reference to the Clang module then such module would be
+  /// pre-loaded by \p Loader for !Update case.
+  ///
+  /// \pre NoODR, Update options should be set before call to addObjectFile.
+  virtual void addObjectFile(
+      DWARFFile &File, ObjFileLoaderTy Loader = nullptr,
+      CompileUnitHandlerTy OnCUDieLoaded = [](const DWARFUnit &) {}) = 0;
+  /// Link debug info for added objFiles. Object files are linked all together.
+  virtual Error link() = 0;
+  /// A number of methods setting various linking options:
+  /// Allows to generate log of linking process to the standard output.
+  virtual void setVerbosity(bool Verbose) = 0;
+  /// Print statistics to standard output.
+  virtual void setStatistics(bool Statistics) = 0;
+  /// Verify the input DWARF.
+  virtual void setVerifyInputDWARF(bool Verify) = 0;
+  /// Do not unique types according to ODR.
+  virtual void setNoODR(bool NoODR) = 0;
+  /// Update index tables only(do not modify rest of DWARF).
+  virtual void setUpdateIndexTablesOnly(bool Update) = 0;
+  /// Allow generating valid, but non-deterministic output.
+  virtual void setAllowNonDeterministicOutput(bool) = 0;
+  /// Set whether to keep the enclosing function for a static variable.
+  virtual void setKeepFunctionForStatic(bool KeepFunctionForStatic) = 0;
+  /// Use specified number of threads for parallel files linking.
+  virtual void setNumThreads(unsigned NumThreads) = 0;
+  /// Add kind of accelerator tables to be generated.
+  virtual void addAccelTableKind(AccelTableKind Kind) = 0;
+  /// Set prepend path for clang modules.
+  virtual void setPrependPath(const std::string &Ppath) = 0;
+  /// Set estimated objects files amount, for preliminary data allocation.
+  virtual void setEstimatedObjfilesAmount(unsigned ObjFilesNum) = 0;
+  /// Set verification handler which would be used to report verification
+  /// errors.
+  virtual void
+  setInputVerificationHandler(InputVerificationHandlerTy Handler) = 0;
+  /// Set map for Swift interfaces.
+  virtual void setSwiftInterfacesMap(SwiftInterfacesMapTy *Map) = 0;
+  /// Set prefix map for objects.
+  virtual void setObjectPrefixMap(ObjectPrefixMapTy *Map) = 0;
+  /// Set target DWARF version.
+  virtual Error setTargetDWARFVersion(uint16_t TargetDWARFVersion) = 0;
+};
+} // end namespace dwarflinker
+} // end namespace llvm
+#endif // LLVM_DWARFLINKER_DWARFLINKERBASE_H
diff --git a/llvm/include/llvm/DWARFLinkerParallel/DWARFLinker.h b/llvm/include/llvm/DWARFLinker/LLVM/DWARFLinker.h
similarity index 59%
rename from llvm/include/llvm/DWARFLinkerParallel/DWARFLinker.h
rename to llvm/include/llvm/DWARFLinker/LLVM/DWARFLinker.h
index c16c94d65c2fe6..a7d5e9db97ef4b 100644
--- a/llvm/include/llvm/DWARFLinkerParallel/DWARFLinker.h
+++ b/llvm/include/llvm/DWARFLinker/LLVM/DWARFLinker.h
@@ -6,11 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_DWARFLINKERPARALLEL_DWARFLINKER_H
-#define LLVM_DWARFLINKERPARALLEL_DWARFLINKER_H
+#ifndef LLVM_DWARFLINKERPARALLEL_LLVM_DWARFLINKER_H
+#define LLVM_DWARFLINKERPARALLEL_LLVM_DWARFLINKER_H
 
 #include "llvm/CodeGen/AsmPrinter.h"
-#include "llvm/DWARFLinkerParallel/DWARFFile.h"
+#include "llvm/DWARFLinker/DWARFFile.h"
+#include "llvm/DWARFLinker/DWARFLinkerBase.h"
 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
 #include "llvm/DebugInfo/DWARF/DWARFDie.h"
 #include "llvm/MC/MCDwarf.h"
@@ -85,6 +86,7 @@
 ///
 
 namespace llvm {
+namespace dwarflinker {
 namespace dwarflinker_parallel {
 
 /// ExtraDwarfEmitter allows adding extra data to the DWARFLinker output.
@@ -111,31 +113,8 @@ class ExtraDwarfEmitter {
   virtual AsmPrinter &getAsmPrinter() const = 0;
 };
 
-class DWARFLinker {
+class DWARFLinker : public DWARFLinkerBase {
 public:
-  /// Type of output file.
-  enum class OutputFileType {
-    Object,
-    Assembly,
-  };
-
-  /// The kind of accelerator tables we should emit.
-  enum class AccelTableKind : uint8_t {
-    Apple,     ///< .apple_names, .apple_namespaces, .apple_types, .apple_objc.
-    Pub,       ///< .debug_pubnames, .debug_pubtypes
-    DebugNames ///< .debug_names.
-  };
-
-  using MessageHandlerTy = std::function<void(
-      const Twine &Warning, StringRef Context, const DWARFDie *DIE)>;
-  using ObjFileLoaderTy = std::function<ErrorOr<DWARFFile &>(
-      StringRef ContainerName, StringRef Path)>;
-  using InputVerificationHandlerTy = std::function<void(const DWARFFile &File, llvm::StringRef Output)>;
-  using ObjectPrefixMapTy = std::map<std::string, std::string>;
-  using CompileUnitHandlerTy = function_ref<void(const DWARFUnit &Unit)>;
-  using TranslatorFuncTy = std::function<StringRef(StringRef)>;
-  using SwiftInterfacesMapTy = std::map<std::string, std::string>;
-
   virtual ~DWARFLinker() = default;
 
   /// Creates dwarf linker instance.
@@ -149,75 +128,10 @@ class DWARFLinker {
 
   /// Returns previously created dwarf emitter. May be nullptr.
   virtual ExtraDwarfEmitter *getEmitter() = 0;
-
-  /// Add object file to be linked. Pre-load compile unit die. Call
-  /// \p OnCUDieLoaded for each compile unit die. If specified \p File
-  /// has reference to the Clang module then such module would be
-  /// pre-loaded by \p Loader for !Update case.
-  ///
-  /// \pre NoODR, Update options should be set before call to addObjectFile.
-  virtual void addObjectFile(
-      DWARFFile &File, ObjFileLoaderTy Loader = nullptr,
-      CompileUnitHandlerTy OnCUDieLoaded = [](const DWARFUnit &) {}) = 0;
-
-  /// Link debug info for added files.
-  virtual Error link() = 0;
-
-  /// \defgroup Methods setting various linking options:
-  ///
-  /// @{
-
-  /// Allows to generate log of linking process to the standard output.
-  virtual void setVerbosity(bool Verbose) = 0;
-
-  /// Print statistics to standard output.
-  virtual void setStatistics(bool Statistics) = 0;
-
-  /// Verify the input DWARF.
-  virtual void setVerifyInputDWARF(bool Verify) = 0;
-
-  /// Do not unique types according to ODR.
-  virtual void setNoODR(bool NoODR) = 0;
-
-  /// Update index tables only(do not modify rest of DWARF).
-  virtual void setUpdateIndexTablesOnly(bool UpdateIndexTablesOnly) = 0;
-
-  /// Allow generating valid, but non-deterministic output.
-  virtual void
-  setAllowNonDeterministicOutput(bool AllowNonDeterministicOutput) = 0;
-
-  /// Set to keep the enclosing function for a static variable.
-  virtual void setKeepFunctionForStatic(bool KeepFunctionForStatic) = 0;
-
-  /// Use specified number of threads for parallel files linking.
-  virtual void setNumThreads(unsigned NumThreads) = 0;
-
-  /// Add kind of accelerator tables to be generated.
-  virtual void addAccelTableKind(AccelTableKind Kind) = 0;
-
-  /// Set prepend path for clang modules.
-  virtual void setPrependPath(const std::string &Ppath) = 0;
-
-  /// Set estimated objects files amount, for preliminary data allocation.
-  virtual void setEstimatedObjfilesAmount(unsigned ObjFilesNum) = 0;
-
-  /// Set verification handler which would be used to report verification
-  /// errors.
-  virtual void
-  setInputVerificationHandler(InputVerificationHandlerTy Handler) = 0;
-
-  /// Set map for Swift interfaces.
-  virtual void setSwiftInterfacesMap(SwiftInterfacesMapTy *Map) = 0;
-
-  /// Set prefix map for objects.
-  virtual void setObjectPrefixMap(ObjectPrefixMapTy *Map) = 0;
-
-  /// Set target DWARF version.
-  virtual Error setTargetDWARFVersion(uint16_t TargetDWARFVersion) = 0;
-  /// @}
 };
 
 } // end namespace dwarflinker_parallel
+} // end namespace dwarflinker
 } // end namespace llvm
 
-#endif // LLVM_DWARFLINKERPARALLEL_DWARFLINKER_H
+#endif // LLVM_DWARFLINKERPARALLEL_LLVM_DWARFLINKER_H
diff --git a/llvm/include/llvm/DWARFLinkerParallel/StringPool.h b/llvm/include/llvm/DWARFLinker/StringPool.h
similarity index 91%
rename from llvm/include/llvm/DWARFLinkerParallel/StringPool.h
rename to llvm/include/llvm/DWARFLinker/StringPool.h
index e55909f343116d..87a3309f35afac 100644
--- a/llvm/include/llvm/DWARFLinkerParallel/StringPool.h
+++ b/llvm/include/llvm/DWARFLinker/StringPool.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_DWARFLINKERPARALLEL_STRINGPOOL_H
-#define LLVM_DWARFLINKERPARALLEL_STRINGPOOL_H
+#ifndef LLVM_DWARFLINKER_STRINGPOOL_H
+#define LLVM_DWARFLINKER_STRINGPOOL_H
 
 #include "llvm/ADT/ConcurrentHashtable.h"
 #include "llvm/CodeGen/DwarfStringPoolEntry.h"
@@ -16,7 +16,7 @@
 #include <string_view>
 
 namespace llvm {
-namespace dwarflinker_parallel {
+namespace dwarflinker {
 
 /// StringEntry keeps data of the string: the length, external offset
 /// and a string body which is placed right after StringEntry.
@@ -69,7 +69,7 @@ class StringPool
   parallel::PerThreadBumpPtrAllocator Allocator;
 };
 
-} // end of namespace dwarflinker_parallel
+} // end of namespace dwarflinker
 } // end namespace llvm
 
-#endif // LLVM_DWARFLINKERPARALLEL_STRINGPOOL_H
+#endif // LLVM_DWARFLINKER_STRINGPOOL_H
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugMacro.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugMacro.h
index 6b1b2ae6d7e049..3fc9b05e6d0a6e 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugMacro.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugMacro.h
@@ -18,11 +18,14 @@
 namespace llvm {
 
 class raw_ostream;
+
+namespace dwarflinker {
 class DwarfStreamer;
+}
 
 class DWARFDebugMacro {
-  friend DwarfStreamer;
-  friend dwarflinker_parallel::CompileUnit;
+  friend dwarflinker::DwarfStreamer;
+  friend dwarflinker::dwarflinker_parallel::CompileUnit;
 
   /// DWARFv5 section 6.3.1 Macro Information Header.
   enum HeaderFlagMask {
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
index 7084081ce61a43..286b67a82d68a4 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
@@ -43,9 +43,11 @@ class DWARFObject;
 class raw_ostream;
 struct DIDumpOptions;
 struct DWARFSection;
+namespace dwarflinker {
 namespace dwarflinker_parallel {
 class CompileUnit;
 }
+} // namespace dwarflinker
 
 /// Base class describing the header of any kind of "unit."  Some information
 /// is specific to certain unit types.  We separate this class out so we can
@@ -256,7 +258,7 @@ class DWARFUnit {
   std::shared_ptr<DWARFUnit> DWO;
 
 protected:
-  friend dwarflinker_parallel::CompileUnit;
+  friend dwarflinker::dwarflinker_parallel::CompileUnit;
 
   /// Return the index of a \p Die entry inside the unit's DIE vector.
   ///
diff --git a/llvm/lib/CMakeLists.txt b/llvm/lib/CMakeLists.txt
index 283baa6090eb9a..ea22ff21820a98 100644
--- a/llvm/lib/CMakeLists.txt
+++ b/llvm/lib/CMakeLists.txt
@@ -14,7 +14,6 @@ add_subdirectory(BinaryFormat)
 add_subdirectory(Bitcode)
 add_subdirectory(Bitstream)
 add_subdirectory(DWARFLinker)
-add_subdirectory(DWARFLinkerParallel)
 add_subdirectory(Extensions)
 add_subdirectory(Frontend)
 add_subdirectory(Transforms)
diff --git a/llvm/lib/DWARFLinker/Apple/CMakeLists.txt b/llvm/lib/DWARFLinker/Apple/CMakeLists.txt
new file mode 100644
index 00000000000000..b173d42eb01539
--- /dev/null
+++ b/llvm/lib/DWARFLinker/Apple/CMakeLists.txt
@@ -0,0 +1,24 @@
+add_llvm_component_library(LLVMDWARFLinker
+  DWARFLinkerCompileUnit.cpp
+  DWARFLinkerDeclContext.cpp
+  DWARFLinker.cpp
+  DWARFStreamer.cpp
+
+  ADDITIONAL_HEADER_DIRS
+  ${LLVM_MAIN_INCLUDE_DIR}/llvm/DWARFLinker
+
+  DEPENDS
+  intrinsics_gen
+
+  LINK_COMPONENTS
+  AsmPrinter
+  BinaryFormat
+  CodeGen
+  CodeGenTypes
+  DebugInfoDWARF
+  DWARFLinkerBase
+  MC
+  Object
+  Support
+  TargetParser
+  )
diff --git a/llvm/lib/DWARFLinker/DWARFLinker.cpp b/llvm/lib/DWARFLinker/Apple/DWARFLinker.cpp
similarity index 98%
rename from llvm/lib/DWARFLinker/DWARFLinker.cpp
rename to llvm/lib/DWARFLinker/Apple/DWARFLinker.cpp
index 10967123a562e7..173601cfe71e93 100644
--- a/llvm/lib/DWARFLinker/DWARFLinker.cpp
+++ b/llvm/lib/DWARFLinker/Apple/DWARFLinker.cpp
@@ -6,14 +6,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/DWARFLinker/DWARFLinker.h"
+#include "llvm/DWARFLinker/Apple/DWARFLinker.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/BitVector.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/CodeGen/NonRelocatableStringpool.h"
-#include "llvm/DWARFLinker/DWARFLinkerDeclContext.h"
-#include "llvm/DWARFLinker/DWARFStreamer.h"
+#include "llvm/DWARFLinker/Apple/DWARFLinkerDeclContext.h"
+#include "llvm/DWARFLinker/Apple/DWARFStreamer.h"
 #include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
 #include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h"
 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
@@ -39,6 +39,8 @@
 
 namespace llvm {
 
+using namespace dwarflinker;
+
 /// Hold the input and output of the debug info size in bytes.
 struct DebugInfoSize {
   uint64_t Input;
@@ -137,10 +139,6 @@ static bool isTypeTag(uint16_t Tag) {
   return false;
 }
 
-AddressesMap::~AddressesMap() = default;
-
-DwarfEmitter::~DwarfEmitter() = default;
-
 bool DWARFLinker::DIECloner::getDIENames(const DWARFDie &Die,
                                          AttributesInfo &Info,
                                          OffsetsStringPool &StringPool,
@@ -195,7 +193,7 @@ static SmallString<128> guessToolchainBaseDir(StringRef SysRoot) {
 /// DW_TAG_module blocks.
 static void analyzeImportedModule(
     const DWARFDie &DIE, CompileUnit &CU,
-    swiftInterfacesMap *ParseableSwiftInterfaces,
+    DWARFLinkerBase::SwiftInterfacesMapTy *ParseableSwiftInterfaces,
     std::function<void(const Twine &, const DWARFDie &)> ReportWarning) {
   if (CU.getLanguage() != dwarf::DW_LANG_Swift)
     return;
@@ -307,7 +305,8 @@ static void updateChildPruning(const DWARFDie &Die, CompileUnit &CU,
 static void analyzeContextInfo(
     const DWARFDie &DIE, unsigned ParentIdx, CompileUnit &CU,
     DeclContext *CurrentDeclContext, DeclContextTree &Contexts,
-    uint64_t ModulesEndOffset, swiftInterfacesMap *ParseableSwiftInterfaces,
+    uint64_t ModulesEndOffset,
+    DWARFLinkerBase::SwiftInterfacesMapTy *ParseableSwiftInterfaces,
     std::function<void(const Twine &, const DWARFDie &)> ReportWarning) {
   // LIFO work list.
   std::vector<ContextWorklistItem> Worklist;
@@ -1357,9 +1356,9 @@ unsigned DWARFLinker::DIECloner::cloneAddressAttribute(
   //     independently by the linker).
   //   - If address relocated in an inline_subprogram that happens at the
   //     beginning of its inlining function.
-  //  To avoid above cases and to not apply relocation twice (in applyValidRelocs
-  //  and here), read address attribute from InputDIE and apply Info.PCOffset
-  //  here.
+  //  To avoid above cases and to not apply relocation twice (in
+  //  applyValidRelocs and here), read address attribute from InputDIE and apply
+  //  Info.PCOffset here.
 
   std::optional<DWARFFormValue> AddrAttribute = InputDIE.find(AttrSpec.Attr);
   if (!AddrAttribute)
@@ -1411,7 +1410,7 @@ unsigned DWARFLinker::DIECloner::cloneScalarAttribute(
   // need to remove the attribute.
   if (AttrSpec.Attr == dwarf::DW_AT_macro_info) {
     if (std::optional<uint64_t> Offset = Val.getAsSectionOffset()) {
-      const DWARFDebugMacro *Macro = File.Dwarf->getDebugMacinfo();
+      const llvm::DWARFDebugMacro *Macro = File.Dwarf->getDebugMacinfo();
       if (Macro == nullptr || !Macro->hasEntryForOffset(*Offset))
         return 0;
     }
@@ -1419,7 +1418,7 @@ unsigned DWARFLinker::DIECloner::cloneScalarAttribute(
 
   if (AttrSpec.Attr == dwarf::DW_AT_macros) {
     if (std::optional<uint64_t> Offset = Val.getAsSectionOffset()) {
-      const DWARFDebugMacro *Macro = File.Dwarf->getDebugMacro();
+      const llvm::DWARFDebugMacro *Macro = File.Dwarf->getDebugMacro();
       if (Macro == nullptr || !Macro->hasEntryForOffset(*Offset))
         return 0;
     }
@@ -2040,8 +2039,7 @@ static void patchAddrBase(DIE &Die, DIEInteger Offset) {
 }
 
 void DWARFLinker::DIECloner::emitDebugAddrSection(
-    CompileUnit &Unit,
-    const uint16_t DwarfVersion) const {
+    CompileUnit &Unit, const uint16_t DwarfVersion) const {
 
   if (LLVM_UNLIKELY(Linker.Options.Update))
     return;
@@ -2407,8 +2405,9 @@ static uint64_t getDwoId(const DWARFDie &CUDie) {
   return 0;
 }
 
-static std::string remapPath(StringRef Path,
-                             const objectPrefixMap &ObjectPrefixMap) {
+static std::string
+remapPath(StringRef Path,
+          const DWARFLinkerBase::ObjectPrefixMapTy &ObjectPrefixMap) {
   if (ObjectPrefixMap.empty())
     return Path.str();
 
@@ -2419,8 +2418,9 @@ static std::string remapPath(StringRef Path,
   return p.str().str();
 }
 
-static std::string getPCMFile(const DWARFDie &CUDie,
-                              objectPrefixMap *ObjectPrefixMap) {
+static std::string
+getPCMFile(const DWARFDie &CUDie,
+           const DWARFLinkerBase::ObjectPrefixMapTy *ObjectPrefixMap) {
   std::string PCMFile = dwarf::toString(
       CUDie.find({dwarf::DW_AT_dwo_name, dwarf::DW_AT_GNU_dwo_name}), "");
 
@@ -2477,8 +2477,8 @@ std::pair<bool, bool> DWARFLinker::isClangModuleRef(const DWARFDie &CUDie,
 
 bool DWARFLinker::registerModuleReference(const DWARFDie &CUDie,
                                           LinkContext &Context,
-                                          objFileLoader Loader,
-                                          CompileUnitHandler OnCUDieLoaded,
+                                          ObjFileLoaderTy Loader,
+                                          CompileUnitHandlerTy OnCUDieLoaded,
                                           unsigned Indent) {
   std::string PCMFile = getPCMFile(CUDie, Options.ObjectPrefixMap);
   std::pair<bool, bool> IsClangModuleRef =
@@ -2505,11 +2505,9 @@ bool DWARFLinker::registerModuleReference(const DWARFDie &CUDie,
   return true;
 }
 
-Error DWARFLinker::loadClangModule(objFileLoader Loader, const DWARFDie &CUDie,
-                                   const std::string &PCMFile,
-                                   LinkContext &Context,
-                                   CompileUnitHandler OnCUDieLoaded,
-                                   unsigned Indent) {
+Error DWARFLinker::loadClangModule(
+    ObjFileLoaderTy Loader, const DWARFDie &CUDie, const std::string &PCMFile,
+    LinkContext &Context, CompileUnitHandlerTy OnCUDieLoaded, unsigned Indent) {
 
   uint64_t DwoId = getDwoId(CUDie);
   std::string ModuleName = dwarf::toString(CUDie.find(dwarf::DW_AT_name), "");
@@ -2673,8 +2671,8 @@ void DWARFLinker::copyInvariantDebugSection(DWARFContext &Dwarf) {
       Dwarf.getDWARFObj().getLoclistsSection().Data, "debug_loclists");
 }
 
-void DWARFLinker::addObjectFile(DWARFFile &File, objFileLoader Loader,
-                                CompileUnitHandler OnCUDieLoaded) {
+void DWARFLinker::addObjectFile(DWARFFile &File, ObjFileLoaderTy Loader,
+                                CompileUnitHandlerTy OnCUDieLoaded) {
   ObjectContexts.emplace_back(LinkContext(File));
 
   if (ObjectContexts.back().File.Dwarf) {
@@ -2713,12 +2711,8 @@ Error DWARFLinker::link() {
   DeclContextTree ODRContexts;
 
   for (LinkContext &OptContext : ObjectContexts) {
-    if (Options.Verbose) {
-      if (DwarfLinkerClientID == DwarfLinkerClient::Dsymutil)
-        outs() << "DEBUG MAP OBJECT: " << OptContext.File.FileName << "\n";
-      else
-        outs() << "OBJECT FILE: " << OptContext.File.FileName << "\n";
-    }
+    if (Options.Verbose)
+      outs() << "DEBUG MAP OBJECT: " << OptContext.File.FileName << "\n";
 
     if (!OptContext.File.Dwarf)
       continue;
@@ -3039,7 +3033,6 @@ Error DWARFLinker::cloneModuleUnit(LinkContext &Context, RefModuleUnit &Unit,
 void DWARFLinker::verifyInput(const DWARFFile &File) {
   assert(File.Dwarf);
 
-
   std::string Buffer;
   raw_string_ostream OS(Buffer);
   DIDumpOptions DumpOpts;
diff --git a/llvm/lib/DWARFLinker/DWARFLinkerCompileUnit.cpp b/llvm/lib/DWARFLinker/Apple/DWARFLinkerCompileUnit.cpp
similarity index 97%
rename from llvm/lib/DWARFLinker/DWARFLinkerCompileUnit.cpp
rename to llvm/lib/DWARFLinker/Apple/DWARFLinkerCompileUnit.cpp
index 06559bc38c86cc..8748e9470207c1 100644
--- a/llvm/lib/DWARFLinker/DWARFLinkerCompileUnit.cpp
+++ b/llvm/lib/DWARFLinker/Apple/DWARFLinkerCompileUnit.cpp
@@ -6,15 +6,17 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/DWARFLinker/DWARFLinkerCompileUnit.h"
+#include "llvm/DWARFLinker/Apple/DWARFLinkerCompileUnit.h"
 #include "llvm/ADT/StringExtras.h"
-#include "llvm/DWARFLinker/DWARFLinkerDeclContext.h"
+#include "llvm/DWARFLinker/Apple/DWARFLinkerDeclContext.h"
 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
 #include "llvm/DebugInfo/DWARF/DWARFExpression.h"
 #include "llvm/Support/FormatVariadic.h"
 
 namespace llvm {
 
+using namespace dwarflinker;
+
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 LLVM_DUMP_METHOD void CompileUnit::DIEInfo::dump() {
   llvm::errs() << "{\n";
diff --git a/llvm/lib/DWARFLinker/DWARFLinkerDeclContext.cpp b/llvm/lib/DWARFLinker/Apple/DWARFLinkerDeclContext.cpp
similarity index 98%
rename from llvm/lib/DWARFLinker/DWARFLinkerDeclContext.cpp
rename to llvm/lib/DWARFLinker/Apple/DWARFLinkerDeclContext.cpp
index 015a4f9e8ac6bb..314f53e0170f36 100644
--- a/llvm/lib/DWARFLinker/DWARFLinkerDeclContext.cpp
+++ b/llvm/lib/DWARFLinker/Apple/DWARFLinkerDeclContext.cpp
@@ -6,14 +6,16 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/DWARFLinker/DWARFLinkerDeclContext.h"
-#include "llvm/DWARFLinker/DWARFLinkerCompileUnit.h"
+#include "llvm/DWARFLinker/Apple/DWARFLinkerDeclContext.h"
+#include "llvm/DWARFLinker/Apple/DWARFLinkerCompileUnit.h"
 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
 #include "llvm/DebugInfo/DWARF/DWARFDie.h"
 #include "llvm/DebugInfo/DWARF/DWARFUnit.h"
 
 namespace llvm {
 
+using namespace dwarflinker;
+
 /// Set the last DIE/CU a context was seen in and, possibly invalidate the
 /// context if it is ambiguous.
 ///
diff --git a/llvm/lib/DWARFLinker/DWARFStreamer.cpp b/llvm/lib/DWARFLinker/Apple/DWARFStreamer.cpp
similarity index 99%
rename from llvm/lib/DWARFLinker/DWARFStreamer.cpp
rename to llvm/lib/DWARFLinker/Apple/DWARFStreamer.cpp
index cd649c328ed930..2a9b0827af7c11 100644
--- a/llvm/lib/DWARFLinker/DWARFStreamer.cpp
+++ b/llvm/lib/DWARFLinker/Apple/DWARFStreamer.cpp
@@ -6,9 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/DWARFLinker/DWARFStreamer.h"
+#include "llvm/DWARFLinker/Apple/DWARFStreamer.h"
 #include "llvm/CodeGen/NonRelocatableStringpool.h"
-#include "llvm/DWARFLinker/DWARFLinkerCompileUnit.h"
+#include "llvm/DWARFLinker/Apple/DWARFLinkerCompileUnit.h"
 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
 #include "llvm/DebugInfo/DWARF/DWARFDebugMacro.h"
 #include "llvm/MC/MCAsmBackend.h"
@@ -26,7 +26,8 @@
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/TargetParser/Triple.h"
 
-namespace llvm {
+using namespace llvm;
+using namespace dwarflinker;
 
 Error DwarfStreamer::init(Triple TheTriple,
                           StringRef Swift5ReflectionSegmentName) {
@@ -1404,5 +1405,3 @@ void DwarfStreamer::emitMacroTableImpl(const DWARFDebugMacro *MacroTable,
     }
   }
 }
-
-} // namespace llvm
diff --git a/llvm/lib/DWARFLinker/CMakeLists.txt b/llvm/lib/DWARFLinker/CMakeLists.txt
index f720c5e844b36e..947b21bce2d2e0 100644
--- a/llvm/lib/DWARFLinker/CMakeLists.txt
+++ b/llvm/lib/DWARFLinker/CMakeLists.txt
@@ -1,23 +1,18 @@
-add_llvm_component_library(LLVMDWARFLinker
-  DWARFLinkerCompileUnit.cpp
-  DWARFLinkerDeclContext.cpp
-  DWARFLinker.cpp
-  DWARFStreamer.cpp
+add_llvm_component_library(LLVMDWARFLinkerBase
+  Utils.cpp
 
   ADDITIONAL_HEADER_DIRS
   ${LLVM_MAIN_INCLUDE_DIR}/llvm/DWARFLinker
-
   DEPENDS
   intrinsics_gen
 
   LINK_COMPONENTS
-  AsmPrinter
   BinaryFormat
   CodeGen
-  CodeGenTypes
   DebugInfoDWARF
-  MC
   Object
   Support
-  TargetParser
   )
+
+add_subdirectory(Apple)
+add_subdirectory(LLVM)
diff --git a/llvm/lib/DWARFLinkerParallel/AcceleratorRecordsSaver.cpp b/llvm/lib/DWARFLinker/LLVM/AcceleratorRecordsSaver.cpp
similarity index 98%
rename from llvm/lib/DWARFLinkerParallel/AcceleratorRecordsSaver.cpp
rename to llvm/lib/DWARFLinker/LLVM/AcceleratorRecordsSaver.cpp
index 5ec25cfe5fd26e..0d8a4113d4d417 100644
--- a/llvm/lib/DWARFLinkerParallel/AcceleratorRecordsSaver.cpp
+++ b/llvm/lib/DWARFLinker/LLVM/AcceleratorRecordsSaver.cpp
@@ -11,8 +11,9 @@
 #include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h"
 #include "llvm/Support/DJB.h"
 
-namespace llvm {
-namespace dwarflinker_parallel {
+using namespace llvm;
+using namespace dwarflinker;
+using namespace dwarflinker_parallel;
 
 static uint32_t hashFullyQualifiedName(CompileUnit &InputCU, DWARFDie &InputDIE,
                                        int ChildRecurseDepth = 0) {
@@ -290,6 +291,3 @@ void AcceleratorRecordsSaver::saveTypeRecord(StringEntry *Name, DIE *OutDIE,
   Info.TypeEntryBodyPtr = TypeEntry->getValue().load();
   OutUnit.getAsTypeUnit()->saveAcceleratorInfo(Info);
 }
-
-} // end of namespace dwarflinker_parallel
-} // namespace llvm
diff --git a/llvm/lib/DWARFLinkerParallel/AcceleratorRecordsSaver.h b/llvm/lib/DWARFLinker/LLVM/AcceleratorRecordsSaver.h
similarity index 91%
rename from llvm/lib/DWARFLinkerParallel/AcceleratorRecordsSaver.h
rename to llvm/lib/DWARFLinker/LLVM/AcceleratorRecordsSaver.h
index 5e7f4d0c3166fd..22504f1f45f6a5 100644
--- a/llvm/lib/DWARFLinkerParallel/AcceleratorRecordsSaver.h
+++ b/llvm/lib/DWARFLinker/LLVM/AcceleratorRecordsSaver.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIB_DWARFLINKERPARALLEL_ACCELERATORRECORDSSAVER_H
-#define LLVM_LIB_DWARFLINKERPARALLEL_ACCELERATORRECORDSSAVER_H
+#ifndef LLVM_LIB_DWARFLINKER_LLVM_ACCELERATORRECORDSSAVER_H
+#define LLVM_LIB_DWARFLINKER_LLVM_ACCELERATORRECORDSSAVER_H
 
 #include "DIEAttributeCloner.h"
 #include "DWARFLinkerCompileUnit.h"
@@ -15,6 +15,7 @@
 #include "DWARFLinkerTypeUnit.h"
 
 namespace llvm {
+namespace dwarflinker {
 namespace dwarflinker_parallel {
 
 /// This class helps to store information for accelerator entries.
@@ -65,6 +66,7 @@ class AcceleratorRecordsSaver {
 };
 
 } // end of namespace dwarflinker_parallel
+} // end of namespace dwarflinker
 } // end namespace llvm
 
-#endif // LLVM_LIB_DWARFLINKERPARALLEL_ACCELERATORRECORDSSAVER_H
+#endif // LLVM_LIB_DWARFLINKER_LLVM_ACCELERATORRECORDSSAVER_H
diff --git a/llvm/lib/DWARFLinkerParallel/ArrayList.h b/llvm/lib/DWARFLinker/LLVM/ArrayList.h
similarity index 96%
rename from llvm/lib/DWARFLinkerParallel/ArrayList.h
rename to llvm/lib/DWARFLinker/LLVM/ArrayList.h
index def83f91bc6f31..b9bb6f7c5fd2b2 100644
--- a/llvm/lib/DWARFLinkerParallel/ArrayList.h
+++ b/llvm/lib/DWARFLinker/LLVM/ArrayList.h
@@ -6,13 +6,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIB_DWARFLINKERPARALLEL_ARRAYLIST_H
-#define LLVM_LIB_DWARFLINKERPARALLEL_ARRAYLIST_H
+#ifndef LLVM_LIB_DWARFLINKER_LLVM_ARRAYLIST_H
+#define LLVM_LIB_DWARFLINKER_LLVM_ARRAYLIST_H
 
 #include "llvm/Support/PerThreadBumpPtrAllocator.h"
 #include <atomic>
 
 namespace llvm {
+namespace dwarflinker {
 namespace dwarflinker_parallel {
 
 /// This class is a simple list of T structures. It keeps elements as
@@ -160,6 +161,7 @@ template <typename T, size_t ItemsGroupSize = 512> class ArrayList {
 };
 
 } // end of namespace dwarflinker_parallel
+} // end of namespace dwarflinker
 } // end namespace llvm
 
-#endif // LLVM_LIB_DWARFLINKERPARALLEL_ARRAYLIST_H
+#endif // LLVM_LIB_DWARFLINKER_LLVM_ARRAYLIST_H
diff --git a/llvm/lib/DWARFLinkerParallel/CMakeLists.txt b/llvm/lib/DWARFLinker/LLVM/CMakeLists.txt
similarity index 94%
rename from llvm/lib/DWARFLinkerParallel/CMakeLists.txt
rename to llvm/lib/DWARFLinker/LLVM/CMakeLists.txt
index b0f0b3910e586a..5d38062975135f 100644
--- a/llvm/lib/DWARFLinkerParallel/CMakeLists.txt
+++ b/llvm/lib/DWARFLinker/LLVM/CMakeLists.txt
@@ -3,14 +3,12 @@ add_llvm_component_library(LLVMDWARFLinkerParallel
   DependencyTracker.cpp
   DIEAttributeCloner.cpp
   DWARFEmitterImpl.cpp
-  DWARFFile.cpp
   DWARFLinker.cpp
   DWARFLinkerCompileUnit.cpp
   DWARFLinkerTypeUnit.cpp
   DWARFLinkerImpl.cpp
   DWARFLinkerUnit.cpp
   OutputSections.cpp
-  StringPool.cpp
   SyntheticTypeNameBuilder.cpp
 
   ADDITIONAL_HEADER_DIRS
@@ -24,6 +22,7 @@ add_llvm_component_library(LLVMDWARFLinkerParallel
   BinaryFormat
   CodeGen
   DebugInfoDWARF
+  DWARFLinkerBase
   MC
   Object
   Support
diff --git a/llvm/lib/DWARFLinkerParallel/DIEAttributeCloner.cpp b/llvm/lib/DWARFLinker/LLVM/DIEAttributeCloner.cpp
similarity index 99%
rename from llvm/lib/DWARFLinkerParallel/DIEAttributeCloner.cpp
rename to llvm/lib/DWARFLinker/LLVM/DIEAttributeCloner.cpp
index 81fc57f7cabbb7..afec44e3e69211 100644
--- a/llvm/lib/DWARFLinkerParallel/DIEAttributeCloner.cpp
+++ b/llvm/lib/DWARFLinker/LLVM/DIEAttributeCloner.cpp
@@ -9,8 +9,9 @@
 #include "DIEAttributeCloner.h"
 #include "llvm/DebugInfo/DWARF/DWARFDebugMacro.h"
 
-namespace llvm {
-namespace dwarflinker_parallel {
+using namespace llvm;
+using namespace dwarflinker;
+using namespace dwarflinker_parallel;
 
 void DIEAttributeCloner::clone() {
   // Extract and clone every attribute.
@@ -650,6 +651,3 @@ unsigned DIEAttributeCloner::finalizeAbbreviations(bool HasChildrenToClone) {
 
   return AttrOutOffset;
 }
-
-} // end of namespace dwarflinker_parallel
-} // namespace llvm
diff --git a/llvm/lib/DWARFLinkerParallel/DIEAttributeCloner.h b/llvm/lib/DWARFLinker/LLVM/DIEAttributeCloner.h
similarity index 96%
rename from llvm/lib/DWARFLinkerParallel/DIEAttributeCloner.h
rename to llvm/lib/DWARFLinker/LLVM/DIEAttributeCloner.h
index e18c0a15cefc63..83e48e904205ab 100644
--- a/llvm/lib/DWARFLinkerParallel/DIEAttributeCloner.h
+++ b/llvm/lib/DWARFLinker/LLVM/DIEAttributeCloner.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIB_DWARFLINKERPARALLEL_DIEATTRIBUTECLONER_H
-#define LLVM_LIB_DWARFLINKERPARALLEL_DIEATTRIBUTECLONER_H
+#ifndef LLVM_LIB_DWARFLINKER_LLVM_DIEATTRIBUTECLONER_H
+#define LLVM_LIB_DWARFLINKER_LLVM_DIEATTRIBUTECLONER_H
 
 #include "ArrayList.h"
 #include "DIEGenerator.h"
@@ -16,6 +16,7 @@
 #include "DWARFLinkerTypeUnit.h"
 
 namespace llvm {
+namespace dwarflinker {
 namespace dwarflinker_parallel {
 
 /// Information gathered and exchanged between the various
@@ -179,6 +180,7 @@ class DIEAttributeCloner {
 };
 
 } // end of namespace dwarflinker_parallel
+} // end of namespace dwarflinker
 } // end namespace llvm
 
-#endif // LLVM_LIB_DWARFLINKERPARALLEL_DIEATTRIBUTECLONER_H
+#endif // LLVM_LIB_DWARFLINKER_LLVM_DIEATTRIBUTECLONER_H
diff --git a/llvm/lib/DWARFLinkerParallel/DIEGenerator.h b/llvm/lib/DWARFLinker/LLVM/DIEGenerator.h
similarity index 97%
rename from llvm/lib/DWARFLinkerParallel/DIEGenerator.h
rename to llvm/lib/DWARFLinker/LLVM/DIEGenerator.h
index 42bf00f55ff180..b38c032f2339fa 100644
--- a/llvm/lib/DWARFLinkerParallel/DIEGenerator.h
+++ b/llvm/lib/DWARFLinker/LLVM/DIEGenerator.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIB_DWARFLINKERPARALLEL_DIEGENERATOR_H
-#define LLVM_LIB_DWARFLINKERPARALLEL_DIEGENERATOR_H
+#ifndef LLVM_LIB_DWARFLINKER_LLVM_DIEGENERATOR_H
+#define LLVM_LIB_DWARFLINKER_LLVM_DIEGENERATOR_H
 
 #include "DWARFLinkerGlobalData.h"
 #include "DWARFLinkerUnit.h"
@@ -15,6 +15,7 @@
 #include "llvm/Support/LEB128.h"
 
 namespace llvm {
+namespace dwarflinker {
 namespace dwarflinker_parallel {
 
 /// This class is a helper to create output DIE tree.
@@ -175,6 +176,7 @@ class DIEGenerator {
 };
 
 } // end of namespace dwarflinker_parallel
+} // end of namespace dwarflinker
 } // end namespace llvm
 
-#endif // LLVM_LIB_DWARFLINKERPARALLEL_DIEGENERATOR_H
+#endif // LLVM_LIB_DWARFLINKER_LLVM_DIEGENERATOR_H
diff --git a/llvm/lib/DWARFLinkerParallel/DWARFEmitterImpl.cpp b/llvm/lib/DWARFLinker/LLVM/DWARFEmitterImpl.cpp
similarity index 98%
rename from llvm/lib/DWARFLinkerParallel/DWARFEmitterImpl.cpp
rename to llvm/lib/DWARFLinker/LLVM/DWARFEmitterImpl.cpp
index 355cfae3a64629..2beab7f4130547 100644
--- a/llvm/lib/DWARFLinkerParallel/DWARFEmitterImpl.cpp
+++ b/llvm/lib/DWARFLinker/LLVM/DWARFEmitterImpl.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "DWARFEmitterImpl.h"
-#include "llvm/DWARFLinker/DWARFLinkerCompileUnit.h"
+#include "DWARFLinkerCompileUnit.h"
 #include "llvm/MC/MCAsmBackend.h"
 #include "llvm/MC/MCCodeEmitter.h"
 #include "llvm/MC/MCObjectWriter.h"
@@ -17,8 +17,9 @@
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Support/FormattedStream.h"
 
-namespace llvm {
-namespace dwarflinker_parallel {
+using namespace llvm;
+using namespace dwarflinker;
+using namespace dwarflinker_parallel;
 
 Error DwarfEmitterImpl::init(Triple TheTriple,
                              StringRef Swift5ReflectionSegmentName) {
@@ -276,6 +277,3 @@ void DwarfEmitterImpl::emitAppleTypes(
   Asm->OutStreamer->emitLabel(SectionBegin);
   emitAppleAccelTable(Asm.get(), Table, "types", SectionBegin);
 }
-
-} // end of namespace dwarflinker_parallel
-} // namespace llvm
diff --git a/llvm/lib/DWARFLinkerParallel/DWARFEmitterImpl.h b/llvm/lib/DWARFLinker/LLVM/DWARFEmitterImpl.h
similarity index 95%
rename from llvm/lib/DWARFLinkerParallel/DWARFEmitterImpl.h
rename to llvm/lib/DWARFLinker/LLVM/DWARFEmitterImpl.h
index d03336c1c11a36..1d330d68663113 100644
--- a/llvm/lib/DWARFLinkerParallel/DWARFEmitterImpl.h
+++ b/llvm/lib/DWARFLinker/LLVM/DWARFEmitterImpl.h
@@ -6,14 +6,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIB_DWARFLINKERPARALLEL_DWARFEMITTERIMPL_H
-#define LLVM_LIB_DWARFLINKERPARALLEL_DWARFEMITTERIMPL_H
+#ifndef LLVM_LIB_DWARFLINKER_LLVM_DWARFEMITTERIMPL_H
+#define LLVM_LIB_DWARFLINKER_LLVM_DWARFEMITTERIMPL_H
 
 #include "DWARFLinkerCompileUnit.h"
 #include "llvm/BinaryFormat/Swift.h"
 #include "llvm/CodeGen/AccelTable.h"
 #include "llvm/CodeGen/AsmPrinter.h"
-#include "llvm/DWARFLinkerParallel/DWARFLinker.h"
+#include "llvm/DWARFLinker/LLVM/DWARFLinker.h"
 #include "llvm/MC/MCAsmInfo.h"
 #include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCInstrInfo.h"
@@ -36,6 +36,7 @@ namespace llvm {
 template <typename DataT> class AccelTable;
 class MCCodeEmitter;
 
+namespace dwarflinker {
 namespace dwarflinker_parallel {
 
 using DebugNamesUnitsOffsets = std::vector<std::variant<MCSymbol *, uint64_t>>;
@@ -140,6 +141,7 @@ class DwarfEmitterImpl : public ExtraDwarfEmitter {
 };
 
 } // end namespace dwarflinker_parallel
+} // end namespace dwarflinker
 } // end namespace llvm
 
-#endif // LLVM_LIB_DWARFLINKERPARALLEL_DWARFEMITTERIMPL_H
+#endif // LLVM_LIB_DWARFLINKER_LLVM_DWARFEMITTERIMPL_H
diff --git a/llvm/lib/DWARFLinkerParallel/DWARFLinker.cpp b/llvm/lib/DWARFLinker/LLVM/DWARFLinker.cpp
similarity index 65%
rename from llvm/lib/DWARFLinkerParallel/DWARFLinker.cpp
rename to llvm/lib/DWARFLinker/LLVM/DWARFLinker.cpp
index 269f24b1a13b9a..5959ec5939e7ed 100644
--- a/llvm/lib/DWARFLinkerParallel/DWARFLinker.cpp
+++ b/llvm/lib/DWARFLinker/LLVM/DWARFLinker.cpp
@@ -9,10 +9,14 @@
 #include "DWARFLinkerImpl.h"
 #include "DependencyTracker.h"
 
-std::unique_ptr<llvm::dwarflinker_parallel::DWARFLinker>
-llvm::dwarflinker_parallel::DWARFLinker::createLinker(
-    MessageHandlerTy ErrorHandler, MessageHandlerTy WarningHandler,
-    TranslatorFuncTy StringsTranslator) {
+using namespace llvm;
+using namespace dwarflinker;
+using namespace dwarflinker_parallel;
+
+std::unique_ptr<DWARFLinker>
+DWARFLinker::createLinker(MessageHandlerTy ErrorHandler,
+                          MessageHandlerTy WarningHandler,
+                          TranslatorFuncTy StringsTranslator) {
   return std::make_unique<DWARFLinkerImpl>(ErrorHandler, WarningHandler,
                                            StringsTranslator);
 }
diff --git a/llvm/lib/DWARFLinkerParallel/DWARFLinkerCompileUnit.cpp b/llvm/lib/DWARFLinker/LLVM/DWARFLinkerCompileUnit.cpp
similarity index 99%
rename from llvm/lib/DWARFLinkerParallel/DWARFLinkerCompileUnit.cpp
rename to llvm/lib/DWARFLinker/LLVM/DWARFLinkerCompileUnit.cpp
index 3f0e7569027274..97c7a5f821488a 100644
--- a/llvm/lib/DWARFLinkerParallel/DWARFLinkerCompileUnit.cpp
+++ b/llvm/lib/DWARFLinker/LLVM/DWARFLinkerCompileUnit.cpp
@@ -21,7 +21,8 @@
 #include <utility>
 
 using namespace llvm;
-using namespace llvm::dwarflinker_parallel;
+using namespace dwarflinker;
+using namespace dwarflinker_parallel;
 
 CompileUnit::CompileUnit(LinkingGlobalData &GlobalData, unsigned ID,
                          StringRef ClangModuleName, DWARFFile &File,
@@ -1870,7 +1871,7 @@ void CompileUnit::verifyDependencies() {
   Dependencies.get()->verifyKeepChain();
 }
 
-ArrayRef<dwarf::Attribute> llvm::dwarflinker_parallel::getODRAttributes() {
+ArrayRef<dwarf::Attribute> dwarflinker_parallel::getODRAttributes() {
   static dwarf::Attribute ODRAttributes[] = {
       dwarf::DW_AT_type, dwarf::DW_AT_specification,
       dwarf::DW_AT_abstract_origin, dwarf::DW_AT_import};
diff --git a/llvm/lib/DWARFLinkerParallel/DWARFLinkerCompileUnit.h b/llvm/lib/DWARFLinker/LLVM/DWARFLinkerCompileUnit.h
similarity index 98%
rename from llvm/lib/DWARFLinkerParallel/DWARFLinkerCompileUnit.h
rename to llvm/lib/DWARFLinker/LLVM/DWARFLinkerCompileUnit.h
index 28fcc34d867dbd..d6fba36da0502d 100644
--- a/llvm/lib/DWARFLinkerParallel/DWARFLinkerCompileUnit.h
+++ b/llvm/lib/DWARFLinker/LLVM/DWARFLinkerCompileUnit.h
@@ -6,14 +6,15 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERCOMPILEUNIT_H
-#define LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERCOMPILEUNIT_H
+#ifndef LLVM_LIB_DWARFLINKER_LLVM_DWARFLINKERCOMPILEUNIT_H
+#define LLVM_LIB_DWARFLINKER_LLVM_DWARFLINKERCOMPILEUNIT_H
 
 #include "DWARFLinkerUnit.h"
-#include "llvm/DWARFLinkerParallel/DWARFFile.h"
+#include "llvm/DWARFLinker/DWARFFile.h"
 #include <optional>
 
 namespace llvm {
+namespace dwarflinker {
 namespace dwarflinker_parallel {
 
 using OffsetToUnitTy = function_ref<CompileUnit *(uint64_t Offset)>;
@@ -731,6 +732,7 @@ class alignas(8) CompileUnit : public DwarfUnit {
 ArrayRef<dwarf::Attribute> getODRAttributes();
 
 } // end of namespace dwarflinker_parallel
+} // end of namespace dwarflinker
 } // end namespace llvm
 
-#endif // LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERCOMPILEUNIT_H
+#endif // LLVM_LIB_DWARFLINKER_LLVM_DWARFLINKERCOMPILEUNIT_H
diff --git a/llvm/lib/DWARFLinkerParallel/DWARFLinkerGlobalData.h b/llvm/lib/DWARFLinker/LLVM/DWARFLinkerGlobalData.h
similarity index 94%
rename from llvm/lib/DWARFLinkerParallel/DWARFLinkerGlobalData.h
rename to llvm/lib/DWARFLinker/LLVM/DWARFLinkerGlobalData.h
index 31724770093d64..656e49af1a19a7 100644
--- a/llvm/lib/DWARFLinkerParallel/DWARFLinkerGlobalData.h
+++ b/llvm/lib/DWARFLinker/LLVM/DWARFLinkerGlobalData.h
@@ -6,18 +6,19 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERGLOBALDATA_H
-#define LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERGLOBALDATA_H
+#ifndef LLVM_LIB_DWARFLINKER_LLVM_DWARFLINKERGLOBALDATA_H
+#define LLVM_LIB_DWARFLINKER_LLVM_DWARFLINKERGLOBALDATA_H
 
 #include "TypePool.h"
-#include "llvm/DWARFLinkerParallel/DWARFLinker.h"
-#include "llvm/DWARFLinkerParallel/StringPool.h"
+#include "llvm/DWARFLinker/LLVM/DWARFLinker.h"
+#include "llvm/DWARFLinker/StringPool.h"
 #include "llvm/Support/PerThreadBumpPtrAllocator.h"
 
 namespace llvm {
 
 class DWARFDie;
 
+namespace dwarflinker {
 namespace dwarflinker_parallel {
 
 using TranslatorFuncTy = std::function<StringRef(StringRef)>;
@@ -154,6 +155,7 @@ class LinkingGlobalData {
 };
 
 } // end of namespace dwarflinker_parallel
+} // end of namespace dwarflinker
 } // end namespace llvm
 
 #endif // LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERGLOBALDATA_H
diff --git a/llvm/lib/DWARFLinkerParallel/DWARFLinkerImpl.cpp b/llvm/lib/DWARFLinker/LLVM/DWARFLinkerImpl.cpp
similarity index 92%
rename from llvm/lib/DWARFLinkerParallel/DWARFLinkerImpl.cpp
rename to llvm/lib/DWARFLinker/LLVM/DWARFLinkerImpl.cpp
index c49b9ef0cdf989..9d0d5d2602fcfd 100644
--- a/llvm/lib/DWARFLinkerParallel/DWARFLinkerImpl.cpp
+++ b/llvm/lib/DWARFLinker/LLVM/DWARFLinkerImpl.cpp
@@ -15,8 +15,9 @@
 #include "llvm/Support/Parallel.h"
 #include "llvm/Support/ThreadPool.h"
 
-namespace llvm {
-namespace dwarflinker_parallel {
+using namespace llvm;
+using namespace dwarflinker;
+using namespace dwarflinker_parallel;
 
 DWARFLinkerImpl::DWARFLinkerImpl(MessageHandlerTy ErrorHandler,
                                  MessageHandlerTy WarningHandler,
@@ -486,108 +487,104 @@ Error DWARFLinkerImpl::LinkContext::link(TypeUnit *ArtificialTypeUnit) {
     return Error::success();
   }
 
-    OriginalDebugInfoSize = getInputDebugInfoSize();
-
-    // Create CompileUnit structures to keep information about source
-    // DWARFUnit`s, load line tables.
-    for (const auto &OrigCU : InputDWARFFile.Dwarf->compile_units()) {
-      // Load only unit DIE at this stage.
-      auto CUDie = OrigCU->getUnitDIE();
-      std::string PCMFile =
-          getPCMFile(CUDie, GlobalData.getOptions().ObjectPrefixMap);
-
-      // The !isClangModuleRef condition effectively skips over fully resolved
-      // skeleton units.
-      if (!CUDie || GlobalData.getOptions().UpdateIndexTablesOnly ||
-          !isClangModuleRef(CUDie, PCMFile, 0, true).first) {
-        CompileUnits.emplace_back(std::make_unique<CompileUnit>(
-            GlobalData, *OrigCU, UniqueUnitID.fetch_add(1), "", InputDWARFFile,
-            getUnitForOffset, OrigCU->getFormParams(), getEndianness()));
-
-        // Preload line table, as it can't be loaded asynchronously.
-        CompileUnits.back()->loadLineTable();
-      }
-    };
+  OriginalDebugInfoSize = getInputDebugInfoSize();
+
+  // Create CompileUnit structures to keep information about source
+  // DWARFUnit`s, load line tables.
+  for (const auto &OrigCU : InputDWARFFile.Dwarf->compile_units()) {
+    // Load only unit DIE at this stage.
+    auto CUDie = OrigCU->getUnitDIE();
+    std::string PCMFile =
+        getPCMFile(CUDie, GlobalData.getOptions().ObjectPrefixMap);
+
+    // The !isClangModuleRef condition effectively skips over fully resolved
+    // skeleton units.
+    if (!CUDie || GlobalData.getOptions().UpdateIndexTablesOnly ||
+        !isClangModuleRef(CUDie, PCMFile, 0, true).first) {
+      CompileUnits.emplace_back(std::make_unique<CompileUnit>(
+          GlobalData, *OrigCU, UniqueUnitID.fetch_add(1), "", InputDWARFFile,
+          getUnitForOffset, OrigCU->getFormParams(), getEndianness()));
+
+      // Preload line table, as it can't be loaded asynchronously.
+      CompileUnits.back()->loadLineTable();
+    }
+  };
 
-    HasNewInterconnectedCUs = false;
+  HasNewInterconnectedCUs = false;
 
-    // Link self-sufficient compile units and discover inter-connected compile
-    // units.
-    parallelForEach(CompileUnits, [&](std::unique_ptr<CompileUnit> &CU) {
-      linkSingleCompileUnit(*CU, ArtificialTypeUnit);
-    });
+  // Link self-sufficient compile units and discover inter-connected compile
+  // units.
+  parallelForEach(CompileUnits, [&](std::unique_ptr<CompileUnit> &CU) {
+    linkSingleCompileUnit(*CU, ArtificialTypeUnit);
+  });
+
+  // Link all inter-connected units.
+  if (HasNewInterconnectedCUs) {
+    InterCUProcessingStarted = true;
 
-    // Link all inter-connected units.
-    if (HasNewInterconnectedCUs) {
-      InterCUProcessingStarted = true;
-
-      if (Error Err = finiteLoop([&]() -> Expected<bool> {
-            HasNewInterconnectedCUs = false;
-
-            // Load inter-connected units.
-            parallelForEach(
-                CompileUnits, [&](std::unique_ptr<CompileUnit> &CU) {
-                  if (CU->isInterconnectedCU()) {
-                    CU->maybeResetToLoadedStage();
-                    linkSingleCompileUnit(*CU, ArtificialTypeUnit,
-                                          CompileUnit::Stage::Loaded);
-                  }
-                });
-
-            // Do liveness analysis for inter-connected units.
-            parallelForEach(CompileUnits,
-                            [&](std::unique_ptr<CompileUnit> &CU) {
-                              linkSingleCompileUnit(
-                                  *CU, ArtificialTypeUnit,
+    if (Error Err = finiteLoop([&]() -> Expected<bool> {
+          HasNewInterconnectedCUs = false;
+
+          // Load inter-connected units.
+          parallelForEach(CompileUnits, [&](std::unique_ptr<CompileUnit> &CU) {
+            if (CU->isInterconnectedCU()) {
+              CU->maybeResetToLoadedStage();
+              linkSingleCompileUnit(*CU, ArtificialTypeUnit,
+                                    CompileUnit::Stage::Loaded);
+            }
+          });
+
+          // Do liveness analysis for inter-connected units.
+          parallelForEach(CompileUnits, [&](std::unique_ptr<CompileUnit> &CU) {
+            linkSingleCompileUnit(*CU, ArtificialTypeUnit,
                                   CompileUnit::Stage::LivenessAnalysisDone);
-                            });
-
-            return HasNewInterconnectedCUs.load();
-          }))
-        return Err;
-
-      // Update dependencies.
-      if (Error Err = finiteLoop([&]() -> Expected<bool> {
-            HasNewGlobalDependency = false;
-            parallelForEach(
-                CompileUnits, [&](std::unique_ptr<CompileUnit> &CU) {
-                  linkSingleCompileUnit(
-                      *CU, ArtificialTypeUnit,
-                      CompileUnit::Stage::UpdateDependenciesCompleteness);
-                });
-            return HasNewGlobalDependency.load();
-          }))
-        return Err;
-      parallelForEach(CompileUnits, [&](std::unique_ptr<CompileUnit> &CU) {
-        if (CU->isInterconnectedCU() &&
-            CU->getStage() == CompileUnit::Stage::LivenessAnalysisDone)
-          CU->setStage(CompileUnit::Stage::UpdateDependenciesCompleteness);
-      });
+          });
 
-      // Assign type names.
-      parallelForEach(CompileUnits, [&](std::unique_ptr<CompileUnit> &CU) {
-        linkSingleCompileUnit(*CU, ArtificialTypeUnit,
-                              CompileUnit::Stage::TypeNamesAssigned);
-      });
+          return HasNewInterconnectedCUs.load();
+        }))
+      return Err;
 
-      // Clone inter-connected units.
-      parallelForEach(CompileUnits, [&](std::unique_ptr<CompileUnit> &CU) {
-        linkSingleCompileUnit(*CU, ArtificialTypeUnit,
-                              CompileUnit::Stage::Cloned);
-      });
+    // Update dependencies.
+    if (Error Err = finiteLoop([&]() -> Expected<bool> {
+          HasNewGlobalDependency = false;
+          parallelForEach(CompileUnits, [&](std::unique_ptr<CompileUnit> &CU) {
+            linkSingleCompileUnit(
+                *CU, ArtificialTypeUnit,
+                CompileUnit::Stage::UpdateDependenciesCompleteness);
+          });
+          return HasNewGlobalDependency.load();
+        }))
+      return Err;
+    parallelForEach(CompileUnits, [&](std::unique_ptr<CompileUnit> &CU) {
+      if (CU->isInterconnectedCU() &&
+          CU->getStage() == CompileUnit::Stage::LivenessAnalysisDone)
+        CU->setStage(CompileUnit::Stage::UpdateDependenciesCompleteness);
+    });
 
-      // Update patches for inter-connected units.
-      parallelForEach(CompileUnits, [&](std::unique_ptr<CompileUnit> &CU) {
-        linkSingleCompileUnit(*CU, ArtificialTypeUnit,
-                              CompileUnit::Stage::PatchesUpdated);
-      });
+    // Assign type names.
+    parallelForEach(CompileUnits, [&](std::unique_ptr<CompileUnit> &CU) {
+      linkSingleCompileUnit(*CU, ArtificialTypeUnit,
+                            CompileUnit::Stage::TypeNamesAssigned);
+    });
 
-      // Release data.
-      parallelForEach(CompileUnits, [&](std::unique_ptr<CompileUnit> &CU) {
-        linkSingleCompileUnit(*CU, ArtificialTypeUnit,
-                              CompileUnit::Stage::Cleaned);
-      });
-    }
+    // Clone inter-connected units.
+    parallelForEach(CompileUnits, [&](std::unique_ptr<CompileUnit> &CU) {
+      linkSingleCompileUnit(*CU, ArtificialTypeUnit,
+                            CompileUnit::Stage::Cloned);
+    });
+
+    // Update patches for inter-connected units.
+    parallelForEach(CompileUnits, [&](std::unique_ptr<CompileUnit> &CU) {
+      linkSingleCompileUnit(*CU, ArtificialTypeUnit,
+                            CompileUnit::Stage::PatchesUpdated);
+    });
+
+    // Release data.
+    parallelForEach(CompileUnits, [&](std::unique_ptr<CompileUnit> &CU) {
+      linkSingleCompileUnit(*CU, ArtificialTypeUnit,
+                            CompileUnit::Stage::Cleaned);
+    });
+  }
 
   if (GlobalData.getOptions().UpdateIndexTablesOnly) {
     // Emit Invariant sections.
@@ -1451,6 +1448,3 @@ void DWARFLinkerImpl::writeCommonSectionsToTheOutput() {
     OutSection.clearSectionContent();
   });
 }
-
-} // end of namespace dwarflinker_parallel
-} // namespace llvm
diff --git a/llvm/lib/DWARFLinkerParallel/DWARFLinkerImpl.h b/llvm/lib/DWARFLinker/LLVM/DWARFLinkerImpl.h
similarity index 97%
rename from llvm/lib/DWARFLinkerParallel/DWARFLinkerImpl.h
rename to llvm/lib/DWARFLinker/LLVM/DWARFLinkerImpl.h
index 60018eea121f20..b13d2a07f98050 100644
--- a/llvm/lib/DWARFLinkerParallel/DWARFLinkerImpl.h
+++ b/llvm/lib/DWARFLinker/LLVM/DWARFLinkerImpl.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERIMPL_H
-#define LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERIMPL_H
+#ifndef LLVM_LIB_DWARFLINKER_LLVM_DWARFLINKERIMPL_H
+#define LLVM_LIB_DWARFLINKER_LLVM_DWARFLINKERIMPL_H
 
 #include "DWARFEmitterImpl.h"
 #include "DWARFLinkerCompileUnit.h"
@@ -15,10 +15,11 @@
 #include "StringEntryToDwarfStringPoolEntryMap.h"
 #include "llvm/ADT/AddressRanges.h"
 #include "llvm/CodeGen/AccelTable.h"
-#include "llvm/DWARFLinkerParallel/DWARFLinker.h"
-#include "llvm/DWARFLinkerParallel/StringPool.h"
+#include "llvm/DWARFLinker/LLVM/DWARFLinker.h"
+#include "llvm/DWARFLinker/StringPool.h"
 
 namespace llvm {
+namespace dwarflinker {
 namespace dwarflinker_parallel {
 
 /// This class links debug info.
@@ -375,6 +376,7 @@ class DWARFLinkerImpl : public DWARFLinker {
 };
 
 } // end namespace dwarflinker_parallel
+} // end namespace dwarflinker
 } // end namespace llvm
 
-#endif // LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERIMPL_H
+#endif // LLVM_LIB_DWARFLINKER_LLVM_DWARFLINKERIMPL_H
diff --git a/llvm/lib/DWARFLinkerParallel/DWARFLinkerTypeUnit.cpp b/llvm/lib/DWARFLinker/LLVM/DWARFLinkerTypeUnit.cpp
similarity index 99%
rename from llvm/lib/DWARFLinkerParallel/DWARFLinkerTypeUnit.cpp
rename to llvm/lib/DWARFLinker/LLVM/DWARFLinkerTypeUnit.cpp
index 9d5c213085c293..ff0ed76fa22d1c 100644
--- a/llvm/lib/DWARFLinkerParallel/DWARFLinkerTypeUnit.cpp
+++ b/llvm/lib/DWARFLinker/LLVM/DWARFLinkerTypeUnit.cpp
@@ -12,7 +12,8 @@
 #include "llvm/Support/LEB128.h"
 
 using namespace llvm;
-using namespace llvm::dwarflinker_parallel;
+using namespace dwarflinker;
+using namespace dwarflinker_parallel;
 
 TypeUnit::TypeUnit(LinkingGlobalData &GlobalData, unsigned ID,
                    std::optional<uint16_t> Language, dwarf::FormParams Format,
diff --git a/llvm/lib/DWARFLinkerParallel/DWARFLinkerTypeUnit.h b/llvm/lib/DWARFLinker/LLVM/DWARFLinkerTypeUnit.h
similarity index 95%
rename from llvm/lib/DWARFLinkerParallel/DWARFLinkerTypeUnit.h
rename to llvm/lib/DWARFLinker/LLVM/DWARFLinkerTypeUnit.h
index 97e620eee0c424..671a7328adeb19 100644
--- a/llvm/lib/DWARFLinkerParallel/DWARFLinkerTypeUnit.h
+++ b/llvm/lib/DWARFLinker/LLVM/DWARFLinkerTypeUnit.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_DWARFLINKERPARALLEL_DWARFLINKERTYPEUNIT_H
-#define LLVM_DWARFLINKERPARALLEL_DWARFLINKERTYPEUNIT_H
+#ifndef LLVM_DWARFLINKER_LLVM_DWARFLINKERTYPEUNIT_H
+#define LLVM_DWARFLINKER_LLVM_DWARFLINKERTYPEUNIT_H
 
 #include "DWARFLinkerUnit.h"
 #include "llvm/CodeGen/DIE.h"
@@ -15,6 +15,7 @@
 #include "llvm/DebugInfo/DWARF/DWARFUnit.h"
 
 namespace llvm {
+namespace dwarflinker {
 namespace dwarflinker_parallel {
 
 /// Type Unit is used to represent an artificial compilation unit
@@ -133,6 +134,7 @@ class TypeUnit : public DwarfUnit {
 };
 
 } // end of namespace dwarflinker_parallel
+} // end of namespace dwarflinker
 } // end namespace llvm
 
-#endif // LLVM_DWARFLINKERPARALLEL_DWARFLINKERTYPEUNIT_H
+#endif // LLVM_DWARFLINKER_LLVM_DWARFLINKERTYPEUNIT_H
diff --git a/llvm/lib/DWARFLinkerParallel/DWARFLinkerUnit.cpp b/llvm/lib/DWARFLinker/LLVM/DWARFLinkerUnit.cpp
similarity index 89%
rename from llvm/lib/DWARFLinkerParallel/DWARFLinkerUnit.cpp
rename to llvm/lib/DWARFLinker/LLVM/DWARFLinkerUnit.cpp
index b1da1900d65ef7..800b549c9a7fbe 100644
--- a/llvm/lib/DWARFLinkerParallel/DWARFLinkerUnit.cpp
+++ b/llvm/lib/DWARFLinker/LLVM/DWARFLinkerUnit.cpp
@@ -10,10 +10,11 @@
 #include "DWARFEmitterImpl.h"
 #include "DebugLineSectionEmitter.h"
 
-namespace llvm {
-namespace dwarflinker_parallel {
+using namespace llvm;
+using namespace dwarflinker;
+using namespace dwarflinker_parallel;
 
-void DwarfUnit::assignAbbrev(DIEAbbrev &Abbrev) {
+void dwarflinker_parallel::DwarfUnit::assignAbbrev(DIEAbbrev &Abbrev) {
   // Check the set for priors.
   FoldingSetNodeID ID;
   Abbrev.Profile(ID);
@@ -37,7 +38,7 @@ void DwarfUnit::assignAbbrev(DIEAbbrev &Abbrev) {
   }
 }
 
-Error DwarfUnit::emitAbbreviations() {
+Error dwarflinker_parallel::DwarfUnit::emitAbbreviations() {
   const std::vector<std::unique_ptr<DIEAbbrev>> &Abbrevs = getAbbreviations();
   if (Abbrevs.empty())
     return Error::success();
@@ -55,8 +56,8 @@ Error DwarfUnit::emitAbbreviations() {
   return Error::success();
 }
 
-void DwarfUnit::emitDwarfAbbrevEntry(const DIEAbbrev &Abbrev,
-                                     SectionDescriptor &AbbrevSection) {
+void dwarflinker_parallel::DwarfUnit::emitDwarfAbbrevEntry(
+    const DIEAbbrev &Abbrev, SectionDescriptor &AbbrevSection) {
   // Emit the abbreviations code (base 1 index.)
   encodeULEB128(Abbrev.getNumber(), AbbrevSection.OS);
 
@@ -88,7 +89,8 @@ void DwarfUnit::emitDwarfAbbrevEntry(const DIEAbbrev &Abbrev,
   encodeULEB128(0, AbbrevSection.OS);
 }
 
-Error DwarfUnit::emitDebugInfo(const Triple &TargetTriple) {
+Error dwarflinker_parallel::DwarfUnit::emitDebugInfo(
+    const Triple &TargetTriple) {
   DIE *OutUnitDIE = getOutUnitDIE();
   if (OutUnitDIE == nullptr)
     return Error::success();
@@ -119,14 +121,14 @@ Error DwarfUnit::emitDebugInfo(const Triple &TargetTriple) {
   return Error::success();
 }
 
-Error DwarfUnit::emitDebugLine(const Triple &TargetTriple,
-                               const DWARFDebugLine::LineTable &OutLineTable) {
+Error dwarflinker_parallel::DwarfUnit::emitDebugLine(
+    const Triple &TargetTriple, const DWARFDebugLine::LineTable &OutLineTable) {
   DebugLineSectionEmitter DebugLineEmitter(TargetTriple, *this);
 
   return DebugLineEmitter.emit(OutLineTable);
 }
 
-Error DwarfUnit::emitDebugStringOffsetSection() {
+Error dwarflinker_parallel::DwarfUnit::emitDebugStringOffsetSection() {
   if (getVersion() < 5)
     return Error::success();
 
@@ -171,9 +173,9 @@ Error DwarfUnit::emitDebugStringOffsetSection() {
 /// Emit the pubnames or pubtypes section contribution for \p
 /// Unit into \p Sec. The data is provided in \p Info.
 std::optional<uint64_t>
-DwarfUnit::emitPubAcceleratorEntry(SectionDescriptor &OutSection,
-                                   const DwarfUnit::AccelInfo &Info,
-                                   std::optional<uint64_t> LengthOffset) {
+dwarflinker_parallel::DwarfUnit::emitPubAcceleratorEntry(
+    SectionDescriptor &OutSection, const DwarfUnit::AccelInfo &Info,
+    std::optional<uint64_t> LengthOffset) {
   if (!LengthOffset) {
     // Emit the header.
     OutSection.emitIntVal(0xBADDEF,
@@ -198,7 +200,7 @@ DwarfUnit::emitPubAcceleratorEntry(SectionDescriptor &OutSection,
 }
 
 /// Emit .debug_pubnames and .debug_pubtypes for \p Unit.
-void DwarfUnit::emitPubAccelerators() {
+void dwarflinker_parallel::DwarfUnit::emitPubAccelerators() {
   std::optional<uint64_t> NamesLengthOffset;
   std::optional<uint64_t> TypesLengthOffset;
 
@@ -245,6 +247,3 @@ void DwarfUnit::emitPubAccelerators() {
                      OutSection.OS.tell() - *TypesLengthOffset);
   }
 }
-
-} // end of namespace dwarflinker_parallel
-} // end of namespace llvm
diff --git a/llvm/lib/DWARFLinkerParallel/DWARFLinkerUnit.h b/llvm/lib/DWARFLinker/LLVM/DWARFLinkerUnit.h
similarity index 95%
rename from llvm/lib/DWARFLinkerParallel/DWARFLinkerUnit.h
rename to llvm/lib/DWARFLinker/LLVM/DWARFLinkerUnit.h
index 9640a8ee711eb0..d56b1702bc2f54 100644
--- a/llvm/lib/DWARFLinkerParallel/DWARFLinkerUnit.h
+++ b/llvm/lib/DWARFLinker/LLVM/DWARFLinkerUnit.h
@@ -6,19 +6,20 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERUNIT_H
-#define LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERUNIT_H
+#ifndef LLVM_LIB_DWARFLINKER_LLVM_DWARFLINKERUNIT_H
+#define LLVM_LIB_DWARFLINKER_LLVM_DWARFLINKERUNIT_H
 
 #include "DWARFLinkerGlobalData.h"
 #include "IndexedValuesMap.h"
 #include "OutputSections.h"
 #include "llvm/CodeGen/DIE.h"
-#include "llvm/DWARFLinkerParallel/DWARFLinker.h"
-#include "llvm/DWARFLinkerParallel/StringPool.h"
+#include "llvm/DWARFLinker/LLVM/DWARFLinker.h"
+#include "llvm/DWARFLinker/StringPool.h"
 #include "llvm/DebugInfo/DWARF/DWARFUnit.h"
 #include "llvm/Support/LEB128.h"
 
 namespace llvm {
+namespace dwarflinker {
 namespace dwarflinker_parallel {
 
 class DwarfUnit;
@@ -216,6 +217,7 @@ inline bool isODRLanguage(uint16_t Language) {
 }
 
 } // end of namespace dwarflinker_parallel
+} // end of namespace dwarflinker
 } // end namespace llvm
 
-#endif // LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERUNIT_H
+#endif // LLVM_LIB_DWARFLINKER_LLVM_DWARFLINKERUNIT_H
diff --git a/llvm/lib/DWARFLinkerParallel/DebugLineSectionEmitter.h b/llvm/lib/DWARFLinker/LLVM/DebugLineSectionEmitter.h
similarity index 97%
rename from llvm/lib/DWARFLinkerParallel/DebugLineSectionEmitter.h
rename to llvm/lib/DWARFLinker/LLVM/DebugLineSectionEmitter.h
index fc7f8cbc4a8e7b..213d7a555a1484 100644
--- a/llvm/lib/DWARFLinkerParallel/DebugLineSectionEmitter.h
+++ b/llvm/lib/DWARFLinker/LLVM/DebugLineSectionEmitter.h
@@ -6,17 +6,18 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIB_DWARFLINKERPARALLEL_DEBUGLINESECTIONEMITTER_H
-#define LLVM_LIB_DWARFLINKERPARALLEL_DEBUGLINESECTIONEMITTER_H
+#ifndef LLVM_LIB_DWARFLINKER_LLVM_DEBUGLINESECTIONEMITTER_H
+#define LLVM_LIB_DWARFLINKER_LLVM_DEBUGLINESECTIONEMITTER_H
 
 #include "DWARFEmitterImpl.h"
-#include "llvm/DWARFLinkerParallel/AddressesMap.h"
-#include "llvm/DWARFLinkerParallel/DWARFLinker.h"
+#include "llvm/DWARFLinker/AddressesMap.h"
+#include "llvm/DWARFLinker/LLVM/DWARFLinker.h"
 #include "llvm/DebugInfo/DWARF/DWARFObject.h"
 #include "llvm/MC/MCTargetOptionsCommandFlags.h"
 #include "llvm/MC/TargetRegistry.h"
 
 namespace llvm {
+namespace dwarflinker {
 namespace dwarflinker_parallel {
 
 /// This class emits specified line table into the .debug_line section.
@@ -379,6 +380,7 @@ class DebugLineSectionEmitter {
 };
 
 } // end of namespace dwarflinker_parallel
+} // end of namespace dwarflinker
 } // end namespace llvm
 
-#endif // LLVM_LIB_DWARFLINKERPARALLEL_DEBUGLINESECTIONEMITTER_H
+#endif // LLVM_LIB_DWARFLINKER_LLVM_DEBUGLINESECTIONEMITTER_H
diff --git a/llvm/lib/DWARFLinkerParallel/DependencyTracker.cpp b/llvm/lib/DWARFLinker/LLVM/DependencyTracker.cpp
similarity index 99%
rename from llvm/lib/DWARFLinkerParallel/DependencyTracker.cpp
rename to llvm/lib/DWARFLinker/LLVM/DependencyTracker.cpp
index 052eb6cf57d41e..f5f44978dc83d9 100644
--- a/llvm/lib/DWARFLinkerParallel/DependencyTracker.cpp
+++ b/llvm/lib/DWARFLinker/LLVM/DependencyTracker.cpp
@@ -9,8 +9,9 @@
 #include "DependencyTracker.h"
 #include "llvm/Support/FormatVariadic.h"
 
-namespace llvm {
-namespace dwarflinker_parallel {
+using namespace llvm;
+using namespace dwarflinker;
+using namespace dwarflinker_parallel;
 
 /// A broken link in the keep chain. By recording both the parent and the child
 /// we can show only broken links for DIEs with multiple children.
@@ -834,6 +835,3 @@ bool DependencyTracker::isLiveSubprogramEntry(const UnitEntryPairTy &Entry) {
   Entry.CU->addFunctionRange(*LowPc, *HighPc, *RelocAdjustment);
   return true;
 }
-
-} // end of namespace dwarflinker_parallel
-} // namespace llvm
diff --git a/llvm/lib/DWARFLinkerParallel/DependencyTracker.h b/llvm/lib/DWARFLinker/LLVM/DependencyTracker.h
similarity index 97%
rename from llvm/lib/DWARFLinkerParallel/DependencyTracker.h
rename to llvm/lib/DWARFLinker/LLVM/DependencyTracker.h
index b0b6ad3a1e8cfa..84247b6ba90167 100644
--- a/llvm/lib/DWARFLinkerParallel/DependencyTracker.h
+++ b/llvm/lib/DWARFLinker/LLVM/DependencyTracker.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIB_DWARFLINKERPARALLEL_DEPENDENCYTRACKER_H
-#define LLVM_LIB_DWARFLINKERPARALLEL_DEPENDENCYTRACKER_H
+#ifndef LLVM_LIB_DWARFLINKER_LLVM_DEPENDENCYTRACKER_H
+#define LLVM_LIB_DWARFLINKER_LLVM_DEPENDENCYTRACKER_H
 
 #include "DWARFLinkerCompileUnit.h"
 #include "llvm/ADT/PointerIntPair.h"
@@ -17,6 +17,7 @@ namespace llvm {
 class DWARFDebugInfoEntry;
 class DWARFDie;
 
+namespace dwarflinker {
 namespace dwarflinker_parallel {
 
 /// This class discovers DIEs dependencies: marks "live" DIEs, marks DIE
@@ -267,6 +268,7 @@ class DependencyTracker {
 };
 
 } // end namespace dwarflinker_parallel
+} // end namespace dwarflinker
 } // end namespace llvm
 
-#endif // LLVM_LIB_DWARFLINKERPARALLEL_DEPENDENCYTRACKER_H
+#endif // LLVM_LIB_DWARFLINKER_LLVM_DEPENDENCYTRACKER_H
diff --git a/llvm/lib/DWARFLinkerParallel/IndexedValuesMap.h b/llvm/lib/DWARFLinker/LLVM/IndexedValuesMap.h
similarity index 85%
rename from llvm/lib/DWARFLinkerParallel/IndexedValuesMap.h
rename to llvm/lib/DWARFLinker/LLVM/IndexedValuesMap.h
index 0dc8de860a42e8..581d04226411c3 100644
--- a/llvm/lib/DWARFLinkerParallel/IndexedValuesMap.h
+++ b/llvm/lib/DWARFLinker/LLVM/IndexedValuesMap.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIB_DWARFLINKERPARALLEL_INDEXEDVALUESMAP_H
-#define LLVM_LIB_DWARFLINKERPARALLEL_INDEXEDVALUESMAP_H
+#ifndef LLVM_LIB_DWARFLINKER_LLVM_INDEXEDVALUESMAP_H
+#define LLVM_LIB_DWARFLINKER_LLVM_INDEXEDVALUESMAP_H
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallVector.h"
@@ -15,6 +15,7 @@
 #include <utility>
 
 namespace llvm {
+namespace dwarflinker {
 namespace dwarflinker_parallel {
 
 template <typename T> class IndexedValuesMap {
@@ -44,6 +45,7 @@ template <typename T> class IndexedValuesMap {
 };
 
 } // end of namespace dwarflinker_parallel
+} // end of namespace dwarflinker
 } // end namespace llvm
 
-#endif // LLVM_LIB_DWARFLINKERPARALLEL_INDEXEDVALUESMAP_H
+#endif // LLVM_LIB_DWARFLINKER_LLVM_INDEXEDVALUESMAP_H
diff --git a/llvm/lib/DWARFLinkerParallel/OutputSections.cpp b/llvm/lib/DWARFLinker/LLVM/OutputSections.cpp
similarity index 95%
rename from llvm/lib/DWARFLinkerParallel/OutputSections.cpp
rename to llvm/lib/DWARFLinker/LLVM/OutputSections.cpp
index 9c3e3ebd220aaf..7caf3e4ab37ba3 100644
--- a/llvm/lib/DWARFLinkerParallel/OutputSections.cpp
+++ b/llvm/lib/DWARFLinker/LLVM/OutputSections.cpp
@@ -11,22 +11,12 @@
 #include "DWARFLinkerTypeUnit.h"
 #include "llvm/ADT/StringSwitch.h"
 
-namespace llvm {
-namespace dwarflinker_parallel {
-
-static constexpr StringLiteral SectionNames[SectionKindsNum] = {
-    "debug_info",     "debug_line",     "debug_frame",       "debug_ranges",
-    "debug_rnglists", "debug_loc",      "debug_loclists",    "debug_aranges",
-    "debug_abbrev",   "debug_macinfo",  "debug_macro",       "debug_addr",
-    "debug_str",      "debug_line_str", "debug_str_offsets", "debug_pubnames",
-    "debug_pubtypes", "debug_names",    "apple_names",       "apple_namespac",
-    "apple_objc",     "apple_types"};
-
-const StringLiteral &getSectionName(DebugSectionKind SectionKind) {
-  return SectionNames[static_cast<uint8_t>(SectionKind)];
-}
+using namespace llvm;
+using namespace dwarflinker;
+using namespace dwarflinker_parallel;
 
-std::optional<DebugSectionKind> parseDebugTableName(llvm::StringRef SecName) {
+std::optional<DebugSectionKind>
+dwarflinker_parallel::parseDebugTableName(llvm::StringRef SecName) {
   return llvm::StringSwitch<std::optional<DebugSectionKind>>(
              SecName.substr(SecName.find_first_not_of("._")))
       .Case(getSectionName(DebugSectionKind::DebugInfo),
@@ -527,6 +517,3 @@ void OutputSections::applyPatches(
     Section.apply(Patch.PatchOffset, dwarf::DW_FORM_sec_offset, FinalValue);
   });
 }
-
-} // end of namespace dwarflinker_parallel
-} // end of namespace llvm
diff --git a/llvm/lib/DWARFLinkerParallel/OutputSections.h b/llvm/lib/DWARFLinker/LLVM/OutputSections.h
similarity index 95%
rename from llvm/lib/DWARFLinkerParallel/OutputSections.h
rename to llvm/lib/DWARFLinker/LLVM/OutputSections.h
index f23b2efb869da8..715b36920aa0a0 100644
--- a/llvm/lib/DWARFLinkerParallel/OutputSections.h
+++ b/llvm/lib/DWARFLinker/LLVM/OutputSections.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIB_DWARFLINKERPARALLEL_OUTPUTSECTIONS_H
-#define LLVM_LIB_DWARFLINKERPARALLEL_OUTPUTSECTIONS_H
+#ifndef LLVM_LIB_DWARFLINKER_LLVM_OUTPUTSECTIONS_H
+#define LLVM_LIB_DWARFLINKER_LLVM_OUTPUTSECTIONS_H
 
 #include "ArrayList.h"
 #include "StringEntryToDwarfStringPoolEntryMap.h"
@@ -15,7 +15,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/BinaryFormat/Dwarf.h"
 #include "llvm/CodeGen/DwarfStringPoolEntry.h"
-#include "llvm/DWARFLinkerParallel/StringPool.h"
+#include "llvm/DWARFLinker/StringPool.h"
 #include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
 #include "llvm/DebugInfo/DWARF/DWARFObject.h"
 #include "llvm/Object/ObjectFile.h"
@@ -29,6 +29,7 @@
 #include <cstdint>
 
 namespace llvm {
+namespace dwarflinker {
 namespace dwarflinker_parallel {
 
 class TypeUnit;
@@ -62,12 +63,22 @@ enum class DebugSectionKind : uint8_t {
 constexpr static size_t SectionKindsNum =
     static_cast<size_t>(DebugSectionKind::NumberOfEnumEntries);
 
+static constexpr StringLiteral SectionNames[SectionKindsNum] = {
+    "debug_info",     "debug_line",     "debug_frame",       "debug_ranges",
+    "debug_rnglists", "debug_loc",      "debug_loclists",    "debug_aranges",
+    "debug_abbrev",   "debug_macinfo",  "debug_macro",       "debug_addr",
+    "debug_str",      "debug_line_str", "debug_str_offsets", "debug_pubnames",
+    "debug_pubtypes", "debug_names",    "apple_names",       "apple_namespac",
+    "apple_objc",     "apple_types"};
+
+static constexpr const StringLiteral &
+getSectionName(DebugSectionKind SectionKind) {
+  return SectionNames[static_cast<uint8_t>(SectionKind)];
+}
+
 /// Recognise the table name and match it with the DebugSectionKind.
 std::optional<DebugSectionKind> parseDebugTableName(StringRef Name);
 
-/// Return the name of the section.
-const StringLiteral &getSectionName(DebugSectionKind SectionKind);
-
 /// There are fields(sizes, offsets) which should be updated after
 /// sections are generated. To remember offsets and related data
 /// the descendants of SectionPatch structure should be used.
@@ -497,6 +508,7 @@ class OutputSections {
 };
 
 } // end of namespace dwarflinker_parallel
+} // end of namespace dwarflinker
 } // end namespace llvm
 
-#endif // LLVM_LIB_DWARFLINKERPARALLEL_OUTPUTSECTIONS_H
+#endif // LLVM_LIB_DWARFLINKER_LLVM_OUTPUTSECTIONS_H
diff --git a/llvm/lib/DWARFLinkerParallel/StringEntryToDwarfStringPoolEntryMap.h b/llvm/lib/DWARFLinker/LLVM/StringEntryToDwarfStringPoolEntryMap.h
similarity index 88%
rename from llvm/lib/DWARFLinkerParallel/StringEntryToDwarfStringPoolEntryMap.h
rename to llvm/lib/DWARFLinker/LLVM/StringEntryToDwarfStringPoolEntryMap.h
index b4c74d0adba970..ad68109172121c 100644
--- a/llvm/lib/DWARFLinkerParallel/StringEntryToDwarfStringPoolEntryMap.h
+++ b/llvm/lib/DWARFLinker/LLVM/StringEntryToDwarfStringPoolEntryMap.h
@@ -6,14 +6,15 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIB_DWARFLINKERPARALLEL_STRINGENTRYTODWARFSTRINGPOOLENTRYMAP_H
-#define LLVM_LIB_DWARFLINKERPARALLEL_STRINGENTRYTODWARFSTRINGPOOLENTRYMAP_H
+#ifndef LLVM_LIB_DWARFLINKER_LLVM_STRINGENTRYTODWARFSTRINGPOOLENTRYMAP_H
+#define LLVM_LIB_DWARFLINKER_LLVM_STRINGENTRYTODWARFSTRINGPOOLENTRYMAP_H
 
 #include "DWARFLinkerGlobalData.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/DWARFLinkerParallel/StringPool.h"
+#include "llvm/DWARFLinker/StringPool.h"
 
 namespace llvm {
+namespace dwarflinker {
 namespace dwarflinker_parallel {
 
 /// This class creates a DwarfStringPoolEntry for the corresponding StringEntry.
@@ -67,6 +68,7 @@ class StringEntryToDwarfStringPoolEntryMap {
 };
 
 } // end of namespace dwarflinker_parallel
+} // end of namespace dwarflinker
 } // end namespace llvm
 
-#endif // LLVM_LIB_DWARFLINKERPARALLEL_STRINGENTRYTODWARFSTRINGPOOLENTRYMAP_H
+#endif // LLVM_LIB_DWARFLINKER_LLVM_STRINGENTRYTODWARFSTRINGPOOLENTRYMAP_H
diff --git a/llvm/lib/DWARFLinkerParallel/SyntheticTypeNameBuilder.cpp b/llvm/lib/DWARFLinker/LLVM/SyntheticTypeNameBuilder.cpp
similarity index 99%
rename from llvm/lib/DWARFLinkerParallel/SyntheticTypeNameBuilder.cpp
rename to llvm/lib/DWARFLinker/LLVM/SyntheticTypeNameBuilder.cpp
index a9b4478e33c40f..875458ed82536b 100644
--- a/llvm/lib/DWARFLinkerParallel/SyntheticTypeNameBuilder.cpp
+++ b/llvm/lib/DWARFLinker/LLVM/SyntheticTypeNameBuilder.cpp
@@ -12,8 +12,9 @@
 #include "llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h"
 #include "llvm/Support/ScopedPrinter.h"
 
-namespace llvm {
-namespace dwarflinker_parallel {
+using namespace llvm;
+using namespace dwarflinker;
+using namespace dwarflinker_parallel;
 
 Error SyntheticTypeNameBuilder::assignName(
     UnitEntryPairTy InputUnitEntryPair,
@@ -762,6 +763,3 @@ OrderedChildrenIndexAssigner::getChildIndex(
   OrderedChildIdxs[*ArrayIndex]++;
   return Result;
 }
-
-} // end of namespace dwarflinker_parallel
-} // namespace llvm
diff --git a/llvm/lib/DWARFLinkerParallel/SyntheticTypeNameBuilder.h b/llvm/lib/DWARFLinker/LLVM/SyntheticTypeNameBuilder.h
similarity index 96%
rename from llvm/lib/DWARFLinkerParallel/SyntheticTypeNameBuilder.h
rename to llvm/lib/DWARFLinker/LLVM/SyntheticTypeNameBuilder.h
index c9dce4e94fb0dc..2eef161076d805 100644
--- a/llvm/lib/DWARFLinkerParallel/SyntheticTypeNameBuilder.h
+++ b/llvm/lib/DWARFLinker/LLVM/SyntheticTypeNameBuilder.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===/
 
-#ifndef LLVM_LIB_DWARFLINKERNEXT_SYNTHETICTYPENAMEBUILDER_H
-#define LLVM_LIB_DWARFLINKERNEXT_SYNTHETICTYPENAMEBUILDER_H
+#ifndef LLVM_LIB_DWARFLINKER_LLVM_SYNTHETICTYPENAMEBUILDER_H
+#define LLVM_LIB_DWARFLINKER_LLVM_SYNTHETICTYPENAMEBUILDER_H
 
 #include "DWARFLinkerCompileUnit.h"
 #include "DWARFLinkerGlobalData.h"
@@ -17,6 +17,7 @@
 namespace llvm {
 class DWARFDebugInfoEntry;
 
+namespace dwarflinker {
 namespace dwarflinker_parallel {
 struct LinkContext;
 class TypeTableUnit;
@@ -150,6 +151,7 @@ class OrderedChildrenIndexAssigner {
 };
 
 } // end namespace dwarflinker_parallel
+} // end namespace dwarflinker
 } // end namespace llvm
 
-#endif // LLVM_LIB_DWARFLINKERNEXT_SYNTHETICTYPENAMEBUILDER_H
+#endif // LLVM_LIB_DWARFLINKER_LLVM_SYNTHETICTYPENAMEBUILDER_H
diff --git a/llvm/lib/DWARFLinkerParallel/TypePool.h b/llvm/lib/DWARFLinker/LLVM/TypePool.h
similarity index 96%
rename from llvm/lib/DWARFLinkerParallel/TypePool.h
rename to llvm/lib/DWARFLinker/LLVM/TypePool.h
index bbb3261027ce89..29530abb0c5bc2 100644
--- a/llvm/lib/DWARFLinkerParallel/TypePool.h
+++ b/llvm/lib/DWARFLinker/LLVM/TypePool.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_DWARFLINKERPARALLEL_TYPEPOOL_H
-#define LLVM_DWARFLINKERPARALLEL_TYPEPOOL_H
+#ifndef LLVM_DWARFLINKER_LLVM_TYPEPOOL_H
+#define LLVM_DWARFLINKER_LLVM_TYPEPOOL_H
 
 #include "ArrayList.h"
 #include "llvm/ADT/ConcurrentHashtable.h"
@@ -17,6 +17,7 @@
 #include <atomic>
 
 namespace llvm {
+namespace dwarflinker {
 namespace dwarflinker_parallel {
 
 class TypePool;
@@ -172,6 +173,7 @@ class TypePool : ConcurrentHashTableByPtr<StringRef, TypeEntry,
 };
 
 } // end of namespace dwarflinker_parallel
+} // end of namespace dwarflinker
 } // end namespace llvm
 
-#endif // LLVM_DWARFLINKERPARALLEL_TYPEPOOL_H
+#endif // LLVM_DWARFLINKER_LLVM_TYPEPOOL_H
diff --git a/llvm/lib/DWARFLinkerParallel/Utils.h b/llvm/lib/DWARFLinker/LLVM/Utils.h
similarity index 87%
rename from llvm/lib/DWARFLinkerParallel/Utils.h
rename to llvm/lib/DWARFLinker/LLVM/Utils.h
index 91f9dca46a82b1..5f4827b67a4c05 100644
--- a/llvm/lib/DWARFLinkerParallel/Utils.h
+++ b/llvm/lib/DWARFLinker/LLVM/Utils.h
@@ -6,12 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIB_DWARFLINKERPARALLEL_UTILS_H
-#define LLVM_LIB_DWARFLINKERPARALLEL_UTILS_H
+#ifndef LLVM_LIB_DWARFLINKER_LLVM_UTILS_H
+#define LLVM_LIB_DWARFLINKER_LLVM_UTILS_H
 
 #include "llvm/Support/Error.h"
 
 namespace llvm {
+namespace dwarflinker {
 namespace dwarflinker_parallel {
 
 /// This function calls \p Iteration() until it returns false.
@@ -35,6 +36,7 @@ inline Error finiteLoop(function_ref<Expected<bool>()> Iteration,
 }
 
 } // end of namespace dwarflinker_parallel
+} // end of namespace dwarflinker
 } // end namespace llvm
 
-#endif // LLVM_LIB_DWARFLINKERPARALLEL_UTILS_H
+#endif // LLVM_LIB_DWARFLINKER_LLVM_UTILS_H
diff --git a/llvm/lib/DWARFLinkerParallel/StringPool.cpp b/llvm/lib/DWARFLinker/Utils.cpp
similarity index 68%
rename from llvm/lib/DWARFLinkerParallel/StringPool.cpp
rename to llvm/lib/DWARFLinker/Utils.cpp
index fbff6b05e3a542..e8b0fe303aaef8 100644
--- a/llvm/lib/DWARFLinkerParallel/StringPool.cpp
+++ b/llvm/lib/DWARFLinker/Utils.cpp
@@ -1,9 +1,7 @@
-//=== StringPool.cpp ------------------------------------------------------===//
+//===- Utils.cpp ------------------------------------------------*- 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
 //
 //===----------------------------------------------------------------------===//
-
-#include "llvm/DWARFLinkerParallel/StringPool.h"
diff --git a/llvm/lib/DWARFLinkerParallel/DWARFFile.cpp b/llvm/lib/DWARFLinkerParallel/DWARFFile.cpp
deleted file mode 100644
index 5a3486e6398d4c..00000000000000
--- a/llvm/lib/DWARFLinkerParallel/DWARFFile.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-//=== DWARFFile.cpp -------------------------------------------------------===//
-//
-// 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 "llvm/DWARFLinkerParallel/DWARFFile.h"
-#include "DWARFLinkerGlobalData.h"
-
-llvm::dwarflinker_parallel::DWARFFile::DWARFFile(
-    StringRef Name, std::unique_ptr<DWARFContext> Dwarf,
-    std::unique_ptr<AddressesMap> Addresses,
-    DWARFFile::UnloadCallbackTy UnloadFunc)
-    : FileName(Name), Dwarf(std::move(Dwarf)), Addresses(std::move(Addresses)),
-      UnloadFunc(UnloadFunc) {}
diff --git a/llvm/tools/dsymutil/CMakeLists.txt b/llvm/tools/dsymutil/CMakeLists.txt
index c612bfd9150c47..0e407f6fa1db43 100644
--- a/llvm/tools/dsymutil/CMakeLists.txt
+++ b/llvm/tools/dsymutil/CMakeLists.txt
@@ -9,6 +9,7 @@ set(LLVM_LINK_COMPONENTS
   AsmPrinter
   CodeGen
   CodeGenTypes
+  DWARFLinkerBase
   DWARFLinker
   DWARFLinkerParallel
   DebugInfoDWARF
diff --git a/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp b/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
index 33d053c745b0cb..1343774cfd0c15 100644
--- a/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
+++ b/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
@@ -27,8 +27,8 @@
 #include "llvm/CodeGen/DIE.h"
 #include "llvm/CodeGen/NonRelocatableStringpool.h"
 #include "llvm/Config/config.h"
-#include "llvm/DWARFLinker/DWARFLinkerDeclContext.h"
-#include "llvm/DWARFLinkerParallel/DWARFLinker.h"
+#include "llvm/DWARFLinker/Apple/DWARFLinkerDeclContext.h"
+#include "llvm/DWARFLinker/LLVM/DWARFLinker.h"
 #include "llvm/DebugInfo/DIContext.h"
 #include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
@@ -100,6 +100,8 @@ namespace llvm {
 
 static mc::RegisterMCTargetOptionsFlags MOF;
 
+using namespace dwarflinker;
+
 namespace dsymutil {
 
 static void dumpDIE(const DWARFDie *DIE, bool Verbose) {
@@ -185,10 +187,8 @@ static Error remarksErrorHandler(const DebugMapObject &DMO,
 
   return createFileError(FE->getFileName(), std::move(NewE));
 }
-template <typename OutDwarfFile, typename AddressMap>
 Error DwarfLinkerForBinary::emitRelocations(
-    const DebugMap &DM,
-    std::vector<ObjectWithRelocMap<OutDwarfFile>> &ObjectsForLinking) {
+    const DebugMap &DM, std::vector<ObjectWithRelocMap> &ObjectsForLinking) {
   // Return early if the "Resources" directory is not being written to.
   if (!Options.ResourceDir)
     return Error::success();
@@ -262,13 +262,12 @@ static Error emitRemarks(const LinkOptions &Options, StringRef BinaryPath,
   return Error::success();
 }
 
-template <typename OutDWARFFile, typename AddressesMap>
-ErrorOr<std::unique_ptr<OutDWARFFile>> DwarfLinkerForBinary::loadObject(
+ErrorOr<std::unique_ptr<DWARFFile>> DwarfLinkerForBinary::loadObject(
     const DebugMapObject &Obj, const DebugMap &DebugMap,
     remarks::RemarkLinker &RL,
     std::shared_ptr<DwarfLinkerForBinaryRelocationMap> DLBRM) {
   auto ErrorOrObj = loadObject(Obj, DebugMap.getTriple());
-  std::unique_ptr<OutDWARFFile> Res;
+  std::unique_ptr<DWARFFile> Res;
 
   if (ErrorOrObj) {
     auto Context = DWARFContext::create(
@@ -285,9 +284,9 @@ ErrorOr<std::unique_ptr<OutDWARFFile>> DwarfLinkerForBinary::loadObject(
           });
         });
     DLBRM->init(*Context);
-    Res = std::make_unique<OutDWARFFile>(
+    Res = std::make_unique<DWARFFile>(
         Obj.getObjectFilename(), std::move(Context),
-        std::make_unique<AddressesMap>(*this, *ErrorOrObj, Obj, DLBRM),
+        std::make_unique<AddressManager>(*this, *ErrorOrObj, Obj, DLBRM),
         [&](StringRef FileName) { BinHolder.eraseObjectEntry(FileName); });
 
     Error E = RL.link(*ErrorOrObj);
@@ -607,14 +606,11 @@ bool DwarfLinkerForBinary::link(const DebugMap &Map) {
       break;
     }
 
-    return linkImpl<dwarflinker_parallel::DWARFLinker,
-                    dwarflinker_parallel::DWARFFile,
-                    AddressManager<dwarflinker_parallel::AddressesMap>>(
-        Map, DWARFLinkerOutputType);
+    return linkImpl<dwarflinker_parallel::DWARFLinker>(Map,
+                                                       DWARFLinkerOutputType);
   }
 
-  return linkImpl<DWARFLinker, DWARFFile, AddressManager<AddressesMap>>(
-      Map, Options.FileType);
+  return linkImpl<DWARFLinker>(Map, Options.FileType);
 }
 
 template <typename Linker>
@@ -645,11 +641,11 @@ void setAcceleratorTables(Linker &GeneralLinker,
   llvm_unreachable("All cases handled above!");
 }
 
-template <typename Linker, typename OutDwarfFile, typename AddressMap>
+template <typename Linker>
 bool DwarfLinkerForBinary::linkImpl(
     const DebugMap &Map, typename Linker::OutputFileType ObjectType) {
 
-  std::vector<ObjectWithRelocMap<OutDwarfFile>> ObjectsForLinking;
+  std::vector<ObjectWithRelocMap> ObjectsForLinking;
 
   DebugMap DebugMap(Map.getTriple(), Map.getBinaryPath());
 
@@ -691,22 +687,22 @@ bool DwarfLinkerForBinary::linkImpl(
   GeneralLinker->setNumThreads(Options.Threads);
   GeneralLinker->setPrependPath(Options.PrependPath);
   GeneralLinker->setKeepFunctionForStatic(Options.KeepFunctionForStatic);
-  GeneralLinker->setInputVerificationHandler([&](const OutDwarfFile &File, llvm::StringRef Output) {
-    std::lock_guard<std::mutex> Guard(ErrorHandlerMutex);
-    if (Options.Verbose)
-      errs() << Output;
-    warn("input verification failed", File.FileName);
-    HasVerificationErrors = true;
-  });
+  GeneralLinker->setInputVerificationHandler(
+      [&](const DWARFFile &File, llvm::StringRef Output) {
+        std::lock_guard<std::mutex> Guard(ErrorHandlerMutex);
+        if (Options.Verbose)
+          errs() << Output;
+        warn("input verification failed", File.FileName);
+        HasVerificationErrors = true;
+      });
   auto Loader = [&](StringRef ContainerName,
-                    StringRef Path) -> ErrorOr<OutDwarfFile &> {
+                    StringRef Path) -> ErrorOr<DWARFFile &> {
     auto &Obj = DebugMap.addDebugMapObject(
         Path, sys::TimePoint<std::chrono::seconds>(), MachO::N_OSO);
 
     auto DLBRelocMap = std::make_shared<DwarfLinkerForBinaryRelocationMap>();
-    if (ErrorOr<std::unique_ptr<OutDwarfFile>> ErrorOrObj =
-            loadObject<OutDwarfFile, AddressMap>(Obj, DebugMap, RL,
-                                                 DLBRelocMap)) {
+    if (ErrorOr<std::unique_ptr<DWARFFile>> ErrorOrObj =
+            loadObject(Obj, DebugMap, RL, DLBRelocMap)) {
       ObjectsForLinking.emplace_back(std::move(*ErrorOrObj), DLBRelocMap);
       return *ObjectsForLinking.back().Object;
     } else {
@@ -820,15 +816,15 @@ bool DwarfLinkerForBinary::linkImpl(
     }
 
     auto DLBRelocMap = std::make_shared<DwarfLinkerForBinaryRelocationMap>();
-    if (ErrorOr<std::unique_ptr<OutDwarfFile>> ErrorOrObj =
-            loadObject<OutDwarfFile, AddressMap>(*Obj, Map, RL, DLBRelocMap)) {
+    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,
                                    OnCUDieLoaded);
     } else {
       ObjectsForLinking.push_back(
-          {std::make_unique<OutDwarfFile>(Obj->getObjectFilename(), nullptr,
-                                          nullptr),
+          {std::make_unique<DWARFFile>(Obj->getObjectFilename(), nullptr,
+                                       nullptr),
            DLBRelocMap});
       GeneralLinker->addObjectFile(*ObjectsForLinking.back().Object);
     }
@@ -855,8 +851,7 @@ bool DwarfLinkerForBinary::linkImpl(
   if (Options.NoOutput)
     return true;
 
-  if (Error E =
-          emitRelocations<OutDwarfFile, AddressMap>(Map, ObjectsForLinking))
+  if (Error E = emitRelocations(Map, ObjectsForLinking))
     return error(toString(std::move(E)));
 
   if (Options.ResourceDir && !ParseableSwiftInterfaces.empty()) {
@@ -879,12 +874,9 @@ bool DwarfLinkerForBinary::linkImpl(
 /// Iterate over the relocations of the given \p Section and
 /// store the ones that correspond to debug map entries into the
 /// ValidRelocs array.
-template <typename AddressesMapBase>
-void DwarfLinkerForBinary::AddressManager<AddressesMapBase>::
-    findValidRelocsMachO(const object::SectionRef &Section,
-                         const object::MachOObjectFile &Obj,
-                         const DebugMapObject &DMO,
-                         std::vector<ValidReloc> &ValidRelocs) {
+void DwarfLinkerForBinary::AddressManager::findValidRelocsMachO(
+    const object::SectionRef &Section, const object::MachOObjectFile &Obj,
+    const DebugMapObject &DMO, std::vector<ValidReloc> &ValidRelocs) {
   Expected<StringRef> ContentsOrErr = Section.getContents();
   if (!ContentsOrErr) {
     consumeError(ContentsOrErr.takeError());
@@ -961,8 +953,7 @@ void DwarfLinkerForBinary::AddressManager<AddressesMapBase>::
 
 /// Dispatch the valid relocation finding logic to the
 /// appropriate handler depending on the object file format.
-template <typename AddressesMapBase>
-bool DwarfLinkerForBinary::AddressManager<AddressesMapBase>::findValidRelocs(
+bool DwarfLinkerForBinary::AddressManager::findValidRelocs(
     const object::SectionRef &Section, const object::ObjectFile &Obj,
     const DebugMapObject &DMO, std::vector<ValidReloc> &Relocs) {
   // Dispatch to the right handler depending on the file type.
@@ -987,10 +978,8 @@ bool DwarfLinkerForBinary::AddressManager<AddressesMapBase>::findValidRelocs(
 /// entries in the debug map. These relocations will drive the Dwarf link by
 /// indicating which DIEs refer to symbols present in the linked binary.
 /// \returns whether there are any valid relocations in the debug info.
-template <typename AddressesMapBase>
-bool DwarfLinkerForBinary::AddressManager<AddressesMapBase>::
-    findValidRelocsInDebugSections(const object::ObjectFile &Obj,
-                                   const DebugMapObject &DMO) {
+bool DwarfLinkerForBinary::AddressManager::findValidRelocsInDebugSections(
+    const object::ObjectFile &Obj, const DebugMapObject &DMO) {
   // Find the debug_info section.
   bool FoundValidRelocs = false;
   for (const object::SectionRef &Section : Obj.sections()) {
@@ -1011,9 +1000,7 @@ bool DwarfLinkerForBinary::AddressManager<AddressesMapBase>::
   return FoundValidRelocs;
 }
 
-template <typename AddressesMapBase>
-std::vector<ValidReloc>
-DwarfLinkerForBinary::AddressManager<AddressesMapBase>::getRelocations(
+std::vector<ValidReloc> DwarfLinkerForBinary::AddressManager::getRelocations(
     const std::vector<ValidReloc> &Relocs, uint64_t StartPos, uint64_t EndPos) {
   std::vector<ValidReloc> Res;
 
@@ -1030,9 +1017,7 @@ DwarfLinkerForBinary::AddressManager<AddressesMapBase>::getRelocations(
   return Res;
 }
 
-template <typename AddressesMapBase>
-void DwarfLinkerForBinary::AddressManager<AddressesMapBase>::printReloc(
-    const ValidReloc &Reloc) {
+void DwarfLinkerForBinary::AddressManager::printReloc(const ValidReloc &Reloc) {
   const auto &Mapping = Reloc.SymbolMapping;
   const uint64_t ObjectAddress = Mapping.ObjectAddress
                                      ? uint64_t(*Mapping.ObjectAddress)
@@ -1043,18 +1028,16 @@ void DwarfLinkerForBinary::AddressManager<AddressesMapBase>::printReloc(
                    uint64_t(Mapping.BinaryAddress));
 }
 
-template <typename AddressesMapBase>
-int64_t DwarfLinkerForBinary::AddressManager<AddressesMapBase>::getRelocValue(
-    const ValidReloc &Reloc) {
+int64_t
+DwarfLinkerForBinary::AddressManager::getRelocValue(const ValidReloc &Reloc) {
   int64_t AddrAdjust = relocate(Reloc);
   if (Reloc.SymbolMapping.ObjectAddress)
     AddrAdjust -= uint64_t(*Reloc.SymbolMapping.ObjectAddress);
   return AddrAdjust;
 }
 
-template <typename AddressesMapBase>
 std::optional<int64_t>
-DwarfLinkerForBinary::AddressManager<AddressesMapBase>::hasValidRelocationAt(
+DwarfLinkerForBinary::AddressManager::hasValidRelocationAt(
     const std::vector<ValidReloc> &AllRelocs, uint64_t StartOffset,
     uint64_t EndOffset) {
   std::vector<ValidReloc> Relocs =
@@ -1089,11 +1072,10 @@ getAttributeOffsets(const DWARFAbbreviationDeclaration *Abbrev, unsigned Idx,
   return std::make_pair(Offset, End);
 }
 
-template <typename AddressesMapBase>
-std::optional<int64_t> DwarfLinkerForBinary::AddressManager<AddressesMapBase>::
-    getExprOpAddressRelocAdjustment(DWARFUnit &U,
-                                    const DWARFExpression::Operation &Op,
-                                    uint64_t StartOffset, uint64_t EndOffset) {
+std::optional<int64_t>
+DwarfLinkerForBinary::AddressManager::getExprOpAddressRelocAdjustment(
+    DWARFUnit &U, const DWARFExpression::Operation &Op, uint64_t StartOffset,
+    uint64_t EndOffset) {
   switch (Op.getCode()) {
   default: {
     assert(false && "Specified operation does not have address operand");
@@ -1116,9 +1098,9 @@ std::optional<int64_t> DwarfLinkerForBinary::AddressManager<AddressesMapBase>::
   return std::nullopt;
 }
 
-template <typename AddressesMapBase>
-std::optional<int64_t> DwarfLinkerForBinary::AddressManager<
-    AddressesMapBase>::getSubprogramRelocAdjustment(const DWARFDie &DIE) {
+std::optional<int64_t>
+DwarfLinkerForBinary::AddressManager::getSubprogramRelocAdjustment(
+    const DWARFDie &DIE) {
   const auto *Abbrev = DIE.getAbbreviationDeclarationPtr();
 
   std::optional<uint32_t> LowPcIdx =
@@ -1158,25 +1140,19 @@ std::optional<int64_t> DwarfLinkerForBinary::AddressManager<
   }
 }
 
-template <typename AddressesMapBase>
-std::optional<StringRef> DwarfLinkerForBinary::AddressManager<
-    AddressesMapBase>::getLibraryInstallName() {
+std::optional<StringRef>
+DwarfLinkerForBinary::AddressManager::getLibraryInstallName() {
   return LibInstallName;
 }
 
-template <typename AddressesMapBase>
-uint64_t DwarfLinkerForBinary::AddressManager<AddressesMapBase>::relocate(
-    const ValidReloc &Reloc) const {
+uint64_t
+DwarfLinkerForBinary::AddressManager::relocate(const ValidReloc &Reloc) const {
   return Reloc.SymbolMapping.BinaryAddress + Reloc.Addend;
 }
 
-template <typename AddressesMapBase>
-void DwarfLinkerForBinary::AddressManager<
-    AddressesMapBase>::updateAndSaveValidRelocs(bool IsDWARF5,
-                                                uint64_t OriginalUnitOffset,
-                                                int64_t LinkedOffset,
-                                                uint64_t StartOffset,
-                                                uint64_t EndOffset) {
+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)
@@ -1185,10 +1161,8 @@ void DwarfLinkerForBinary::AddressManager<
       IsDWARF5, InRelocs, OriginalUnitOffset, LinkedOffset);
 }
 
-template <typename AddressesMapBase>
-void DwarfLinkerForBinary::AddressManager<AddressesMapBase>::
-    updateRelocationsWithUnitOffset(uint64_t OriginalUnitOffset,
-                                    uint64_t OutputUnitOffset) {
+void DwarfLinkerForBinary::AddressManager::updateRelocationsWithUnitOffset(
+    uint64_t OriginalUnitOffset, uint64_t OutputUnitOffset) {
   DwarfLinkerRelocMap->updateRelocationsWithUnitOffset(OriginalUnitOffset,
                                                        OutputUnitOffset);
 }
@@ -1200,8 +1174,7 @@ void DwarfLinkerForBinary::AddressManager<AddressesMapBase>::
 /// monotonic \p BaseOffset values.
 ///
 /// \returns whether any reloc has been applied.
-template <typename AddressesMapBase>
-bool DwarfLinkerForBinary::AddressManager<AddressesMapBase>::applyValidRelocs(
+bool DwarfLinkerForBinary::AddressManager::applyValidRelocs(
     MutableArrayRef<char> Data, uint64_t BaseOffset, bool IsLittleEndian) {
 
   std::vector<ValidReloc> Relocs = getRelocations(
diff --git a/llvm/tools/dsymutil/DwarfLinkerForBinary.h b/llvm/tools/dsymutil/DwarfLinkerForBinary.h
index 328cd9197d0d17..34cf9add5236ec 100644
--- a/llvm/tools/dsymutil/DwarfLinkerForBinary.h
+++ b/llvm/tools/dsymutil/DwarfLinkerForBinary.h
@@ -14,10 +14,10 @@
 #include "LinkUtils.h"
 #include "MachOUtils.h"
 #include "RelocationMap.h"
-#include "llvm/DWARFLinker/DWARFLinker.h"
-#include "llvm/DWARFLinker/DWARFLinkerCompileUnit.h"
-#include "llvm/DWARFLinker/DWARFLinkerDeclContext.h"
-#include "llvm/DWARFLinker/DWARFStreamer.h"
+#include "llvm/DWARFLinker/Apple/DWARFLinker.h"
+#include "llvm/DWARFLinker/Apple/DWARFLinkerCompileUnit.h"
+#include "llvm/DWARFLinker/Apple/DWARFLinkerDeclContext.h"
+#include "llvm/DWARFLinker/Apple/DWARFStreamer.h"
 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
 #include "llvm/Remarks/RemarkFormat.h"
 #include "llvm/Remarks/RemarkLinker.h"
@@ -25,6 +25,8 @@
 #include <optional>
 
 namespace llvm {
+using namespace dwarflinker;
+
 namespace dsymutil {
 
 /// DwarfLinkerForBinaryRelocationMap contains the logic to handle the
@@ -55,12 +57,12 @@ class DwarfLinkerForBinaryRelocationMap {
   DwarfLinkerForBinaryRelocationMap() = default;
 };
 
-template <typename OutDwarfFile> struct ObjectWithRelocMap {
+struct ObjectWithRelocMap {
   ObjectWithRelocMap(
-      std::unique_ptr<OutDwarfFile> Object,
+      std::unique_ptr<DWARFFile> Object,
       std::shared_ptr<DwarfLinkerForBinaryRelocationMap> OutRelocs)
       : Object(std::move(Object)), OutRelocs(OutRelocs) {}
-  std::unique_ptr<OutDwarfFile> Object;
+  std::unique_ptr<DWARFFile> Object;
   std::shared_ptr<DwarfLinkerForBinaryRelocationMap> OutRelocs;
 };
 
@@ -104,8 +106,7 @@ class DwarfLinkerForBinary {
 private:
 
   /// Keeps track of relocations.
-  template <typename AddressesMapBase>
-  class AddressManager : public AddressesMapBase {
+  class AddressManager : public dwarflinker::AddressesMap {
 
     const DwarfLinkerForBinary &Linker;
 
@@ -241,8 +242,7 @@ class DwarfLinkerForBinary {
   /// Attempt to load a debug object from disk.
   ErrorOr<const object::ObjectFile &> loadObject(const DebugMapObject &Obj,
                                                  const Triple &triple);
-  template <typename OutDWARFFile, typename AddressesMap>
-  ErrorOr<std::unique_ptr<OutDWARFFile>>
+  ErrorOr<std::unique_ptr<dwarflinker::DWARFFile>>
   loadObject(const DebugMapObject &Obj, const DebugMap &DebugMap,
              remarks::RemarkLinker &RL,
              std::shared_ptr<DwarfLinkerForBinaryRelocationMap> DLBRM);
@@ -264,14 +264,12 @@ class DwarfLinkerForBinary {
       std::vector<MachOUtils::DwarfRelocationApplicationInfo>
           &RelocationsToApply);
 
-  template <typename Linker, typename OutDwarfFile, typename AddressMapBase>
+  template <typename Linker>
   bool linkImpl(const DebugMap &Map,
                 typename Linker::OutputFileType ObjectType);
 
-  template <typename OutDwarfFile, typename AddressMap>
-  Error emitRelocations(
-      const DebugMap &DM,
-      std::vector<ObjectWithRelocMap<OutDwarfFile>> &ObjectsForLinking);
+  Error emitRelocations(const DebugMap &DM,
+                        std::vector<ObjectWithRelocMap> &ObjectsForLinking);
 
   raw_fd_ostream &OutFile;
   BinaryHolder &BinHolder;
diff --git a/llvm/tools/dsymutil/LinkUtils.h b/llvm/tools/dsymutil/LinkUtils.h
index 0bf6d9aac1a3f3..5d80be640deeb3 100644
--- a/llvm/tools/dsymutil/LinkUtils.h
+++ b/llvm/tools/dsymutil/LinkUtils.h
@@ -16,8 +16,8 @@
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/WithColor.h"
 
-#include "llvm/DWARFLinker/DWARFLinker.h"
-#include "llvm/DWARFLinker/DWARFStreamer.h"
+#include "llvm/DWARFLinker/Apple/DWARFLinker.h"
+#include "llvm/DWARFLinker/Apple/DWARFStreamer.h"
 #include <string>
 
 namespace llvm {
@@ -72,7 +72,8 @@ struct LinkOptions {
   unsigned Threads = 1;
 
   // Output file type.
-  DWARFLinker::OutputFileType FileType = DWARFLinker::OutputFileType::Object;
+  dwarflinker::DWARFLinker::OutputFileType FileType =
+      dwarflinker::DWARFLinker::OutputFileType::Object;
 
   /// The accelerator table kind
   DsymutilAccelTableKind TheAccelTableKind;
diff --git a/llvm/tools/dsymutil/dsymutil.cpp b/llvm/tools/dsymutil/dsymutil.cpp
index 2dd123318e00bd..0b8d29793d4f7b 100644
--- a/llvm/tools/dsymutil/dsymutil.cpp
+++ b/llvm/tools/dsymutil/dsymutil.cpp
@@ -55,6 +55,7 @@
 using namespace llvm;
 using namespace llvm::dsymutil;
 using namespace object;
+using namespace llvm::dwarflinker;
 
 namespace {
 enum ID {
diff --git a/llvm/tools/llvm-dwarfutil/CMakeLists.txt b/llvm/tools/llvm-dwarfutil/CMakeLists.txt
index b2585799b10c13..91b25207b4f728 100644
--- a/llvm/tools/llvm-dwarfutil/CMakeLists.txt
+++ b/llvm/tools/llvm-dwarfutil/CMakeLists.txt
@@ -7,6 +7,7 @@ set(LLVM_LINK_COMPONENTS
   AllTargetsDescs
   AllTargetsInfos
   CodeGenTypes
+  DWARFLinkerBase
   DWARFLinker
   DWARFLinkerParallel
   DebugInfoDWARF
diff --git a/llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp b/llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp
index 02a94596ec7644..61856a055d83e7 100644
--- a/llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp
+++ b/llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp
@@ -9,9 +9,9 @@
 #include "DebugInfoLinker.h"
 #include "Error.h"
 #include "llvm/ADT/StringSwitch.h"
-#include "llvm/DWARFLinker/DWARFLinker.h"
-#include "llvm/DWARFLinker/DWARFStreamer.h"
-#include "llvm/DWARFLinkerParallel/DWARFLinker.h"
+#include "llvm/DWARFLinker/Apple/DWARFLinker.h"
+#include "llvm/DWARFLinker/Apple/DWARFStreamer.h"
+#include "llvm/DWARFLinker/LLVM/DWARFLinker.h"
 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
 #include "llvm/DebugInfo/DWARF/DWARFExpression.h"
 #include "llvm/Object/ObjectFile.h"
@@ -19,6 +19,8 @@
 #include <vector>
 
 namespace llvm {
+using namespace dwarflinker;
+
 namespace dwarfutil {
 
 // ObjFileAddressMap allows to check whether specified DIE referencing
@@ -37,8 +39,7 @@ namespace dwarfutil {
 // exec: [LowPC, HighPC] is not inside address ranges of .text sections
 //
 // universal: maxpc and bfd
-template <typename AddressMapBase>
-class ObjFileAddressMap : public AddressMapBase {
+class ObjFileAddressMap : public AddressesMap {
 public:
   ObjFileAddressMap(DWARFContext &Context, const Options &Options,
                     object::ObjectFile &ObjFile)
@@ -298,7 +299,7 @@ static std::string getMessageForDeletedAcceleratorTables(
   return Message;
 }
 
-template <typename Linker, typename OutDwarfFile, typename AddressMapBase>
+template <typename Linker>
 Error linkDebugInfoImpl(object::ObjectFile &File, const Options &Options,
                         raw_pwrite_stream &OutStream) {
   std::mutex ErrorHandlerMutex;
@@ -345,7 +346,7 @@ Error linkDebugInfoImpl(object::ObjectFile &File, const Options &Options,
   DebugInfoLinker->setVerbosity(Options.Verbose);
   DebugInfoLinker->setUpdateIndexTablesOnly(!Options.DoGarbageCollection);
 
-  std::vector<std::unique_ptr<OutDwarfFile>> ObjectsForLinking(1);
+  std::vector<std::unique_ptr<DWARFFile>> ObjectsForLinking(1);
 
   // Add object files to the DWARFLinker.
   std::unique_ptr<DWARFContext> Context = DWARFContext::create(
@@ -360,11 +361,10 @@ Error linkDebugInfoImpl(object::ObjectFile &File, const Options &Options,
           ReportWarn(Info.message(), "", nullptr);
         });
       });
-  std::unique_ptr<ObjFileAddressMap<AddressMapBase>> AddressesMap(
-      std::make_unique<ObjFileAddressMap<AddressMapBase>>(*Context, Options,
-                                                          File));
+  std::unique_ptr<ObjFileAddressMap> AddressesMap(
+      std::make_unique<ObjFileAddressMap>(*Context, Options, File));
 
-  ObjectsForLinking[0] = std::make_unique<OutDwarfFile>(
+  ObjectsForLinking[0] = std::make_unique<DWARFFile>(
       File.getFileName(), std::move(Context), std::move(AddressesMap));
 
   uint16_t MaxDWARFVersion = 0;
@@ -400,7 +400,7 @@ Error linkDebugInfoImpl(object::ObjectFile &File, const Options &Options,
   for (typename Linker::AccelTableKind Table : AccelTables)
     DebugInfoLinker->addAccelTableKind(Table);
 
-  for (std::unique_ptr<OutDwarfFile> &CurFile : ObjectsForLinking) {
+  for (std::unique_ptr<DWARFFile> &CurFile : ObjectsForLinking) {
     SmallVector<StringRef> AccelTableNamesToReplace;
     SmallVector<StringRef> AccelTableNamesToDelete;
 
@@ -452,13 +452,10 @@ Error linkDebugInfoImpl(object::ObjectFile &File, const Options &Options,
 Error linkDebugInfo(object::ObjectFile &File, const Options &Options,
                     raw_pwrite_stream &OutStream) {
   if (Options.UseLLVMDWARFLinker)
-    return linkDebugInfoImpl<dwarflinker_parallel::DWARFLinker,
-                             dwarflinker_parallel::DWARFFile,
-                             dwarflinker_parallel::AddressesMap>(File, Options,
-                                                                 OutStream);
+    return linkDebugInfoImpl<dwarflinker_parallel::DWARFLinker>(File, Options,
+                                                                OutStream);
   else
-    return linkDebugInfoImpl<DWARFLinker, DWARFFile, AddressesMap>(
-        File, Options, OutStream);
+    return linkDebugInfoImpl<DWARFLinker>(File, Options, OutStream);
 }
 
 } // end of namespace dwarfutil
diff --git a/llvm/unittests/DWARFLinkerParallel/StringPoolTest.cpp b/llvm/unittests/DWARFLinkerParallel/StringPoolTest.cpp
index 84199f696a59de..b3a6c674d2e5da 100644
--- a/llvm/unittests/DWARFLinkerParallel/StringPoolTest.cpp
+++ b/llvm/unittests/DWARFLinkerParallel/StringPoolTest.cpp
@@ -6,13 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/DWARFLinkerParallel/StringPool.h"
+#include "llvm/DWARFLinker/StringPool.h"
 #include "llvm/Support/Parallel.h"
 #include "gtest/gtest.h"
 #include <cstdlib>
 
 using namespace llvm;
-using namespace dwarflinker_parallel;
+using namespace dwarflinker;
 
 namespace {
 

>From ec5aabe861bb79fa28460474768d051f6600f885 Mon Sep 17 00:00:00 2001
From: Alexey Lapshin <a.v.lapshin at mail.ru>
Date: Sat, 23 Dec 2023 00:17:16 +0300
Subject: [PATCH 2/3] addressed comments.

---
 .../llvm/DWARFLinker/Apple/DWARFLinker.h      |  6 ++--
 .../llvm/DWARFLinker/DWARFLinkerBase.h        | 28 ++++++++++---------
 .../DWARFLinker/LLVM/DWARFLinkerGlobalData.h  |  2 +-
 llvm/lib/DWARFLinker/LLVM/DWARFLinkerImpl.h   |  2 +-
 4 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/llvm/include/llvm/DWARFLinker/Apple/DWARFLinker.h b/llvm/include/llvm/DWARFLinker/Apple/DWARFLinker.h
index 05cee779179cda..b743c75339d7f4 100644
--- a/llvm/include/llvm/DWARFLinker/Apple/DWARFLinker.h
+++ b/llvm/include/llvm/DWARFLinker/Apple/DWARFLinker.h
@@ -310,9 +310,7 @@ class DWARFLinker : public DWARFLinkerBase {
   }
 
   /// Set prepend path for clang modules.
-  void setPrependPath(const std::string &Ppath) override {
-    Options.PrependPath = Ppath;
-  }
+  void setPrependPath(StringRef Ppath) override { Options.PrependPath = Ppath; }
 
   /// Set estimated objects files amount, for preliminary data allocation.
   void setEstimatedObjfilesAmount(unsigned ObjFilesNum) override {
@@ -844,7 +842,7 @@ class DWARFLinker : public DWARFLinkerBase {
     SmallVector<AccelTableKind, 1> AccelTables;
 
     /// Prepend path for the clang modules.
-    std::string PrependPath;
+    StringRef PrependPath;
 
     // input verification handler
     InputVerificationHandlerTy InputVerificationHandler = nullptr;
diff --git a/llvm/include/llvm/DWARFLinker/DWARFLinkerBase.h b/llvm/include/llvm/DWARFLinker/DWARFLinkerBase.h
index a7dc77cb1a8a64..e7394ce90a9af2 100644
--- a/llvm/include/llvm/DWARFLinker/DWARFLinkerBase.h
+++ b/llvm/include/llvm/DWARFLinker/DWARFLinkerBase.h
@@ -42,25 +42,27 @@ class DWARFLinkerBase {
     Object,
     Assembly,
   };
-  /// The kind of accelerator tables we should emit.
+  /// The kind of accelerator tables to be emitted.
   enum class AccelTableKind : uint8_t {
     Apple,     ///< .apple_names, .apple_namespaces, .apple_types, .apple_objc.
     Pub,       ///< .debug_pubnames, .debug_pubtypes
     DebugNames ///< .debug_names.
   };
-  /// Add object file to be linked. Pre-load compile unit die. Call
-  /// \p OnCUDieLoaded for each compile unit die. If specified \p File
-  /// has reference to the Clang module then such module would be
-  /// pre-loaded by \p Loader for !Update case.
+  /// Add an object file to be linked. Pre-load compile unit die. Call
+  /// \p OnCUDieLoaded for each compile unit die. If \p File has reference to
+  /// a Clang module and UpdateIndexTablesOnly == false then the module is be
+  /// pre-loaded by \p Loader.
   ///
-  /// \pre NoODR, Update options should be set before call to addObjectFile.
+  /// \pre a call to setNoODR(true) and/or setUpdateIndexTablesOnly(bool Update)
+  ///      must be made when required.
   virtual void addObjectFile(
       DWARFFile &File, ObjFileLoaderTy Loader = nullptr,
       CompileUnitHandlerTy OnCUDieLoaded = [](const DWARFUnit &) {}) = 0;
-  /// Link debug info for added objFiles. Object files are linked all together.
+  /// Link the debug info for all object files added through calls to
+  /// addObjectFile.
   virtual Error link() = 0;
   /// A number of methods setting various linking options:
-  /// Allows to generate log of linking process to the standard output.
+  /// Enable logging to standard output.
   virtual void setVerbosity(bool Verbose) = 0;
   /// Print statistics to standard output.
   virtual void setStatistics(bool Statistics) = 0;
@@ -68,9 +70,10 @@ class DWARFLinkerBase {
   virtual void setVerifyInputDWARF(bool Verify) = 0;
   /// Do not unique types according to ODR.
   virtual void setNoODR(bool NoODR) = 0;
-  /// Update index tables only(do not modify rest of DWARF).
+  /// Update index tables only (do not modify rest of DWARF).
   virtual void setUpdateIndexTablesOnly(bool Update) = 0;
-  /// Allow generating valid, but non-deterministic output.
+  /// Allows generating non-deterministic output in exchange for more
+  /// parallelism.
   virtual void setAllowNonDeterministicOutput(bool) = 0;
   /// Set whether to keep the enclosing function for a static variable.
   virtual void setKeepFunctionForStatic(bool KeepFunctionForStatic) = 0;
@@ -79,11 +82,10 @@ class DWARFLinkerBase {
   /// Add kind of accelerator tables to be generated.
   virtual void addAccelTableKind(AccelTableKind Kind) = 0;
   /// Set prepend path for clang modules.
-  virtual void setPrependPath(const std::string &Ppath) = 0;
+  virtual void setPrependPath(StringRef Ppath) = 0;
   /// Set estimated objects files amount, for preliminary data allocation.
   virtual void setEstimatedObjfilesAmount(unsigned ObjFilesNum) = 0;
-  /// Set verification handler which would be used to report verification
-  /// errors.
+  /// Set verification handler which used to report verification errors.
   virtual void
   setInputVerificationHandler(InputVerificationHandlerTy Handler) = 0;
   /// Set map for Swift interfaces.
diff --git a/llvm/lib/DWARFLinker/LLVM/DWARFLinkerGlobalData.h b/llvm/lib/DWARFLinker/LLVM/DWARFLinkerGlobalData.h
index 656e49af1a19a7..8305534140ca8d 100644
--- a/llvm/lib/DWARFLinker/LLVM/DWARFLinkerGlobalData.h
+++ b/llvm/lib/DWARFLinker/LLVM/DWARFLinkerGlobalData.h
@@ -62,7 +62,7 @@ struct DWARFLinkerOptions {
   SmallVector<DWARFLinker::AccelTableKind, 1> AccelTables;
 
   /// Prepend path for the clang modules.
-  std::string PrependPath;
+  StringRef PrependPath;
 
   /// input verification handler(it might be called asynchronously).
   DWARFLinker::InputVerificationHandlerTy InputVerificationHandler = nullptr;
diff --git a/llvm/lib/DWARFLinker/LLVM/DWARFLinkerImpl.h b/llvm/lib/DWARFLinker/LLVM/DWARFLinkerImpl.h
index b13d2a07f98050..09957876250252 100644
--- a/llvm/lib/DWARFLinker/LLVM/DWARFLinkerImpl.h
+++ b/llvm/lib/DWARFLinker/LLVM/DWARFLinkerImpl.h
@@ -101,7 +101,7 @@ class DWARFLinkerImpl : public DWARFLinker {
   }
 
   /// Set prepend path for clang modules.
-  void setPrependPath(const std::string &Ppath) override {
+  void setPrependPath(StringRef Ppath) override {
     GlobalData.Options.PrependPath = Ppath;
   }
 

>From 4d71aa894ec305985d1f3526745578c660fe12a7 Mon Sep 17 00:00:00 2001
From: Alexey Lapshin <a.v.lapshin at mail.ru>
Date: Tue, 2 Jan 2024 16:29:18 +0300
Subject: [PATCH 3/3] addressed comments(changed comment spelling, replaced
 member variable StringRef -> std::string).

---
 llvm/include/llvm/DWARFLinker/Apple/DWARFLinker.h | 2 +-
 llvm/include/llvm/DWARFLinker/DWARFLinkerBase.h   | 2 +-
 llvm/lib/DWARFLinker/LLVM/DWARFLinkerGlobalData.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/include/llvm/DWARFLinker/Apple/DWARFLinker.h b/llvm/include/llvm/DWARFLinker/Apple/DWARFLinker.h
index b743c75339d7f4..b5815be8829962 100644
--- a/llvm/include/llvm/DWARFLinker/Apple/DWARFLinker.h
+++ b/llvm/include/llvm/DWARFLinker/Apple/DWARFLinker.h
@@ -842,7 +842,7 @@ class DWARFLinker : public DWARFLinkerBase {
     SmallVector<AccelTableKind, 1> AccelTables;
 
     /// Prepend path for the clang modules.
-    StringRef PrependPath;
+    std::string PrependPath;
 
     // input verification handler
     InputVerificationHandlerTy InputVerificationHandler = nullptr;
diff --git a/llvm/include/llvm/DWARFLinker/DWARFLinkerBase.h b/llvm/include/llvm/DWARFLinker/DWARFLinkerBase.h
index e7394ce90a9af2..ac3ab942c3cd11 100644
--- a/llvm/include/llvm/DWARFLinker/DWARFLinkerBase.h
+++ b/llvm/include/llvm/DWARFLinker/DWARFLinkerBase.h
@@ -85,7 +85,7 @@ class DWARFLinkerBase {
   virtual void setPrependPath(StringRef Ppath) = 0;
   /// Set estimated objects files amount, for preliminary data allocation.
   virtual void setEstimatedObjfilesAmount(unsigned ObjFilesNum) = 0;
-  /// Set verification handler which used to report verification errors.
+  /// Set verification handler used to report verification errors.
   virtual void
   setInputVerificationHandler(InputVerificationHandlerTy Handler) = 0;
   /// Set map for Swift interfaces.
diff --git a/llvm/lib/DWARFLinker/LLVM/DWARFLinkerGlobalData.h b/llvm/lib/DWARFLinker/LLVM/DWARFLinkerGlobalData.h
index 8305534140ca8d..656e49af1a19a7 100644
--- a/llvm/lib/DWARFLinker/LLVM/DWARFLinkerGlobalData.h
+++ b/llvm/lib/DWARFLinker/LLVM/DWARFLinkerGlobalData.h
@@ -62,7 +62,7 @@ struct DWARFLinkerOptions {
   SmallVector<DWARFLinker::AccelTableKind, 1> AccelTables;
 
   /// Prepend path for the clang modules.
-  StringRef PrependPath;
+  std::string PrependPath;
 
   /// input verification handler(it might be called asynchronously).
   DWARFLinker::InputVerificationHandlerTy InputVerificationHandler = nullptr;



More information about the llvm-commits mailing list