[llvm] [llvm-dwp] Replace MCStreamer with direct ELF writer for zero-copy output (PR #192112)

via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 16 14:46:39 PDT 2026


================
@@ -28,6 +29,88 @@ enum Dwarf64StrOffsetsPromotion {
   Always,   ///< Always emit .debug_str_offsets talbes as DWARF64 for testing.
 };
 
+/// Section identifiers for DWP output.
+enum DWPSectionId : unsigned {
+  DS_Info,
+  DS_Types,
+  DS_Abbrev,
+  DS_Line,
+  DS_Loc,
+  DS_Loclists,
+  DS_Rnglists,
+  DS_Macro,
+  DS_Str,
+  DS_StrOffsets,
+  DS_CUIndex,
+  DS_TUIndex,
+  DS_NumSections
+};
+
+/// Direct ELF writer for DWP output, bypassing MCStreamer.
+///
+/// Section data is stored as zero-copy StringRef chunks pointing to the
+/// mmap'd input files, plus an inline buffer for constructed data
+/// (emitIntValue). This avoids copying gigabytes of debug section data
+/// through the MC infrastructure (MCContext, MCAssembler, MCDataFragment
+/// allocation, layout, etc.).
+class LLVM_ABI DWPWriter {
+  /// Per-section storage: zero-copy chunks + inline buffer for small writes.
+  struct SectionData {
+    SmallVector<StringRef, 4> Chunks; // zero-copy refs to input data
+    SmallVector<char, 0> Buffer;      // for emitIntValue / constructed data
+
+    uint64_t totalSize() const {
+      uint64_t Size = 0;
+      for (auto &C : Chunks)
+        Size += C.size();
+      Size += Buffer.size();
+      return Size;
+    }
+
+    bool empty() const { return Chunks.empty() && Buffer.empty(); }
+
+    void writeTo(raw_ostream &OS) const {
+      for (auto &C : Chunks)
----------------
lakechd wrote:

error handling

https://github.com/llvm/llvm-project/pull/192112


More information about the llvm-commits mailing list