[lld] r370127 - [lld][WebAssembly] Support for growable tables
Jacob Gravelle via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 27 15:58:22 PDT 2019
Author: jgravelle
Date: Tue Aug 27 15:58:21 2019
New Revision: 370127
URL: http://llvm.org/viewvc/llvm-project?rev=370127&view=rev
Log:
[lld][WebAssembly] Support for growable tables
Adds --growable-table flag to handle building wasm modules with tables
that can grow.
Wasm tables that we use to store function pointers. In order to add functions
to that table at runtime, we need to either preallocate space, or grow the table.
In order to specify a table with no maximum size, we need some flag to handle
that case, separately from a potential --max-table-size= flag.
Note that the number of elements in the table isn't knowable until link-time,
so it's unclear if we will want a --max-table-size= flag in the future.
Added:
lld/trunk/test/wasm/growable-table.test
Modified:
lld/trunk/wasm/Config.h
lld/trunk/wasm/Driver.cpp
lld/trunk/wasm/Options.td
lld/trunk/wasm/SyntheticSections.cpp
Added: lld/trunk/test/wasm/growable-table.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/growable-table.test?rev=370127&view=auto
==============================================================================
--- lld/trunk/test/wasm/growable-table.test (added)
+++ lld/trunk/test/wasm/growable-table.test Tue Aug 27 15:58:21 2019
@@ -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
Modified: lld/trunk/wasm/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Config.h?rev=370127&r1=370126&r2=370127&view=diff
==============================================================================
--- lld/trunk/wasm/Config.h (original)
+++ lld/trunk/wasm/Config.h Tue Aug 27 15:58:21 2019
@@ -31,6 +31,7 @@ struct Configuration {
bool exportAll;
bool exportDynamic;
bool exportTable;
+ bool growableTable;
bool gcSections;
bool importMemory;
bool sharedMemory;
Modified: lld/trunk/wasm/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Driver.cpp?rev=370127&r1=370126&r2=370127&view=diff
==============================================================================
--- lld/trunk/wasm/Driver.cpp (original)
+++ lld/trunk/wasm/Driver.cpp Tue Aug 27 15:58:21 2019
@@ -314,6 +314,7 @@ static void readConfigs(opt::InputArgLis
config->entry = getEntry(args);
config->exportAll = args.hasArg(OPT_export_all);
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);
Modified: lld/trunk/wasm/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Options.td?rev=370127&r1=370126&r2=370127&view=diff
==============================================================================
--- lld/trunk/wasm/Options.td (original)
+++ lld/trunk/wasm/Options.td Tue Aug 27 15:58:21 2019
@@ -134,6 +134,9 @@ def export_all: F<"export-all">,
def export_table: F<"export-table">,
HelpText<"Export function table to the environment">;
+def growable_table: F<"growable-table">,
+ HelpText<"Remove maximum size from function table, allowing table to grow">;
+
def global_base: J<"global-base=">,
HelpText<"Where to start to place global data">;
Modified: lld/trunk/wasm/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/SyntheticSections.cpp?rev=370127&r1=370126&r2=370127&view=diff
==============================================================================
--- lld/trunk/wasm/SyntheticSections.cpp (original)
+++ lld/trunk/wasm/SyntheticSections.cpp Tue Aug 27 15:58:21 2019
@@ -216,7 +216,11 @@ void TableSection::writeBody() {
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});
}
More information about the llvm-commits
mailing list