Index: llvm/lib/MC/MCParser/WasmAsmParser.cpp =================================================================== --- llvm/lib/MC/MCParser/WasmAsmParser.cpp +++ llvm/lib/MC/MCParser/WasmAsmParser.cpp @@ -33,6 +33,7 @@ class WasmAsmParser : public MCAsmParserExtension { MCAsmParser *Parser = nullptr; MCAsmLexer *Lexer = nullptr; + size_t AnonymousDataSections = 0; template void addDirectiveHandler(StringRef Directive) { @@ -52,6 +53,7 @@ this->MCAsmParserExtension::Initialize(*Parser); addDirectiveHandler<&WasmAsmParser::parseSectionDirectiveText>(".text"); + addDirectiveHandler<&WasmAsmParser::parseSectionDirectiveData>(".data"); addDirectiveHandler<&WasmAsmParser::parseSectionDirective>(".section"); addDirectiveHandler<&WasmAsmParser::parseDirectiveSize>(".size"); addDirectiveHandler<&WasmAsmParser::parseDirectiveType>(".type"); @@ -89,6 +91,14 @@ return false; } + bool parseSectionDirectiveData(StringRef, SMLoc) { + auto Name = ".data." + std::to_string(AnonymousDataSections); + auto *WS = getContext().getWasmSection( + Name, SectionKind::getData(), 0, "", MCContext::GenericSectionID); + getStreamer().SwitchSection(WS); + return false; + } + uint32_t parseSectionFlags(StringRef FlagStr, bool &Passive, bool &Group) { uint32_t flags = 0; for (char C : FlagStr) { Index: llvm/test/MC/WebAssembly/basic-assembly.s =================================================================== --- llvm/test/MC/WebAssembly/basic-assembly.s +++ llvm/test/MC/WebAssembly/basic-assembly.s @@ -137,6 +137,9 @@ .int32 2000000000 .size .L.str, 28 + .data + .int8 73 + .section .init_array.42,"",@ .p2align 2 .int32 test0 @@ -272,6 +275,10 @@ # CHECK-NEXT: .int32 2000000000 # CHECK-NEXT: .size .L.str, 28 +# CHECK: .section .data.0,"",@ +# CHECK-EMPTY: +# CHECK-NEXT: .int8 73 + # CHECK: .section .init_array.42,"",@ # CHECK-NEXT: .p2align 2 # CHECK-NEXT: .int32 test0