dschuff created this revision.
dschuff added reviewers: sbc100, aardappel.
Herald added subscribers: llvm-commits, cfe-commits, sunfish, hiraditya, 
aprantl.
Herald added projects: clang, LLVM.
dschuff requested review of this revision.
Herald added a subscriber: aheejin.

Initial support for dwarf fission sections (-gsplit-dwarf) on wasm.
The most interesting change is support for writing 2 files (.o and .dwo) in the
wasm object writer. My approach moves object-writing logic into its own function
and calls it twice, swapping out the endian::Writer (W) in between calls.
(This is a bit different than the ELF writer's approach. I like it a bit better
but don't have a strong opinion).

This patch has the basic structure and writes separate files containing
non-dwo and dwo sections. There are couple of other things needed:

1. Linker support for an equivalent of ELF's SHF_EXCLUDE to keep the debug 
sections from being linked
2. a few checks and validations (equivalent to the places where the ELF object 
writer checks the dwo mode, such as validating relocs)

These can go in future CLs, but I still need to add some tests to this one.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85685

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  llvm/lib/MC/MCAsmBackend.cpp
  llvm/lib/MC/MCObjectFileInfo.cpp
  llvm/lib/MC/WasmObjectWriter.cpp

Index: llvm/lib/MC/WasmObjectWriter.cpp
===================================================================
--- llvm/lib/MC/WasmObjectWriter.cpp
+++ llvm/lib/MC/WasmObjectWriter.cpp
@@ -270,8 +270,8 @@
     DwoOnly,
   };
   bool IsSplitDwarf = false;
-  raw_pwrite_stream* OS = nullptr;
-  raw_pwrite_stream* DwoOS = nullptr;
+  raw_pwrite_stream *OS = nullptr;
+  raw_pwrite_stream *DwoOS = nullptr;
 
   // TargetObjectWriter wranppers.
   bool is64Bit() const { return TargetObjectWriter->is64Bit(); }
@@ -287,9 +287,8 @@
       : TargetObjectWriter(std::move(MOTW)), OS(&OS_) {}
   WasmObjectWriter(std::unique_ptr<MCWasmObjectTargetWriter> MOTW,
                    raw_pwrite_stream &OS_, raw_pwrite_stream &DwoOS_)
-      : TargetObjectWriter(std::move(MOTW)),
-        IsSplitDwarf(true), OS(&OS_), DwoOS(&DwoOS_) {}
-
+      : TargetObjectWriter(std::move(MOTW)), IsSplitDwarf(true), OS(&OS_),
+        DwoOS(&DwoOS_) {}
 
 private:
   void reset() override {
@@ -324,8 +323,8 @@
 
   uint64_t writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) override;
 
-  uint64_t writeOneObject(MCAssembler &Asm, const MCAsmLayout &Layout, DwoMode Mode);
-
+  uint64_t writeOneObject(MCAssembler &Asm, const MCAsmLayout &Layout,
+                          DwoMode Mode);
 
   void writeString(const StringRef Str) {
     encodeULEB128(Str.size(), W->OS);
@@ -781,7 +780,7 @@
       break;
     case wasm::WASM_EXTERNAL_MEMORY:
       encodeULEB128(Import.Memory.Flags, W->OS);
-      encodeULEB128(NumPages, W->OS);  // initial
+      encodeULEB128(NumPages, W->OS); // initial
       break;
     case wasm::WASM_EXTERNAL_TABLE:
       W->OS << char(Import.Table.ElemType);
@@ -961,8 +960,8 @@
       encodeULEB128(0, W->OS); // memory index
     if ((Segment.InitFlags & wasm::WASM_SEGMENT_IS_PASSIVE) == 0) {
       W->OS << char(Segment.Offset > std::numeric_limits<int32_t>().max()
-                     ? wasm::WASM_OPCODE_I64_CONST
-                     : wasm::WASM_OPCODE_I32_CONST);
+                        ? wasm::WASM_OPCODE_I64_CONST
+                        : wasm::WASM_OPCODE_I32_CONST);
       encodeSLEB128(Segment.Offset, W->OS); // offset
       W->OS << char(wasm::WASM_OPCODE_END);
     }
@@ -1771,6 +1770,7 @@
 
 std::unique_ptr<MCObjectWriter>
 llvm::createWasmDwoObjectWriter(std::unique_ptr<MCWasmObjectTargetWriter> MOTW,
-                                raw_pwrite_stream &OS, raw_pwrite_stream &DwoOS) {
+                                raw_pwrite_stream &OS,
+                                raw_pwrite_stream &DwoOS) {
   return std::make_unique<WasmObjectWriter>(std::move(MOTW), OS);
 }
