Skip to content

Commit 0ff28fa

Browse files
committed
Support dwarf fission for wasm object files
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. It also splits the import-preparation step into its own function (and skips it when writing a dwo). Differential Revision: https://reviews.llvm.org/D85685
1 parent a0017c2 commit 0ff28fa

File tree

9 files changed

+436
-145
lines changed

9 files changed

+436
-145
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4805,7 +4805,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
48054805
// Add the split debug info name to the command lines here so we
48064806
// can propagate it to the backend.
48074807
bool SplitDWARF = (DwarfFission != DwarfFissionKind::None) &&
4808-
TC.getTriple().isOSBinFormatELF() &&
4808+
(TC.getTriple().isOSBinFormatELF() ||
4809+
TC.getTriple().isOSBinFormatWasm()) &&
48094810
(isa<AssembleJobAction>(JA) || isa<CompileJobAction>(JA) ||
48104811
isa<BackendJobAction>(JA));
48114812
if (SplitDWARF) {

clang/test/Driver/split-debug.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
// RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf=split -c -### %s 2> %t
1111
// RUN: FileCheck -check-prefix=CHECK-ACTIONS < %t %s
1212

13+
// RUN: %clang -target wasm32-unknown-unknown -gsplit-dwarf -c -### %s 2> %t
14+
// RUN: FileCheck -check-prefix=CHECK-ACTIONS < %t %s
15+
// RUN: %clang -target wasm32-unknown-unknown -gsplit-dwarf=split -c -### %s 2> %t
16+
// RUN: FileCheck -check-prefix=CHECK-ACTIONS < %t %s
17+
1318
// RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf=single -c -### %s 2> %t
1419
// RUN: FileCheck -check-prefix=CHECK-ACTIONS-SINGLE-SPLIT < %t %s
1520
//

llvm/include/llvm/MC/MCWasmObjectWriter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ std::unique_ptr<MCObjectWriter>
5252
createWasmObjectWriter(std::unique_ptr<MCWasmObjectTargetWriter> MOTW,
5353
raw_pwrite_stream &OS);
5454

55+
std::unique_ptr<MCObjectWriter>
56+
createWasmDwoObjectWriter(std::unique_ptr<MCWasmObjectTargetWriter> MOTW,
57+
raw_pwrite_stream &OS, raw_pwrite_stream &DwoOS);
58+
5559
} // namespace llvm
5660

5761
#endif

llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,10 @@ DIE &DwarfCompileUnit::updateSubprogramScopeDIE(const DISubprogram *SP) {
422422
// FIXME: duplicated from Target/WebAssembly/WebAssembly.h
423423
// don't want to depend on target specific headers in this code?
424424
const unsigned TI_GLOBAL_RELOC = 3;
425-
if (FrameBase.Location.WasmLoc.Kind == TI_GLOBAL_RELOC) {
425+
// FIXME: when writing dwo, we need to avoid relocations. Probably
426+
// the "right" solution is to treat globals the way func and data symbols
427+
// are (with entries in .debug_addr).
428+
if (FrameBase.Location.WasmLoc.Kind == TI_GLOBAL_RELOC && !isDwoUnit()) {
426429
// These need to be relocatable.
427430
assert(FrameBase.Location.WasmLoc.Index == 0); // Only SP so far.
428431
auto SPSym = cast<MCSymbolWasm>(

llvm/lib/MC/MCAsmBackend.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,17 @@ std::unique_ptr<MCObjectWriter>
5454
MCAsmBackend::createDwoObjectWriter(raw_pwrite_stream &OS,
5555
raw_pwrite_stream &DwoOS) const {
5656
auto TW = createObjectTargetWriter();
57-
if (TW->getFormat() != Triple::ELF)
58-
report_fatal_error("dwo only supported with ELF");
59-
return createELFDwoObjectWriter(cast<MCELFObjectTargetWriter>(std::move(TW)),
60-
OS, DwoOS, Endian == support::little);
57+
switch (TW->getFormat()) {
58+
case Triple::ELF:
59+
return createELFDwoObjectWriter(
60+
cast<MCELFObjectTargetWriter>(std::move(TW)), OS, DwoOS,
61+
Endian == support::little);
62+
case Triple::Wasm:
63+
return createWasmDwoObjectWriter(
64+
cast<MCWasmObjectTargetWriter>(std::move(TW)), OS, DwoOS);
65+
default:
66+
report_fatal_error("dwo only supported with ELF and Wasm");
67+
}
6168
}
6269

6370
Optional<MCFixupKind> MCAsmBackend::getFixupKind(StringRef Name) const {

llvm/lib/MC/MCObjectFileInfo.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,10 @@ void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) {
796796
DwarfFrameSection = Ctx->getWasmSection(".debug_frame", SectionKind::getMetadata());
797797
DwarfPubNamesSection = Ctx->getWasmSection(".debug_pubnames", SectionKind::getMetadata());
798798
DwarfPubTypesSection = Ctx->getWasmSection(".debug_pubtypes", SectionKind::getMetadata());
799+
DwarfGnuPubNamesSection =
800+
Ctx->getWasmSection(".debug_gnu_pubnames", SectionKind::getMetadata());
801+
DwarfGnuPubTypesSection =
802+
Ctx->getWasmSection(".debug_gnu_pubtypes", SectionKind::getMetadata());
799803

800804
DwarfDebugNamesSection =
801805
Ctx->getWasmSection(".debug_names", SectionKind::getMetadata());
@@ -808,6 +812,37 @@ void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) {
808812
DwarfLoclistsSection =
809813
Ctx->getWasmSection(".debug_loclists", SectionKind::getMetadata());
810814

815+
// Fission Sections
816+
DwarfInfoDWOSection =
817+
Ctx->getWasmSection(".debug_info.dwo", SectionKind::getMetadata());
818+
DwarfTypesDWOSection =
819+
Ctx->getWasmSection(".debug_types.dwo", SectionKind::getMetadata());
820+
DwarfAbbrevDWOSection =
821+
Ctx->getWasmSection(".debug_abbrev.dwo", SectionKind::getMetadata());
822+
DwarfStrDWOSection =
823+
Ctx->getWasmSection(".debug_str.dwo", SectionKind::getMetadata());
824+
DwarfLineDWOSection =
825+
Ctx->getWasmSection(".debug_line.dwo", SectionKind::getMetadata());
826+
DwarfLocDWOSection =
827+
Ctx->getWasmSection(".debug_loc.dwo", SectionKind::getMetadata());
828+
DwarfStrOffDWOSection =
829+
Ctx->getWasmSection(".debug_str_offsets.dwo", SectionKind::getMetadata());
830+
DwarfRnglistsDWOSection =
831+
Ctx->getWasmSection(".debug_rnglists.dwo", SectionKind::getMetadata());
832+
DwarfMacinfoDWOSection =
833+
Ctx->getWasmSection(".debug_macinfo.dwo", SectionKind::getMetadata());
834+
DwarfMacroDWOSection =
835+
Ctx->getWasmSection(".debug_macro.dwo", SectionKind::getMetadata());
836+
837+
DwarfLoclistsDWOSection =
838+
Ctx->getWasmSection(".debug_loclists.dwo", SectionKind::getMetadata());
839+
840+
// DWP Sections
841+
DwarfCUIndexSection =
842+
Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata(), 0);
843+
DwarfTUIndexSection =
844+
Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata(), 0);
845+
811846
// Wasm use data section for LSDA.
812847
// TODO Consider putting each function's exception table in a separate
813848
// section, as in -function-sections, to facilitate lld's --gc-section.

0 commit comments

Comments
 (0)