forked from OSchip/llvm-project
[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. llvm-svn: 370127
This commit is contained in:
parent
29db51dad4
commit
92ed86d239
|
@ -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
|
|
@ -31,6 +31,7 @@ struct Configuration {
|
|||
bool exportAll;
|
||||
bool exportDynamic;
|
||||
bool exportTable;
|
||||
bool growableTable;
|
||||
bool gcSections;
|
||||
bool importMemory;
|
||||
bool sharedMemory;
|
||||
|
|
|
@ -314,6 +314,7 @@ static void readConfigs(opt::InputArgList &args) {
|
|||
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);
|
||||
|
|
|
@ -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">;
|
||||
|
||||
|
|
|
@ -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});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue