[WebAssembly] Write out undefined symbol addresses as zero
The addresses of undefined symbols that make it into the final
executable (i.e. weak references to non-existent symbols) should
resolve to zero.
Also, make sure to not include function in the indirect function
table if they are not included in the output.
Differential Revision: https://reviews.llvm.org/D41839
llvm-svn: 322045
diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp
index e7dd49d..dfa0760 100644
--- a/lld/wasm/Writer.cpp
+++ b/lld/wasm/Writer.cpp
@@ -629,12 +629,14 @@
Sym->setOutputIndex(GlobalIndex++);
}
}
+ }
+ for (ObjFile *File : Symtab->ObjectFiles) {
for (Symbol *Sym : File->getTableSymbols()) {
- if (!Sym->hasTableIndex()) {
- Sym->setTableIndex(TableIndex++);
- IndirectFunctions.emplace_back(Sym);
- }
+ if (Sym->hasTableIndex() || !Sym->hasOutputIndex())
+ continue;
+ Sym->setTableIndex(TableIndex++);
+ IndirectFunctions.emplace_back(Sym);
}
}
}