[lld] r370509 - [lld][WebAssembly] Fix spurious signature mismatch warnings

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 30 12:50:59 PDT 2019


Author: sbc
Date: Fri Aug 30 12:50:59 2019
New Revision: 370509

URL: http://llvm.org/viewvc/llvm-project?rev=370509&view=rev
Log:
[lld][WebAssembly] Fix spurious signature mismatch warnings

Summary:
This a follow up on: https://reviews.llvm.org/D62153

Handle the case where there are multiple object files that contain
undefined references to the same function.  We only generate a function
variant if the existing symbol is directly called.

See: https://github.com/emscripten-core/emscripten/issues/8995

Subscribers: dschuff, jgravelle-google, aheejin, sunfish, llvm-commits

Tags: #llvm

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

Modified:
    lld/trunk/test/wasm/signature-mismatch-unknown.ll
    lld/trunk/wasm/SymbolTable.cpp

Modified: lld/trunk/test/wasm/signature-mismatch-unknown.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/signature-mismatch-unknown.ll?rev=370509&r1=370508&r2=370509&view=diff
==============================================================================
--- lld/trunk/test/wasm/signature-mismatch-unknown.ll (original)
+++ lld/trunk/test/wasm/signature-mismatch-unknown.ll Fri Aug 30 12:50:59 2019
@@ -3,6 +3,14 @@
 ; RUN: wasm-ld --fatal-warnings -o %t.wasm %t.ret32.o %t.main.o
 ; RUN: wasm-ld --fatal-warnings -o %t.wasm %t.main.o %t.ret32.o
 
+; Also test the case where there are two different object files that contains
+; referneces ret32:
+; %t.main.o: Does not call ret32 directly; used the wrong signature.
+; %t.call-ret32.o: Calls ret32 directly; uses the correct signature.
+; RUN: llc -filetype=obj %p/Inputs/call-ret32.ll -o %t.call-ret32.o
+; RUN: wasm-ld --export=call_ret32 --fatal-warnings -o %t.wasm %t.main.o %t.call-ret32.o %t.ret32.o
+; RUN: wasm-ld --export=call_ret32 --fatal-warnings -o %t.wasm %t.call-ret32.o %t.main.o %t.ret32.o
+
 target triple = "wasm32-unknown-unknown"
 
 ; Function declartion with incorrect signature.

Modified: lld/trunk/wasm/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/SymbolTable.cpp?rev=370509&r1=370508&r2=370509&view=diff
==============================================================================
--- lld/trunk/wasm/SymbolTable.cpp (original)
+++ lld/trunk/wasm/SymbolTable.cpp Fri Aug 30 12:50:59 2019
@@ -425,9 +425,16 @@ Symbol *SymbolTable::addUndefinedFunctio
     }
     if (!existingFunction->signature && sig)
       existingFunction->signature = sig;
-    if (isCalledDirectly && !signatureMatches(existingFunction, sig))
-      if (getFunctionVariant(s, sig, file, &s))
+    if (isCalledDirectly && !signatureMatches(existingFunction, sig)) {
+      auto* existingUndefined = dyn_cast<UndefinedFunction>(existingFunction);
+      // If the existing undefined functions is not called direcltly then let
+      // this one take precedence.  Otherwise the existing function is either
+      // direclty called or defined, in which case we need a function variant.
+      if (existingUndefined && !existingUndefined->isCalledDirectly)
         replaceSym();
+      else if (getFunctionVariant(s, sig, file, &s))
+        replaceSym();
+    }
   }
 
   return s;




More information about the llvm-commits mailing list