summaryrefslogtreecommitdiffstats
path: root/lld/wasm/Driver.cpp
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2018-08-04 00:04:06 +0000
committerSam Clegg <sbc@chromium.org>2018-08-04 00:04:06 +0000
commit47e2b6b29eae57267b5c966eb7d02dc8eae0caaf (patch)
tree457d8d54ec7090c29e0acbeaf5f778192946046c /lld/wasm/Driver.cpp
parentefab30c73ee9793c780665fbd46a68aa5ac2a138 (diff)
downloadbcm5719-llvm-47e2b6b29eae57267b5c966eb7d02dc8eae0caaf.tar.gz
bcm5719-llvm-47e2b6b29eae57267b5c966eb7d02dc8eae0caaf.zip
[WebAssembly] Don't error when --undefined symbols are not found
This matches the behavior of the ELF linker where -u/--undefined means symbols will get pulled in from archives but won't result in link error if they are missing. Also, don't actually great symbol table entries for the undefined symbols, again matching more closely the ELF linker. This also results in simplification of the code. Differential Revision: https://reviews.llvm.org/D50279 llvm-svn: 338938
Diffstat (limited to 'lld/wasm/Driver.cpp')
-rw-r--r--lld/wasm/Driver.cpp66
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);
OpenPOWER on IntegriCloud