diff options
Diffstat (limited to 'lld/wasm/Driver.cpp')
| -rw-r--r-- | lld/wasm/Driver.cpp | 66 |
1 files changed, 30 insertions, 36 deletions
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp index 329b5ae80a9..8d73dab726e 100644 --- a/lld/wasm/Driver.cpp +++ b/lld/wasm/Driver.cpp @@ -329,14 +329,19 @@ static void handleWeakUndefines() { } // Force Sym to be entered in the output. Used for -u or equivalent. -static Symbol *addUndefined(StringRef Name) { - Symbol *S = Symtab->addUndefinedFunction(Name, 0, nullptr, nullptr); +static Symbol *handleUndefined(StringRef Name) { + Symbol *Sym = Symtab->find(Name); + if (!Sym) + return nullptr; // Since symbol S may not be used inside the program, LTO may // eliminate it. Mark the symbol as "used" to prevent it. - S->IsUsedInRegularObj = true; + Sym->IsUsedInRegularObj = true; - return S; + if (auto *LazySym = dyn_cast<LazySymbol>(Sym)) + LazySym->fetch(); + + return Sym; } void LinkerDriver::link(ArrayRef<const char *> ArgsArr) { @@ -462,15 +467,6 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) { WasmSym::DsoHandle = Symtab->addSyntheticDataSymbol( "__dso_handle", WASM_SYMBOL_VISIBILITY_HIDDEN); WasmSym::DataEnd = Symtab->addSyntheticDataSymbol("__data_end", 0); - - // For now, since we don't actually use the start function as the - // wasm start symbol, we don't need to care about it signature. - if (!Config->Entry.empty()) - EntrySym = addUndefined(Config->Entry); - - // Handle the `--undefined <sym>` options. - for (auto *Arg : Args.filtered(OPT_undefined)) - addUndefined(Arg->getValue()); } createFiles(Args); @@ -484,10 +480,29 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) { if (errorCount()) return; - // Add synthetic dummies for weak undefined functions. - if (!Config->Relocatable) + // Handle the `--undefined <sym>` options. + for (auto *Arg : Args.filtered(OPT_undefined)) + handleUndefined(Arg->getValue()); + + if (!Config->Relocatable) { + // Add synthetic dummies for weak undefined functions. handleWeakUndefines(); + if (!Config->Entry.empty()) { + EntrySym = handleUndefined(Config->Entry); + if (!EntrySym) + error("entry symbol not defined (pass --no-entry to supress): " + + Config->Entry); + } + + // Make sure we have resolved all symbols. + if (!Config->AllowUndefined) + Symtab->reportRemainingUndefines(); + } + + if (errorCount()) + return; + // Handle --export. for (auto *Arg : Args.filtered(OPT_export)) { StringRef Name = Arg->getValue(); @@ -504,27 +519,6 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) { if (errorCount()) return; - // Make sure we have resolved all symbols. - if (!Config->Relocatable && !Config->AllowUndefined) { - Symtab->reportRemainingUndefines(); - } else { - // Even when using --allow-undefined we still want to report the absence of - // our initial set of undefined symbols (i.e. the entry point and symbols - // specified via --undefined). - // Part of the reason for this is that these function don't have signatures - // so which means they cannot be written as wasm function imports. - for (auto *Arg : Args.filtered(OPT_undefined)) { - Symbol *Sym = Symtab->find(Arg->getValue()); - if (!Sym->isDefined()) - error("symbol forced with --undefined not found: " + Sym->getName()); - } - if (EntrySym && !EntrySym->isDefined()) - error("entry symbol not defined (pass --no-entry to supress): " + - EntrySym->getName()); - } - if (errorCount()) - return; - if (EntrySym) EntrySym->setHidden(false); |

