[PATCH] D65916: [lld][WebAssembly] Support for growable tables

Jacob Gravelle via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 7 18:11:07 PDT 2019


jgravelle-google created this revision.
jgravelle-google added a reviewer: sbc100.
Herald added subscribers: sunfish, aheejin, dschuff.
Herald added a project: LLVM.

Adds --growable-table flag to handle building wasm modules with tables
that can grow.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65916

Files:
  lld/test/wasm/growable-table.test
  lld/wasm/Config.h
  lld/wasm/Driver.cpp
  lld/wasm/Options.td
  lld/wasm/SyntheticSections.cpp


Index: lld/wasm/SyntheticSections.cpp
===================================================================
--- lld/wasm/SyntheticSections.cpp
+++ lld/wasm/SyntheticSections.cpp
@@ -215,7 +215,11 @@
 
   raw_ostream &os = bodyOutputStream;
   writeUleb128(os, 1, "table count");
-  WasmLimits limits = {WASM_LIMITS_FLAG_HAS_MAX, tableSize, tableSize};
+  WasmLimits limits;
+  if (config->growableTable)
+    limits = {0, tableSize, 0};
+  else
+    limits = {WASM_LIMITS_FLAG_HAS_MAX, tableSize, tableSize};
   writeTableType(os, WasmTable{WASM_TYPE_FUNCREF, limits});
 }
 
Index: lld/wasm/Options.td
===================================================================
--- lld/wasm/Options.td
+++ lld/wasm/Options.td
@@ -134,6 +134,9 @@
 def export_table: F<"export-table">,
   HelpText<"Export function table to the environment">;
 
+def growable_table: F<"growable-table">,
+  HelpText<"Allow table to grow">;
+
 def global_base: J<"global-base=">,
   HelpText<"Where to start to place global data">;
 
Index: lld/wasm/Driver.cpp
===================================================================
--- lld/wasm/Driver.cpp
+++ lld/wasm/Driver.cpp
@@ -316,6 +316,7 @@
   config->exportDynamic = args.hasFlag(OPT_export_dynamic,
       OPT_no_export_dynamic, false);
   config->exportTable = args.hasArg(OPT_export_table);
+  config->growableTable = args.hasArg(OPT_growable_table);
   errorHandler().fatalWarnings =
       args.hasFlag(OPT_fatal_warnings, OPT_no_fatal_warnings, false);
   config->importMemory = args.hasArg(OPT_import_memory);
Index: lld/wasm/Config.h
===================================================================
--- lld/wasm/Config.h
+++ lld/wasm/Config.h
@@ -31,6 +31,7 @@
   bool exportAll;
   bool exportDynamic;
   bool exportTable;
+  bool growableTable;
   bool gcSections;
   bool importMemory;
   bool sharedMemory;
Index: lld/test/wasm/growable-table.test
===================================================================
--- /dev/null
+++ lld/test/wasm/growable-table.test
@@ -0,0 +1,17 @@
+# RUN: llc -filetype=obj %p/Inputs/start.ll -o %t.start.o
+# RUN: wasm-ld --export-table --growable-table -o %t.wasm %t.start.o
+# RUN: obj2yaml %t.wasm | FileCheck %s
+
+# Verify the --growable-table flag creates a growable table
+
+# CHECK:        - Type:            TABLE
+# CHECK-NEXT:     Tables:
+# CHECK-NEXT:       - ElemType:        FUNCREF
+# CHECK-NEXT:         Limits:
+# CHECK-NEXT:           Initial:         0x00000001
+# CHECK-NEXT:   - Type:
+# CHECK:        - Type:            EXPORT
+# CHECK-NEXT:     Exports:
+# CHECK:            - Name:            __indirect_function_table
+# CHECK-NEXT:         Kind:            TABLE
+# CHECK-NEXT:         Index:           0


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65916.214048.patch
Type: text/x-patch
Size: 2712 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190808/296e3ece/attachment.bin>


More information about the llvm-commits mailing list