[lld][WebAssembly] Add new `--import-undefined` option
This change revisits https://reviews.llvm.org/D79248 which originally
added support for the --unresolved-symbols flag.
At the time I thought it would make sense to add a third option to this
flag called `import-functions` but it turns out (as was suspects by on
the reviewers IIRC) that this option can be authoganal.
Instead I've added a new option called `--import-undefined` that only
operates on symbols that can be imported (for example, function symbols
can always be imported as opposed to data symbols we can only be
imported when compiling with PIC).
This option gives us the full expresivitiy that emscripten needs to be
able allow reporting of undefined data symbols as well as the option to
disable that.
This change does remove the `--unresolved-symbols=import-functions`
option, which is been in the codebase now for about a year but I would
be extremely surprised if anyone was using it.
Differential Revision: https://reviews.llvm.org/D103290
diff --git a/lld/wasm/Relocations.cpp b/lld/wasm/Relocations.cpp
index eedd7d7..bb2019a 100644
--- a/lld/wasm/Relocations.cpp
+++ b/lld/wasm/Relocations.cpp
@@ -35,7 +35,7 @@
// Undefined functions and globals with explicit import name are allowed to be
// undefined at link time.
if (auto *f = dyn_cast<UndefinedFunction>(sym))
- if (f->importName)
+ if (f->importName || config->importUndefined)
return true;
if (auto *g = dyn_cast<UndefinedGlobal>(sym))
if (g->importName)
@@ -56,20 +56,20 @@
warn(toString(sym->getFile()) + ": undefined symbol: " + toString(*sym));
break;
case UnresolvedPolicy::Ignore:
- if (auto *f = dyn_cast<UndefinedFunction>(sym)) {
- if (!f->stubFunction) {
- LLVM_DEBUG(dbgs()
- << "ignoring undefined symbol: " + toString(*sym) + "\n");
- f->stubFunction = symtab->createUndefinedStub(*f->getSignature());
- f->stubFunction->markLive();
- // Mark the function itself as a stub which prevents it from being
- // assigned a table entry.
- f->isStub = true;
+ LLVM_DEBUG(dbgs() << "ignoring undefined symbol: " + toString(*sym) +
+ "\n");
+ if (!config->importUndefined) {
+ if (auto *f = dyn_cast<UndefinedFunction>(sym)) {
+ if (!f->stubFunction) {
+ f->stubFunction = symtab->createUndefinedStub(*f->getSignature());
+ f->stubFunction->markLive();
+ // Mark the function itself as a stub which prevents it from being
+ // assigned a table entry.
+ f->isStub = true;
+ }
}
}
break;
- case UnresolvedPolicy::ImportFuncs:
- break;
}
}
}