[WebAssembly] Add --export flag to force a symbol to be exported
This is useful for emscripten or other tools that want to
selectively exports symbols without necessarily changing the
source code.
Differential Revision: https://reviews.llvm.org/D42003
llvm-svn: 322408
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index 0173cdc..75c3cb5 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -296,8 +296,8 @@
addSyntheticUndefinedFunction(Config->Entry, &Signature);
// Handle the `--undefined <sym>` options.
- for (StringRef S : args::getStrings(Args, OPT_undefined))
- addSyntheticUndefinedFunction(S, nullptr);
+ for (auto* Arg : Args.filtered(OPT_undefined))
+ addSyntheticUndefinedFunction(Arg->getValue(), nullptr);
Config->CtorSymbol = Symtab->addDefinedFunction(
"__wasm_call_ctors", &Signature, WASM_SYMBOL_VISIBILITY_HIDDEN);
@@ -321,8 +321,8 @@
// -u/--undefined since these undefined symbols have only names and no
// function signature, which means they cannot be written to the final
// output.
- for (StringRef S : args::getStrings(Args, OPT_undefined)) {
- Symbol *Sym = Symtab->find(S);
+ for (auto* Arg : Args.filtered(OPT_undefined)) {
+ Symbol *Sym = Symtab->find(Arg->getValue());
if (!Sym->isDefined())
error("function forced with --undefined not found: " + Sym->getName());
}
@@ -330,6 +330,15 @@
if (errorCount())
return;
+ for (auto *Arg : Args.filtered(OPT_export)) {
+ Symbol *Sym = Symtab->find(Arg->getValue());
+ if (!Sym || !Sym->isDefined())
+ error("symbol exported via --export not found: " +
+ Twine(Arg->getValue()));
+ else
+ Sym->setHidden(false);
+ }
+
if (!Config->Entry.empty() && !Symtab->find(Config->Entry)->isDefined())
error("entry point not found: " + Config->Entry);
if (errorCount())