Index: llvm/lib/MC/MCObjectFileInfo.cpp
===================================================================
--- llvm/lib/MC/MCObjectFileInfo.cpp
+++ llvm/lib/MC/MCObjectFileInfo.cpp
@@ -796,8 +796,10 @@
   DwarfFrameSection = Ctx->getWasmSection(".debug_frame", SectionKind::getMetadata());
   DwarfPubNamesSection = Ctx->getWasmSection(".debug_pubnames", SectionKind::getMetadata());
   DwarfPubTypesSection = Ctx->getWasmSection(".debug_pubtypes", SectionKind::getMetadata());
-  DwarfGnuPubNamesSection = Ctx->getWasmSection(".debug_gnu_pubnames", SectionKind::getMetadata());
-  DwarfGnuPubTypesSection = Ctx->getWasmSection(".debug_gnu_pubtypes", SectionKind::getMetadata());
+  DwarfGnuPubNamesSection =
+      Ctx->getWasmSection(".debug_gnu_pubnames", SectionKind::getMetadata());
+  DwarfGnuPubTypesSection =
+      Ctx->getWasmSection(".debug_gnu_pubtypes", SectionKind::getMetadata());
 
   DwarfDebugNamesSection =
       Ctx->getWasmSection(".debug_names", SectionKind::getMetadata());
@@ -817,15 +819,15 @@
       Ctx->getWasmSection(".debug_types.dwo", SectionKind::getMetadata());
   DwarfAbbrevDWOSection =
       Ctx->getWasmSection(".debug_abbrev.dwo", SectionKind::getMetadata());
-  DwarfStrDWOSection = Ctx->getWasmSection(
-      ".debug_str.dwo", SectionKind::getMetadata());
-                       //ELF::SHF_MERGE | ELF::SHF_STRINGS | ELF::SHF_EXCLUDE, 1, "");
+  DwarfStrDWOSection =
+      Ctx->getWasmSection(".debug_str.dwo", SectionKind::getMetadata());
+  // ELF::SHF_MERGE | ELF::SHF_STRINGS | ELF::SHF_EXCLUDE, 1, "");
   DwarfLineDWOSection =
       Ctx->getWasmSection(".debug_line.dwo", SectionKind::getMetadata());
   DwarfLocDWOSection =
       Ctx->getWasmSection(".debug_loc.dwo", SectionKind::getMetadata());
-  DwarfStrOffDWOSection = Ctx->getWasmSection(".debug_str_offsets.dwo",
-                                             SectionKind::getMetadata());
+  DwarfStrOffDWOSection =
+      Ctx->getWasmSection(".debug_str_offsets.dwo", SectionKind::getMetadata());
   DwarfRnglistsDWOSection =
       Ctx->getWasmSection(".debug_rnglists.dwo", SectionKind::getMetadata());
   DwarfMacinfoDWOSection =
@@ -842,7 +844,6 @@
   DwarfTUIndexSection =
       Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata(), 0);
 
-
   // Wasm use data section for LSDA.
   // TODO Consider putting each function's exception table in a separate
   // section, as in -function-sections, to facilitate lld's --gc-section.
Index: llvm/lib/MC/MCAsmBackend.cpp
===================================================================
--- llvm/lib/MC/MCAsmBackend.cpp
+++ llvm/lib/MC/MCAsmBackend.cpp
@@ -55,16 +55,16 @@
                                     raw_pwrite_stream &DwoOS) const {
   auto TW = createObjectTargetWriter();
   switch (TW->getFormat()) {
-    case Triple::ELF:
-      return createELFDwoObjectWriter(cast<MCELFObjectTargetWriter>(std::move(TW)),
-                                  OS, DwoOS, Endian == support::little);
-    case Triple::Wasm:
-      return createWasmDwoObjectWriter(cast<MCWasmObjectTargetWriter>(std::move(TW)),
-                                       OS, DwoOS);
-    default:
-      report_fatal_error("dwo only supported with ELF");
+  case Triple::ELF:
+    return createELFDwoObjectWriter(
+        cast<MCELFObjectTargetWriter>(std::move(TW)), OS, DwoOS,
+        Endian == support::little);
+  case Triple::Wasm:
+    return createWasmDwoObjectWriter(
+        cast<MCWasmObjectTargetWriter>(std::move(TW)), OS, DwoOS);
+  default:
+    report_fatal_error("dwo only supported with ELF");
   }
-
 }
 
 Optional<MCFixupKind> MCAsmBackend::getFixupKind(StringRef Name) const {
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4765,7 +4765,8 @@
   // Add the split debug info name to the command lines here so we
   // can propagate it to the backend.
   bool SplitDWARF = (DwarfFission != DwarfFissionKind::None) &&
-                    (TC.getTriple().isOSBinFormatELF() || TC.getTriple().isOSBinFormatWasm()) &&
+                    (TC.getTriple().isOSBinFormatELF() ||
+                     TC.getTriple().isOSBinFormatWasm()) &&
                     (isa<AssembleJobAction>(JA) || isa<CompileJobAction>(JA) ||
                      isa<BackendJobAction>(JA));
   if (SplitDWARF) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D85685: [WI... Derek Schuff via Phabricator via cfe-commits

Reply via email to