[WebAssembly] Error on mismatched function signature in final output

During symbol resolution, emit warnings for function signature
mismatches.  During GC, if any mismatched symbol is marked as live
then generate an error.

This means that we only error out if the mismatch is written to the
final output.  i.e. if we would generate an invalid wasm file.

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

llvm-svn: 335192
diff --git a/lld/wasm/SymbolTable.cpp b/lld/wasm/SymbolTable.cpp
index 1180cfc..77b2f18 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,12 +114,27 @@
     return;
   }
 
+
   const WasmSignature *OldSig = ExistingFunction->getFunctionType();
   if (OldSig && NewSig && *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));
+    // Don't generate more than one warning per symbol.
+    if (Existing->SignatureMismatch)
+      return;
+    Existing->SignatureMismatch = true;
+
+    std::string msg = ("function signature mismatch: " + Existing->getName() +
+                       "\n>>> defined as " + toString(*OldSig) + " in " +
+                       toString(Existing->getFile()) + "\n>>> defined as " +
+                       toString(*NewSig) + " in " + toString(File))
+                          .str();
+    // A function signature mismatch is only really problem if the mismatched
+    // symbol is included in the final output, and gc-sections can remove the
+    // offending uses.  Therefore we delay reporting this as an error when
+    // section GC is enabled.
+    if (Config->GcSections)
+      warn(msg);
+    else
+      error(msg);
   }
 }