[WebAssembly] LTO: Fix signatures of undefined functions in bitcode

Function symbols that come from bitcode have not signatures.
After LTO when the real symbols are read in we need to make
sure that we set the signature on the existing symbol.
the signature-less undefined functions.

Differential Revision: https://reviews.llvm.org/D48693

llvm-svn: 335875
diff --git a/lld/wasm/SymbolTable.cpp b/lld/wasm/SymbolTable.cpp
index 1180cfc..6541ddc 100644
--- a/lld/wasm/SymbolTable.cpp
+++ b/lld/wasm/SymbolTable.cpp
@@ -106,7 +106,7 @@
         " in " + toString(File));
 }
 
-static void checkFunctionType(const Symbol *Existing, const InputFile *File,
+static void checkFunctionType(Symbol *Existing, const InputFile *File,
                               const WasmSignature *NewSig) {
   auto ExistingFunction = dyn_cast<FunctionSymbol>(Existing);
   if (!ExistingFunction) {
@@ -114,13 +114,20 @@
     return;
   }
 
-  const WasmSignature *OldSig = ExistingFunction->getFunctionType();
-  if (OldSig && NewSig && *NewSig != *OldSig) {
+  if (!NewSig)
+    return;
+
+  const WasmSignature *OldSig = ExistingFunction->FunctionType;
+  if (!OldSig) {
+    ExistingFunction->FunctionType = NewSig;
+    return;
+  }
+
+  if (*NewSig != *OldSig)
     warn("function signature mismatch: " + Existing->getName() +
          "\n>>> defined as " + toString(*OldSig) + " in " +
          toString(Existing->getFile()) + "\n>>> defined as " +
          toString(*NewSig) + " in " + toString(File));
-  }
 }
 
 // Check the type of new symbol matches that of the symbol is replacing.
@@ -286,8 +293,9 @@
     replaceSymbol<UndefinedFunction>(S, Name, Flags, File, Sig);
   else if (auto *Lazy = dyn_cast<LazySymbol>(S))
     Lazy->fetch();
-  else if (S->isDefined())
+  else
     checkFunctionType(S, File, Sig);
+
   return S;
 }