diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -3989,7 +3989,7 @@ if (Args.hasFlag(options::OPT_fdebug_types_section, options::OPT_fno_debug_types_section, false)) { - if (!T.isOSBinFormatELF()) { + if (!(T.isOSBinFormatELF() || T.isOSBinFormatWasm())) { D.Diag(diag::err_drv_unsupported_opt_for_target) << Args.getLastArg(options::OPT_fdebug_types_section) ->getAsString(Args) diff --git a/clang/test/Driver/debug-options.c b/clang/test/Driver/debug-options.c --- a/clang/test/Driver/debug-options.c +++ b/clang/test/Driver/debug-options.c @@ -214,6 +214,9 @@ // RUN: %clang -### -fdebug-types-section -fno-debug-types-section -target x86_64-unknown-linux %s 2>&1 \ // RUN: | FileCheck -check-prefix=NOFDTS %s // +// RUN: %clang -### -fdebug-types-section -target wasm32-unknown-unknown %s 2>&1 \ +// RUN: | FileCheck -check-prefix=FDTS %s +// // RUN: %clang -### -fdebug-types-section -target x86_64-apple-darwin %s 2>&1 \ // RUN: | FileCheck -check-prefix=FDTSE %s // diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -394,8 +394,9 @@ UseSectionsAsReferences = DwarfSectionsAsReferences == Enable; // Don't generate type units for unsupported object file formats. - GenerateTypeUnits = - A->TM.getTargetTriple().isOSBinFormatELF() && GenerateDwarfTypeUnits; + GenerateTypeUnits = (A->TM.getTargetTriple().isOSBinFormatELF() || + A->TM.getTargetTriple().isOSBinFormatWasm()) && + GenerateDwarfTypeUnits; TheAccelTableKind = computeAccelTableKind( DwarfVersion, GenerateTypeUnits, DebuggerTuning, A->TM.getTargetTriple()); diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp --- a/llvm/lib/MC/MCContext.cpp +++ b/llvm/lib/MC/MCContext.cpp @@ -644,7 +644,7 @@ StringRef CachedName = Entry.first.SectionName; - MCSymbol *Begin = createSymbol(CachedName, false, false); + MCSymbol *Begin = getOrCreateSymbol(CachedName); cast(Begin)->setType(wasm::WASM_SYMBOL_TYPE_SECTION); MCSectionWasm *Result = new (WasmAllocator.Allocate()) diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp --- a/llvm/lib/MC/MCObjectFileInfo.cpp +++ b/llvm/lib/MC/MCObjectFileInfo.cpp @@ -963,9 +963,11 @@ case Triple::ELF: return Ctx->getELFSection(Name, ELF::SHT_PROGBITS, ELF::SHF_GROUP, 0, utostr(Hash)); + case Triple::Wasm: + return Ctx->getWasmSection(Name, SectionKind::getMetadata(), utostr(Hash), + MCContext::GenericSectionID); case Triple::MachO: case Triple::COFF: - case Triple::Wasm: case Triple::GOFF: case Triple::XCOFF: case Triple::UnknownObjectFormat: diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp --- a/llvm/lib/MC/WasmObjectWriter.cpp +++ b/llvm/lib/MC/WasmObjectWriter.cpp @@ -1378,9 +1378,6 @@ MCSymbol *Begin = Sec.getBeginSymbol(); if (Begin) { WasmIndices[cast(Begin)] = CustomSections.size(); - if (SectionName != Begin->getName()) - report_fatal_error("section name and begin symbol should match: " + - Twine(SectionName)); } // Separate out the producers and target features sections