diff --git a/lld/test/wasm/growable-table.test b/lld/test/wasm/growable-table.test new file mode 100644 --- /dev/null +++ b/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 diff --git a/lld/wasm/Config.h b/lld/wasm/Config.h --- a/lld/wasm/Config.h +++ b/lld/wasm/Config.h @@ -31,6 +31,7 @@ bool exportAll; bool exportDynamic; bool exportTable; + bool growableTable; bool gcSections; bool importMemory; bool sharedMemory; diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp --- a/lld/wasm/Driver.cpp +++ b/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); diff --git a/lld/wasm/Options.td b/lld/wasm/Options.td --- a/lld/wasm/Options.td +++ b/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<"Remove maximum size from function table, allowing table to grow">; + def global_base: J<"global-base=">, HelpText<"Where to start to place global data">; diff --git a/lld/wasm/SyntheticSections.cpp b/lld/wasm/SyntheticSections.cpp --- a/lld/wasm/SyntheticSections.cpp +++ b/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}); }