diff --git a/llvm/lib/MC/MCParser/WasmAsmParser.cpp b/llvm/lib/MC/MCParser/WasmAsmParser.cpp --- a/llvm/lib/MC/MCParser/WasmAsmParser.cpp +++ b/llvm/lib/MC/MCParser/WasmAsmParser.cpp @@ -185,7 +185,6 @@ "Only data sections can be passive"); WS->setPassive(); } - getStreamer().SwitchSection(WS); return false; } diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp --- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp +++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp @@ -971,23 +971,21 @@ auto SymName = Symbol->getName(); if (SymName.startswith(".L")) return; // Local Symbol. + // Only create a new text section if we're already in one. + // TODO: If the user explicitly creates a new function section, we ignore + // its name when we create this one. It would be nice to honor their + // choice, while still ensuring that we create one if they forget. + // (that requires coordination with WasmAsmParser::parseSectionDirective) auto CWS = cast(getStreamer().getCurrentSection().first); if (!CWS || !CWS->getKind().isText()) return; auto SecName = ".text." + SymName; - MCSectionWasm *WS = CWS; - if (cast(Symbol)->isComdat()) { - // If the function is a comdat function, then the user must have already - // declared the section as such (because that's the only way the asm - // parser can tell). In that case, just use the current section. - assert(CWS->getGroup() && - "Current section for comdat function has no group"); - } else { - WS = getContext().getWasmSection(SecName, SectionKind::getText()); - getStreamer().SwitchSection(WS); - } + auto WS = getContext().getWasmSection(SecName, SectionKind::getText(), + CWS->getGroup(), + MCContext::GenericSectionID, nullptr); + getStreamer().SwitchSection(WS); // Also generate DWARF for this section if requested. if (getContext().getGenDwarfForAssembly()) getContext().addGenDwarfSection(WS); diff --git a/llvm/test/MC/WebAssembly/comdat-sections.s b/llvm/test/MC/WebAssembly/comdat-sections.s --- a/llvm/test/MC/WebAssembly/comdat-sections.s +++ b/llvm/test/MC/WebAssembly/comdat-sections.s @@ -7,12 +7,22 @@ .functype foo () -> () return end_function + + .globl bar + .type bar,@function +bar: + .functype bar () -> () + return + end_function + .section .debug_foo,"G",@,abc123,comdat .int32 42 .section .debug_foo,"G",@,duplicate,comdat .int64 234 + + # Check that there are 2 identically-named custom sections, with the desired # contents # CHECK: - Type: CUSTOM @@ -31,6 +41,11 @@ # CHECK-NEXT: Entries: # CHECK-NEXT: - Kind: FUNCTION # CHECK-NEXT: Index: 0 + +# If the user forgets to create a new section for a function, one is created for +# them by the assembler. Check that it is also in the same group. +# CHECK-NEXT: - Kind: FUNCTION +# CHECK-NEXT: Index: 1 # CHECK-NEXT: - Kind: SECTION # CHECK-NEXT: Index: 4 # CHECK-NEXT: - Name: duplicate