[WebAssembly] Only mark non-hidden symbols as live if they are also defined
Previously we were also marking undefined symbols (i.e. imports)
as live.
Differential Revision: https://reviews.llvm.org/D48299
llvm-svn: 335243
diff --git a/lld/wasm/MarkLive.cpp b/lld/wasm/MarkLive.cpp
index 6b90690..c9dbbf5 100644
--- a/lld/wasm/MarkLive.cpp
+++ b/lld/wasm/MarkLive.cpp
@@ -40,6 +40,7 @@
auto Enqueue = [&](Symbol *Sym) {
if (!Sym || Sym->isLive())
return;
+ LLVM_DEBUG(dbgs() << "markLive: " << Sym->getName() << "\n");
Sym->markLive();
if (Sym->SignatureMismatch)
error("function signature mismatch: " + Sym->getName());
@@ -52,9 +53,9 @@
Enqueue(Symtab->find(Config->Entry));
Enqueue(WasmSym::CallCtors);
- // By default we export all non-hidden, so they are gc roots too
+ // We export all defined, non-hidden symbols so they are all gc roots too
for (Symbol *Sym : Symtab->getSymbols())
- if (!Sym->isHidden())
+ if (Sym->isDefined() && !Sym->isHidden())
Enqueue(Sym);
// The ctor functions are all used in the synthetic __wasm_call_ctors