[lld] r358798 - [WebAssembly] Emit the DataCount section when bulk memory is enabled

Thomas Lively via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 19 16:40:36 PDT 2019


Author: tlively
Date: Fri Apr 19 16:40:36 2019
New Revision: 358798

URL: http://llvm.org/viewvc/llvm-project?rev=358798&view=rev
Log:
[WebAssembly] Emit the DataCount section when bulk memory is enabled

Summary:
The DataCount section is necessary for the bulk memory operations
memory.init and data.drop to validate, but it is not recognized by
engines that do not support bulk memory, so emit the section only if
bulk-memory is enabled.

Reviewers: aheejin, dschuff, sbc100

Subscribers: jgravelle-google, sunfish, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D60637

Modified:
    lld/trunk/test/wasm/data-segment-merging.ll
    lld/trunk/wasm/OutputSections.cpp
    lld/trunk/wasm/Writer.cpp

Modified: lld/trunk/test/wasm/data-segment-merging.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/data-segment-merging.ll?rev=358798&r1=358797&r2=358798&view=diff
==============================================================================
--- lld/trunk/test/wasm/data-segment-merging.ll (original)
+++ lld/trunk/test/wasm/data-segment-merging.ll Fri Apr 19 16:40:36 2019
@@ -12,6 +12,8 @@ target triple = "wasm32-unknown-unknown"
 
 ; RUN: wasm-ld -no-gc-sections --no-entry -o %t.merged.wasm %t.data-segment-merging.o
 ; RUN: obj2yaml %t.merged.wasm | FileCheck %s --check-prefix=MERGE
+
+; MERGE-NOT:                  DATACOUNT
 ; MERGE:   - Type:            DATA
 ; MERGE:     Segments:
 ; MERGE:        Content:         68656C6C6F00676F6F6462796500776861746576657200002A000000
@@ -20,6 +22,8 @@ target triple = "wasm32-unknown-unknown"
 
 ; RUN: wasm-ld -no-gc-sections --no-entry --no-merge-data-segments -o %t.separate.wasm %t.data-segment-merging.o
 ; RUN: obj2yaml %t.separate.wasm | FileCheck %s --check-prefix=SEPARATE
+
+; SEPARATE-NOT:                  DATACOUNT
 ; SEPARATE:   - Type:            DATA
 ; SEPARATE:     Segments:
 ; SEPARATE:        Content:         68656C6C6F00
@@ -29,3 +33,15 @@ target triple = "wasm32-unknown-unknown"
 ; SEPARATE:        Content:         636F6E7374616E7400
 ; SEPARATE:        Content:         2B
 ; SEPARATE-NOT:    Content:
+
+; RUN: llc -filetype=obj %s -mattr=+bulk-memory -o %t.data-segment-merging.bulk-memory.o
+; RUN: wasm-ld -no-gc-sections --no-entry -o %t.merged.bulk-memory.wasm %t.data-segment-merging.bulk-memory.o
+; RUN: obj2yaml %t.merged.bulk-memory.wasm | FileCheck %s --check-prefix=BULK-MEMORY
+
+; BULK-MEMORY:   - Type:            DATACOUNT
+; BULK-MEMORY:     Count:           2
+; BULK-MEMORY:   - Type:            DATA
+; BULK-MEMORY:     Segments:
+; BULK-MEMORY:        Content:         68656C6C6F00676F6F6462796500776861746576657200002A000000
+; BULK-MEMORY:        Content:         636F6E7374616E74000000002B
+; BULK-MEMORY-NOT:    Content:

Modified: lld/trunk/wasm/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/OutputSections.cpp?rev=358798&r1=358797&r2=358798&view=diff
==============================================================================
--- lld/trunk/wasm/OutputSections.cpp (original)
+++ lld/trunk/wasm/OutputSections.cpp Fri Apr 19 16:40:36 2019
@@ -51,6 +51,8 @@ static StringRef sectionTypeToString(uin
     return "CODE";
   case WASM_SEC_DATA:
     return "DATA";
+  case WASM_SEC_DATACOUNT:
+    return "DATACOUNT";
   default:
     fatal("invalid section type");
   }

Modified: lld/trunk/wasm/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Writer.cpp?rev=358798&r1=358797&r2=358798&view=diff
==============================================================================
--- lld/trunk/wasm/Writer.cpp (original)
+++ lld/trunk/wasm/Writer.cpp Fri Apr 19 16:40:36 2019
@@ -93,6 +93,7 @@ private:
   void createImportSection();
   void createMemorySection();
   void createElemSection();
+  void createDataCountSection();
   void createCodeSection();
   void createDataSection();
   void createCustomSections();
@@ -414,6 +415,16 @@ void Writer::createElemSection() {
   }
 }
 
+void Writer::createDataCountSection() {
+  if (!Segments.size() || !TargetFeatures.count("bulk-memory"))
+    return;
+
+  log("createDataCountSection");
+  SyntheticSection *Section = createSyntheticSection(WASM_SEC_DATACOUNT);
+  raw_ostream &OS = Section->getStream();
+  writeUleb128(OS, Segments.size(), "data count");
+}
+
 void Writer::createCodeSection() {
   if (InputFunctions.empty())
     return;
@@ -865,6 +876,7 @@ void Writer::createSections() {
   createEventSection();
   createExportSection();
   createElemSection();
+  createDataCountSection();
   createCodeSection();
   createDataSection();
   createCustomSections();




More information about the llvm-commits mailing list