[lld] 06f1a5c - [lld][WebAssembly] Allow symbols with explict import names to be undefined at link time.
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 19 18:03:32 PST 2020
Author: Sam Clegg
Date: 2020-02-19T18:02:49-08:00
New Revision: 06f1a5c9c283838b8ed1d16961e41462371cd61f
URL: https://github.com/llvm/llvm-project/commit/06f1a5c9c283838b8ed1d16961e41462371cd61f
DIFF: https://github.com/llvm/llvm-project/commit/06f1a5c9c283838b8ed1d16961e41462371cd61f.diff
LOG: [lld][WebAssembly] Allow symbols with explict import names to be undefined at link time.
Differential Revision: https://reviews.llvm.org/D74110
Added:
Modified:
lld/docs/WebAssembly.rst
lld/test/wasm/import-name.ll
lld/wasm/Relocations.cpp
Removed:
################################################################################
diff --git a/lld/docs/WebAssembly.rst b/lld/docs/WebAssembly.rst
index 1b01cab5c253..13ed0aeb94d4 100644
--- a/lld/docs/WebAssembly.rst
+++ b/lld/docs/WebAssembly.rst
@@ -112,8 +112,8 @@ The default behaviour is to generate these stub function and to produce
a warning. The ``--fatal-warnings`` flag can be used to disable this behaviour
and error out if mismatched are found.
-Imports and Exports
-~~~~~~~~~~~~~~~~~~~
+Exports
+~~~~~~~
When building a shared library any symbols marked as ``visibility=default`` will
be exported.
@@ -130,6 +130,17 @@ Finally, just like with native ELF linker the ``--export-dynamic`` flag can be
used to export symbols in the executable which are marked as
``visibility=default``.
+Imports
+~~~~~~~
+
+By default no undefined symbols are allowed in the final binary. The flag
+``--allow-undefined`` results in a WebAssembly import being defined for each
+undefined symbol. It is then up to the runtime to provide such symbols.
+
+Alternativly symbols can be marked in the source code as with the
+``import_name`` and/or ``import_module`` clang attributes which signals that
+they are expected to be undefined at static link time.
+
Garbage Collection
~~~~~~~~~~~~~~~~~~
diff --git a/lld/test/wasm/import-name.ll b/lld/test/wasm/import-name.ll
index a3953d335619..fdcbe115df6f 100644
--- a/lld/test/wasm/import-name.ll
+++ b/lld/test/wasm/import-name.ll
@@ -1,5 +1,5 @@
; RUN: llc -filetype=obj %s -o %t.o
-; RUN: wasm-ld --allow-undefined -o %t.wasm %t.o
+; RUN: wasm-ld -o %t.wasm %t.o
; RUN: obj2yaml %t.wasm | FileCheck %s
target triple = "wasm32-unknown-unknown"
diff --git a/lld/wasm/Relocations.cpp b/lld/wasm/Relocations.cpp
index 006a6662cafc..2ab449ffe256 100644
--- a/lld/wasm/Relocations.cpp
+++ b/lld/wasm/Relocations.cpp
@@ -28,6 +28,11 @@ static bool allowUndefined(const Symbol* sym) {
// compiling with -fPIC)
if (isa<DataSymbol>(sym))
return false;
+ // Undefined functions with explicit import name are allowed to be undefined
+ // at link time.
+ if (auto *F = dyn_cast<UndefinedFunction>(sym))
+ if (F->importName)
+ return true;
return (config->allowUndefined ||
config->allowUndefinedSymbols.count(sym->getName()) != 0);
}
More information about the llvm-commits
mailing list