diff --git a/llvm/include/llvm/Object/Wasm.h b/llvm/include/llvm/Object/Wasm.h --- a/llvm/include/llvm/Object/Wasm.h +++ b/llvm/include/llvm/Object/Wasm.h @@ -247,6 +247,7 @@ Error parseElemSection(ReadContext &Ctx); Error parseCodeSection(ReadContext &Ctx); Error parseDataSection(ReadContext &Ctx); + Error parseDataCountSection(ReadContext &Ctx); // Custom section types Error parseDylinkSection(ReadContext &Ctx); @@ -273,6 +274,7 @@ std::vector Exports; std::vector ElemSegments; std::vector DataSegments; + llvm::Optional DataCount; std::vector Functions; std::vector Symbols; std::vector DebugNames; diff --git a/llvm/include/llvm/ObjectYAML/WasmYAML.h b/llvm/include/llvm/ObjectYAML/WasmYAML.h --- a/llvm/include/llvm/ObjectYAML/WasmYAML.h +++ b/llvm/include/llvm/ObjectYAML/WasmYAML.h @@ -379,6 +379,16 @@ std::vector Segments; }; +struct DataCountSection : Section { + DataCountSection() : Section(wasm::WASM_SEC_DATACOUNT) {} + + static bool classof(const Section *S) { + return S->Type == wasm::WASM_SEC_DATACOUNT; + } + + uint32_t Count; +}; + struct Object { FileHeader Header; std::vector> Sections; 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 @@ -326,6 +326,7 @@ void writeFunctionSection(ArrayRef Functions); void writeExportSection(ArrayRef Exports); void writeElemSection(ArrayRef TableElems); + void writeDataCountSection(); void writeCodeSection(const MCAssembler &Asm, const MCAsmLayout &Layout, ArrayRef Functions); void writeDataSection(); @@ -849,6 +850,16 @@ endSection(Section); } +void WasmObjectWriter::writeDataCountSection() { + if (DataSegments.empty()) + return; + + SectionBookkeeping Section; + startSection(Section, wasm::WASM_SEC_DATACOUNT); + encodeULEB128(DataSegments.size(), W.OS); + endSection(Section); +} + void WasmObjectWriter::writeCodeSection(const MCAssembler &Asm, const MCAsmLayout &Layout, ArrayRef Functions) { @@ -1600,6 +1611,7 @@ writeEventSection(Events); writeExportSection(Exports); writeElemSection(TableElems); + writeDataCountSection(); writeCodeSection(Asm, Layout, Functions); writeDataSection(); for (auto &CustomSection : CustomSections) diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -316,6 +316,8 @@ return parseCodeSection(Ctx); case wasm::WASM_SEC_DATA: return parseDataSection(Ctx); + case wasm::WASM_SEC_DATACOUNT: + return parseDataCountSection(Ctx); default: return make_error("Bad section type", object_error::parse_failed); @@ -1201,6 +1203,9 @@ Error WasmObjectFile::parseDataSection(ReadContext &Ctx) { DataSection = Sections.size(); uint32_t Count = readVaruint32(Ctx); + if (DataCount && Count != DataCount.getValue()) + return make_error( + "Number of data segments does not match DataCount section"); DataSegments.reserve(Count); while (Count--) { WasmSegment Segment; @@ -1234,6 +1239,11 @@ return Error::success(); } +Error WasmObjectFile::parseDataCountSection(ReadContext &Ctx) { + DataCount = readVaruint32(Ctx); + return Error::success(); +} + const wasm::WasmObjectHeader &WasmObjectFile::getHeader() const { return Header; } @@ -1399,6 +1409,7 @@ ECase(ELEM); ECase(CODE); ECase(DATA); + ECase(DATACOUNT); case wasm::WASM_SEC_CUSTOM: Res = S.Name; break; diff --git a/llvm/lib/ObjectYAML/WasmYAML.cpp b/llvm/lib/ObjectYAML/WasmYAML.cpp --- a/llvm/lib/ObjectYAML/WasmYAML.cpp +++ b/llvm/lib/ObjectYAML/WasmYAML.cpp @@ -153,6 +153,11 @@ IO.mapRequired("Segments", Section.Segments); } +static void sectionMapping(IO &IO, WasmYAML::DataCountSection &Section) { + commonSectionMapping(IO, Section); + IO.mapRequired("Count", Section.Count); +} + void MappingTraits>::mapping( IO &IO, std::unique_ptr &Section) { WasmYAML::SectionType SectionType; @@ -257,6 +262,11 @@ Section.reset(new WasmYAML::DataSection()); sectionMapping(IO, *cast(Section.get())); break; + case wasm::WASM_SEC_DATACOUNT: + if (!IO.outputting()) + Section.reset(new WasmYAML::DataCountSection()); + sectionMapping(IO, *cast(Section.get())); + break; default: llvm_unreachable("Unknown section type"); } @@ -278,6 +288,7 @@ ECase(ELEM); ECase(CODE); ECase(DATA); + ECase(DATACOUNT); #undef ECase } diff --git a/llvm/test/MC/WebAssembly/bss.ll b/llvm/test/MC/WebAssembly/bss.ll --- a/llvm/test/MC/WebAssembly/bss.ll +++ b/llvm/test/MC/WebAssembly/bss.ll @@ -9,7 +9,7 @@ @foo = global %union.u1 zeroinitializer, align 1 @bar = global %union.u1 zeroinitializer, align 1 -; CHECK: - Type: DATA +; CHECK: - Type: DATA{{$}} ; CHECK-NEXT: Segments: ; CHECK-NEXT: - SectionOffset: 6 ; CHECK-NEXT: InitFlags: 0 diff --git a/llvm/test/MC/WebAssembly/comdat.ll b/llvm/test/MC/WebAssembly/comdat.ll --- a/llvm/test/MC/WebAssembly/comdat.ll +++ b/llvm/test/MC/WebAssembly/comdat.ll @@ -50,6 +50,8 @@ ; CHECK-NEXT: SigIndex: 0 ; CHECK-NEXT: - Type: FUNCTION ; CHECK-NEXT: FunctionTypes: [ 0, 0, 0 ] +; CHECK-NEXT: - Type: DATACOUNT +; CHECK-NEXT: Count: 1 ; CHECK-NEXT: - Type: CODE ; CHECK-NEXT: Relocations: ; CHECK-NEXT: - Type: R_WASM_FUNCTION_INDEX_LEB diff --git a/llvm/test/MC/WebAssembly/data-section.s b/llvm/test/MC/WebAssembly/data-section.s --- a/llvm/test/MC/WebAssembly/data-section.s +++ b/llvm/test/MC/WebAssembly/data-section.s @@ -53,6 +53,8 @@ # BIN-NEXT: Initial: 0x00000000 # BIN-NEXT: - Type: FUNCTION # BIN-NEXT: FunctionTypes: [ 0 ] +# BIN-NEXT: - Type: DATACOUNT +# BIN-NEXT: Count: 1 # BIN-NEXT: - Type: CODE # BIN-NEXT: Relocations: # BIN-NEXT: - Type: R_WASM_MEMORY_ADDR_SLEB @@ -91,4 +93,3 @@ # BIN-NEXT: Alignment: 0 # BIN-NEXT: Flags: [ ] # BIN-NEXT: ... - diff --git a/llvm/test/MC/WebAssembly/debug-info.ll b/llvm/test/MC/WebAssembly/debug-info.ll --- a/llvm/test/MC/WebAssembly/debug-info.ll +++ b/llvm/test/MC/WebAssembly/debug-info.ll @@ -25,14 +25,19 @@ ; CHECK-NEXT: Offset: 90 ; CHECK-NEXT: } ; CHECK-NEXT: Section { +; CHECK-NEXT: Type: DATACOUNT (0xC) +; CHECK-NEXT: Size: 1 +; CHECK-NEXT: Offset: 103 +; CHECK-NEXT: } +; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CODE (0xA) ; CHECK-NEXT: Size: 4 -; CHECK-NEXT: Offset: 103 +; CHECK-NEXT: Offset: 110 ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: DATA (0xB) ; CHECK-NEXT: Size: 19 -; CHECK-NEXT: Offset: 113 +; CHECK-NEXT: Offset: 120 ; CHECK-NEXT: Segments [ ; CHECK-NEXT: Segment { ; CHECK-NEXT: Name: .data.foo @@ -49,94 +54,94 @@ ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 121 -; CHECK-NEXT: Offset: 138 +; CHECK-NEXT: Offset: 145 ; CHECK-NEXT: Name: .debug_str ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 84 -; CHECK-NEXT: Offset: 276 +; CHECK-NEXT: Offset: 283 ; CHECK-NEXT: Name: .debug_abbrev ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 106 -; CHECK-NEXT: Offset: 380 +; CHECK-NEXT: Offset: 387 ; CHECK-NEXT: Name: .debug_info ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 1 -; CHECK-NEXT: Offset: 504 +; CHECK-NEXT: Offset: 511 ; CHECK-NEXT: Name: .debug_macinfo ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 42 -; CHECK-NEXT: Offset: 526 +; CHECK-NEXT: Offset: 533 ; CHECK-NEXT: Name: .debug_pubnames ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 26 -; CHECK-NEXT: Offset: 590 +; CHECK-NEXT: Offset: 597 ; CHECK-NEXT: Name: .debug_pubtypes ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 57 -; CHECK-NEXT: Offset: 638 +; CHECK-NEXT: Offset: 645 ; CHECK-NEXT: Name: .debug_line ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 88 -; CHECK-NEXT: Offset: 713 +; CHECK-NEXT: Offset: 720 ; CHECK-NEXT: Name: linking ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 9 -; CHECK-NEXT: Offset: 815 +; CHECK-NEXT: Offset: 822 ; CHECK-NEXT: Name: reloc.DATA ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 58 -; CHECK-NEXT: Offset: 841 +; CHECK-NEXT: Offset: 848 ; CHECK-NEXT: Name: reloc..debug_info ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 6 -; CHECK-NEXT: Offset: 923 +; CHECK-NEXT: Offset: 930 ; CHECK-NEXT: Name: reloc..debug_pubnames ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 6 -; CHECK-NEXT: Offset: 957 +; CHECK-NEXT: Offset: 964 ; CHECK-NEXT: Name: reloc..debug_pubtypes ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 6 -; CHECK-NEXT: Offset: 991 +; CHECK-NEXT: Offset: 998 ; CHECK-NEXT: Name: reloc..debug_line ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 77 -; CHECK-NEXT: Offset: 1021 +; CHECK-NEXT: Offset: 1028 ; CHECK-NEXT: Name: producers ; CHECK-NEXT: } ; CHECK-NEXT:] ; CHECK-NEXT:Relocations [ -; CHECK-NEXT: Section (6) DATA { +; CHECK-NEXT: Section (7) DATA { ; CHECK-NEXT: 0x6 R_WASM_MEMORY_ADDR_I32 myextern 0 ; CHECK-NEXT: 0xF R_WASM_TABLE_INDEX_I32 f2 ; CHECK-NEXT: } -; CHECK-NEXT: Section (9) .debug_info { +; CHECK-NEXT: Section (10) .debug_info { ; CHECK-NEXT: 0x6 R_WASM_SECTION_OFFSET_I32 .debug_abbrev 0 ; CHECK-NEXT: 0xC R_WASM_SECTION_OFFSET_I32 .debug_str 0 ; CHECK-NEXT: 0x12 R_WASM_SECTION_OFFSET_I32 .debug_str 55 @@ -151,13 +156,13 @@ ; CHECK-NEXT: 0x5B R_WASM_FUNCTION_OFFSET_I32 f2 0 ; CHECK-NEXT: 0x63 R_WASM_SECTION_OFFSET_I32 .debug_str 118 ; CHECK-NEXT: } -; CHECK-NEXT: Section (11) .debug_pubnames { +; CHECK-NEXT: Section (12) .debug_pubnames { ; CHECK-NEXT: 0x6 R_WASM_SECTION_OFFSET_I32 .debug_info 0 ; CHECK-NEXT: } -; CHECK-NEXT: Section (12) .debug_pubtypes { +; CHECK-NEXT: Section (13) .debug_pubtypes { ; CHECK-NEXT: 0x6 R_WASM_SECTION_OFFSET_I32 .debug_info 0 ; CHECK-NEXT: } -; CHECK-NEXT: Section (13) .debug_line { +; CHECK-NEXT: Section (14) .debug_line { ; CHECK-NEXT: 0x2B R_WASM_FUNCTION_OFFSET_I32 f2 0 ; CHECK-NEXT: } ; CHECK-NEXT:] @@ -205,7 +210,7 @@ ; CHECK-NEXT: Flags [ (0x2) ; CHECK-NEXT: BINDING_LOCAL (0x2) ; CHECK-NEXT: ] -; CHECK-NEXT: ElementIndex: 0x6 +; CHECK-NEXT: ElementIndex: 0x7 ; CHECK-NEXT: } ; CHECK-NEXT: Symbol { ; CHECK-NEXT: Name: .debug_abbrev @@ -213,7 +218,7 @@ ; CHECK-NEXT: Flags [ (0x2) ; CHECK-NEXT: BINDING_LOCAL (0x2) ; CHECK-NEXT: ] -; CHECK-NEXT: ElementIndex: 0x7 +; CHECK-NEXT: ElementIndex: 0x8 ; CHECK-NEXT: } ; CHECK-NEXT: Symbol { ; CHECK-NEXT: Name: .debug_info @@ -221,7 +226,7 @@ ; CHECK-NEXT: Flags [ (0x2) ; CHECK-NEXT: BINDING_LOCAL (0x2) ; CHECK-NEXT: ] -; CHECK-NEXT: ElementIndex: 0x8 +; CHECK-NEXT: ElementIndex: 0x9 ; CHECK-NEXT: } ; CHECK-NEXT: Symbol { ; CHECK-NEXT: Name: .debug_line @@ -229,7 +234,7 @@ ; CHECK-NEXT: Flags [ (0x2) ; CHECK-NEXT: BINDING_LOCAL (0x2) ; CHECK-NEXT: ] -; CHECK-NEXT: ElementIndex: 0xC +; CHECK-NEXT: ElementIndex: 0xD ; CHECK-NEXT: } ; CHECK-NEXT:] diff --git a/llvm/test/MC/WebAssembly/explicit-sections.ll b/llvm/test/MC/WebAssembly/explicit-sections.ll --- a/llvm/test/MC/WebAssembly/explicit-sections.ll +++ b/llvm/test/MC/WebAssembly/explicit-sections.ll @@ -10,7 +10,7 @@ @global3 = global i32 8, align 8, section ".sec2" -; CHECK: - Type: DATA +; CHECK: - Type: DATA{{$}} ; CHECK-NEXT: Segments: ; CHECK-NEXT: - SectionOffset: 6 ; CHECK-NEXT: InitFlags: 0 diff --git a/llvm/test/MC/WebAssembly/external-data.ll b/llvm/test/MC/WebAssembly/external-data.ll --- a/llvm/test/MC/WebAssembly/external-data.ll +++ b/llvm/test/MC/WebAssembly/external-data.ll @@ -10,7 +10,7 @@ @foo = global i64 7, align 4 @bar = hidden global i32* @myimport, align 4 -; CHECK: - Type: DATA +; CHECK: - Type: DATA{{$}} ; CHECK-NEXT: Relocations: ; CHECK-NEXT: - Type: R_WASM_MEMORY_ADDR_I32 ; CHECK-NEXT: Index: 2 diff --git a/llvm/test/MC/WebAssembly/external-func-address.ll b/llvm/test/MC/WebAssembly/external-func-address.ll --- a/llvm/test/MC/WebAssembly/external-func-address.ll +++ b/llvm/test/MC/WebAssembly/external-func-address.ll @@ -58,7 +58,7 @@ ; CHECK-NEXT: Opcode: I32_CONST ; CHECK-NEXT: Value: 1 ; CHECK-NEXT: Functions: [ 1, 2 ] -; CHECK: - Type: DATA +; CHECK: - Type: DATA{{$}} ; CHECK-NEXT: Relocations: ; CHECK-NEXT: - Type: R_WASM_TABLE_INDEX_I32 ; CHECK-NEXT: Index: 3 diff --git a/llvm/test/MC/WebAssembly/global-ctor-dtor.ll b/llvm/test/MC/WebAssembly/global-ctor-dtor.ll --- a/llvm/test/MC/WebAssembly/global-ctor-dtor.ll +++ b/llvm/test/MC/WebAssembly/global-ctor-dtor.ll @@ -61,6 +61,8 @@ ; CHECK-NEXT: Opcode: I32_CONST ; CHECK-NEXT: Value: 1 ; CHECK-NEXT: Functions: [ 5, 7 ] +; CHECK-NEXT: - Type: DATACOUNT +; CHECK-NEXT: Count: 1 ; CHECK-NEXT: - Type: CODE ; CHECK-NEXT: Relocations: ; CHECK-NEXT: - Type: R_WASM_FUNCTION_INDEX_LEB diff --git a/llvm/test/MC/WebAssembly/reloc-code.ll b/llvm/test/MC/WebAssembly/reloc-code.ll --- a/llvm/test/MC/WebAssembly/reloc-code.ll +++ b/llvm/test/MC/WebAssembly/reloc-code.ll @@ -24,7 +24,7 @@ ; CHECK: Format: WASM ; CHECK: Relocations [ -; CHECK-NEXT: Section (4) CODE { +; CHECK-NEXT: Section (5) CODE { ; CHECK-NEXT: Relocation { ; CHECK-NEXT: Type: R_WASM_MEMORY_ADDR_LEB (3) ; CHECK-NEXT: Offset: 0x9 diff --git a/llvm/test/MC/WebAssembly/reloc-data.ll b/llvm/test/MC/WebAssembly/reloc-data.ll --- a/llvm/test/MC/WebAssembly/reloc-data.ll +++ b/llvm/test/MC/WebAssembly/reloc-data.ll @@ -13,7 +13,7 @@ ; CHECK: Format: WASM ; CHECK: Relocations [ -; CHECK-NEXT: Section (2) DATA { +; CHECK-NEXT: Section (3) DATA { ; CHECK-NEXT: Relocation { ; CHECK-NEXT: Type: R_WASM_MEMORY_ADDR_I32 (5) ; CHECK-NEXT: Offset: 0x13 diff --git a/llvm/test/MC/WebAssembly/reloc-pic.s b/llvm/test/MC/WebAssembly/reloc-pic.s --- a/llvm/test/MC/WebAssembly/reloc-pic.s +++ b/llvm/test/MC/WebAssembly/reloc-pic.s @@ -84,6 +84,8 @@ # CHECK-NEXT: GlobalMutable: true # CHECK-NEXT: - Type: FUNCTION # CHECK-NEXT: FunctionTypes: [ 0, 0, 0, 0, 0 ] +# CHECK-NEXT: - Type: DATACOUNT +# CHECK-NEXT: Count: 1 # CHECK-NEXT: - Type: CODE # CHECK-NEXT: Relocations: # CHECK-NEXT: - Type: R_WASM_GLOBAL_INDEX_LEB diff --git a/llvm/test/MC/WebAssembly/unnamed-data.ll b/llvm/test/MC/WebAssembly/unnamed-data.ll --- a/llvm/test/MC/WebAssembly/unnamed-data.ll +++ b/llvm/test/MC/WebAssembly/unnamed-data.ll @@ -9,7 +9,7 @@ @b = global i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str2, i32 0, i32 0), align 8 -; CHECK: - Type: DATA +; CHECK: - Type: DATA{{$}} ; CHECK-NEXT: Relocations: ; CHECK-NEXT: - Type: R_WASM_MEMORY_ADDR_I32 ; CHECK-NEXT: Index: 0 diff --git a/llvm/test/MC/WebAssembly/weak-alias.ll b/llvm/test/MC/WebAssembly/weak-alias.ll --- a/llvm/test/MC/WebAssembly/weak-alias.ll +++ b/llvm/test/MC/WebAssembly/weak-alias.ll @@ -73,6 +73,8 @@ ; CHECK-NEXT: Opcode: I32_CONST ; CHECK-NEXT: Value: 1 ; CHECK-NEXT: Functions: [ 0 ] +; CHECK-NEXT: - Type: DATACOUNT +; CHECK-NEXT: Count: 3 ; CHECK-NEXT: - Type: CODE ; CHECK-NEXT: Relocations: ; CHECK-NEXT: - Type: R_WASM_FUNCTION_INDEX_LEB diff --git a/llvm/tools/llvm-readobj/WasmDumper.cpp b/llvm/tools/llvm-readobj/WasmDumper.cpp --- a/llvm/tools/llvm-readobj/WasmDumper.cpp +++ b/llvm/tools/llvm-readobj/WasmDumper.cpp @@ -32,11 +32,11 @@ static const EnumEntry WasmSectionTypes[] = { #define ENUM_ENTRY(X) \ { #X, wasm::WASM_SEC_##X } - ENUM_ENTRY(CUSTOM), ENUM_ENTRY(TYPE), ENUM_ENTRY(IMPORT), - ENUM_ENTRY(FUNCTION), ENUM_ENTRY(TABLE), ENUM_ENTRY(MEMORY), - ENUM_ENTRY(GLOBAL), ENUM_ENTRY(EVENT), ENUM_ENTRY(EXPORT), - ENUM_ENTRY(START), ENUM_ENTRY(ELEM), ENUM_ENTRY(CODE), - ENUM_ENTRY(DATA), + ENUM_ENTRY(CUSTOM), ENUM_ENTRY(TYPE), ENUM_ENTRY(IMPORT), + ENUM_ENTRY(FUNCTION), ENUM_ENTRY(TABLE), ENUM_ENTRY(MEMORY), + ENUM_ENTRY(GLOBAL), ENUM_ENTRY(EVENT), ENUM_ENTRY(EXPORT), + ENUM_ENTRY(START), ENUM_ENTRY(ELEM), ENUM_ENTRY(CODE), + ENUM_ENTRY(DATA), ENUM_ENTRY(DATACOUNT), #undef ENUM_ENTRY }; diff --git a/llvm/tools/obj2yaml/wasm2yaml.cpp b/llvm/tools/obj2yaml/wasm2yaml.cpp --- a/llvm/tools/obj2yaml/wasm2yaml.cpp +++ b/llvm/tools/obj2yaml/wasm2yaml.cpp @@ -353,6 +353,12 @@ S = std::move(DataSec); break; } + case wasm::WASM_SEC_DATACOUNT: { + auto DataCountSec = make_unique(); + DataCountSec->Count = Obj.dataSegments().size(); + S = std::move(DataCountSec); + break; + } default: llvm_unreachable("Unknown section type"); break; diff --git a/llvm/tools/yaml2obj/yaml2wasm.cpp b/llvm/tools/yaml2obj/yaml2wasm.cpp --- a/llvm/tools/yaml2obj/yaml2wasm.cpp +++ b/llvm/tools/yaml2obj/yaml2wasm.cpp @@ -43,6 +43,7 @@ int writeSectionContent(raw_ostream &OS, WasmYAML::ElemSection &Section); int writeSectionContent(raw_ostream &OS, WasmYAML::CodeSection &Section); int writeSectionContent(raw_ostream &OS, WasmYAML::DataSection &Section); + int writeSectionContent(raw_ostream &OS, WasmYAML::DataCountSection &Section); // Custom section types int writeSectionContent(raw_ostream &OS, WasmYAML::DylinkSection &Section); @@ -514,6 +515,12 @@ return 0; } +int WasmWriter::writeSectionContent(raw_ostream &OS, + WasmYAML::DataCountSection &Section) { + encodeULEB128(Section.Count, OS); + return 0; +} + int WasmWriter::writeRelocSection(raw_ostream &OS, WasmYAML::Section &Sec, uint32_t SectionIndex) { switch (Sec.Type) { @@ -614,6 +621,9 @@ } else if (auto S = dyn_cast(Sec.get())) { if (auto Err = writeSectionContent(StringStream, *S)) return Err; + } else if (auto S = dyn_cast(Sec.get())) { + if (auto Err = writeSectionContent(StringStream, *S)) + return Err; } else { errs() << "Unknown section type: " << Sec->Type << "\n"; return 1;