[WebAssembly] Don't generate empty type sections.
Differential Revision: https://reviews.llvm.org/D61991
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@360940 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/wasm/section-symbol-relocs.yaml b/test/wasm/section-symbol-relocs.yaml
index ad292e3..b7d8a44 100644
--- a/test/wasm/section-symbol-relocs.yaml
+++ b/test/wasm/section-symbol-relocs.yaml
@@ -49,3 +49,13 @@
# RELOC-NEXT: Offset: 0x0000000B
# RELOC-NEXT: Addend: 3
# RELOC-NEXT: Name: green
+#
+# RELOC: SymbolTable:
+# RELOC-NEXT: - Index: 0
+# RELOC-NEXT: Kind: SECTION
+# RELOC-NEXT: Flags: [ BINDING_LOCAL ]
+# RELOC-NEXT: Section: 2
+# RELOC-NEXT: - Index: 1
+# RELOC-NEXT: Kind: SECTION
+# RELOC-NEXT: Flags: [ BINDING_LOCAL ]
+# RELOC-NEXT: Section: 3
diff --git a/wasm/Writer.cpp b/wasm/Writer.cpp
index fedaa54..8460f85 100644
--- a/wasm/Writer.cpp
+++ b/wasm/Writer.cpp
@@ -234,6 +234,8 @@
}
void Writer::createTypeSection() {
+ if (!Types.size())
+ return;
SyntheticSection *Section = createSyntheticSection(WASM_SEC_TYPE);
raw_ostream &OS = Section->getStream();
writeUleb128(OS, Types.size(), "type count");