diff options
author | Sam Clegg <sbc@chromium.org> | 2018-01-12 22:10:35 +0000 |
---|---|---|
committer | Sam Clegg <sbc@chromium.org> | 2018-01-12 22:10:35 +0000 |
commit | ed1144e5cacdc381e680eb75f76043113de72889 (patch) | |
tree | 29c209ea8fa14739abec8d93ad45b34cf3acdc25 /lld/wasm/Driver.cpp | |
parent | 2f1aa3783694bb35d75fee2b1cdcab68a8356547 (diff) |
[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
Diffstat (limited to 'lld/wasm/Driver.cpp')
-rw-r--r-- | lld/wasm/Driver.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp index 0173cdc09e5..75c3cb56aa5 100644 --- a/lld/wasm/Driver.cpp +++ b/lld/wasm/Driver.cpp @@ -296,8 +296,8 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) { 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 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) { // -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 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) { 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()) |