diff options
author | Andy Wingo <wingo@igalia.com> | 2021-02-17 17:20:28 +0100 |
---|---|---|
committer | Andy Wingo <wingo@igalia.com> | 2021-02-18 09:16:29 +0100 |
commit | f48923e884611e6271a8da821a58aedd24d91cf7 (patch) | |
tree | 1585affb143eb1c44dd64c283a8c2f95bdcc43d1 | |
parent | fb1dc77bfd24c32a5231face77e0bc4323b67c68 (diff) | |
download | llvm-f48923e884611e6271a8da821a58aedd24d91cf7.zip llvm-f48923e884611e6271a8da821a58aedd24d91cf7.tar.gz llvm-f48923e884611e6271a8da821a58aedd24d91cf7.tar.bz2 |
[WebAssembly][lld] --importTable flag only imports table if needed
Before, --importTable forced the creation of an indirect function table,
whether it was needed or not. Now it only imports a table if needed.
Differential Revision: https://reviews.llvm.org/D96872
-rw-r--r-- | lld/test/wasm/import-table.test | 10 | ||||
-rw-r--r-- | lld/wasm/Driver.cpp | 20 |
2 files changed, 10 insertions, 20 deletions
diff --git a/lld/test/wasm/import-table.test b/lld/test/wasm/import-table.test index 462264d..088ff12 100644 --- a/lld/test/wasm/import-table.test +++ b/lld/test/wasm/import-table.test @@ -1,7 +1,15 @@ # RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %p/Inputs/start.s -o %t.start.o -# RUN: wasm-ld --import-table -o %t.wasm %t.start.o +# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %s -o %t.o +# RUN: wasm-ld --export-all --import-table -o %t.wasm %t.start.o %t.o # RUN: obj2yaml %t.wasm | FileCheck %s +.globl require_function_table +require_function_table: +.functype require_function_table () -> () + i32.const 1 + call_indirect () -> () + end_function + # Verify the --import-table flag creates a table import # CHECK: - Type: IMPORT diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp index a3bcfb7..7e647cb 100644 --- a/lld/wasm/Driver.cpp +++ b/lld/wasm/Driver.cpp @@ -799,21 +799,6 @@ static TableSymbol *createDefinedIndirectFunctionTable(StringRef name) { return sym; } -static TableSymbol *createUndefinedIndirectFunctionTable(StringRef name) { - WasmLimits limits{0, 0, 0}; // Set by the writer. - WasmTableType *type = make<WasmTableType>(); - type->ElemType = uint8_t(ValType::FUNCREF); - type->Limits = limits; - StringRef module(defaultModule); - uint32_t flags = config->exportTable ? 0 : WASM_SYMBOL_VISIBILITY_HIDDEN; - flags |= WASM_SYMBOL_UNDEFINED; - Symbol *sym = - symtab->addUndefinedTable(name, name, module, flags, nullptr, type); - sym->markLive(); - sym->forceExport = config->exportTable; - return cast<TableSymbol>(sym); -} - static TableSymbol *resolveIndirectFunctionTable() { Symbol *existing = symtab->find(functionTableName); if (existing) { @@ -830,10 +815,7 @@ static TableSymbol *resolveIndirectFunctionTable() { } if (config->importTable) { - if (existing) - return cast<TableSymbol>(existing); - else - return createUndefinedIndirectFunctionTable(functionTableName); + return cast_or_null<TableSymbol>(existing); } else if ((existing && existing->isLive()) || config->exportTable) { // A defined table is required. Either because the user request an exported // table or because the table symbol is already live. The existing table is |