diff --git a/lld/docs/WebAssembly.rst b/lld/docs/WebAssembly.rst --- a/lld/docs/WebAssembly.rst +++ b/lld/docs/WebAssembly.rst @@ -112,8 +112,8 @@ 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 @@ 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 --- 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 --- a/lld/wasm/Relocations.cpp +++ b/lld/wasm/Relocations.cpp @@ -28,6 +28,11 @@ // compiling with -fPIC) if (isa(sym)) return false; + // Undefined functions with explicit import name are allowed to be undefined + // at link time. + if (auto *F = dyn_cast(sym)) + if (F->importName) + return true; return (config->allowUndefined || config->allowUndefinedSymbols.count(sym->getName()) != 0); }