[lld] r361975 - [WebAssembly] Fix signatures of undefined function in LTO object which are not called directly.

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Wed May 29 08:36:42 PDT 2019


Author: sbc
Date: Wed May 29 08:36:42 2019
New Revision: 361975

URL: http://llvm.org/viewvc/llvm-project?rev=361975&view=rev
Log:
[WebAssembly] Fix signatures of undefined function in LTO object which are not called directly.

We recently added special handling for function that are not called
directly but failed to add testing for the LTO case.

See https://reviews.llvm.org/D62153

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

Modified:
    lld/trunk/test/wasm/lto/undef.ll
    lld/trunk/wasm/SymbolTable.cpp

Modified: lld/trunk/test/wasm/lto/undef.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/lto/undef.ll?rev=361975&r1=361974&r2=361975&view=diff
==============================================================================
--- lld/trunk/test/wasm/lto/undef.ll (original)
+++ lld/trunk/test/wasm/lto/undef.ll Wed May 29 08:36:42 2019
@@ -5,10 +5,22 @@
 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
 target triple = "wasm32-unknown-unknown"
 
-declare void @bar()
+declare i32 @bar()
+
+; Symbols such as foo which are only called indirectly are handled slightly
+; differently with resepect to signature checking.
+declare i32 @foo()
+
+ at ptr = global i8* bitcast (i32 ()* @foo to i8*), align 8
+; Ensure access to ptr is not inlined below, even under LTO
+ at llvm.used = appending global [1 x i8**] [i8** @ptr], section "llvm.metadata"
 
 define void @_start() {
-  call void @bar()
+  call i32 @bar()
+
+  %addr = load i32 ()*, i32 ()** bitcast (i8** @ptr to i32 ()**), align 8
+  call i32 %addr()
+
   ret void
 }
 
@@ -18,3 +30,7 @@ define void @_start() {
 ; CHECK-NEXT:        Field:           bar
 ; CHECK-NEXT:        Kind:            FUNCTION
 ; CHECK-NEXT:        SigIndex:        0
+; CHECK-NEXT:      - Module:          env
+; CHECK-NEXT:        Field:           foo
+; CHECK-NEXT:        Kind:            FUNCTION
+; CHECK-NEXT:        SigIndex:        0

Modified: lld/trunk/wasm/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/SymbolTable.cpp?rev=361975&r1=361974&r2=361975&view=diff
==============================================================================
--- lld/trunk/wasm/SymbolTable.cpp (original)
+++ lld/trunk/wasm/SymbolTable.cpp Wed May 29 08:36:42 2019
@@ -136,14 +136,13 @@ static void reportTypeError(const Symbol
 // mismatch.
 static bool signatureMatches(FunctionSymbol *Existing,
                              const WasmSignature *NewSig) {
-  if (!NewSig)
-    return true;
-
   const WasmSignature *OldSig = Existing->Signature;
-  if (!OldSig) {
-    Existing->Signature = NewSig;
+
+  // If either function is missing a signature (this happend for bitcode
+  // symbols) then assume they match.  Any mismatch will be reported later
+  // when the LTO objects are added.
+  if (!NewSig || !OldSig)
     return true;
-  }
 
   return *NewSig == *OldSig;
 }
@@ -390,8 +389,9 @@ Symbol *SymbolTable::addUndefinedFunctio
                                           uint32_t Flags, InputFile *File,
                                           const WasmSignature *Sig,
                                           bool IsCalledDirectly) {
-  LLVM_DEBUG(dbgs() << "addUndefinedFunction: " << Name <<
-             " [" << (Sig ? toString(*Sig) : "none") << "]\n");
+  LLVM_DEBUG(dbgs() << "addUndefinedFunction: " << Name << " ["
+                    << (Sig ? toString(*Sig) : "none")
+                    << "] IsCalledDirectly:" << IsCalledDirectly << "\n");
 
   Symbol *S;
   bool WasInserted;
@@ -414,6 +414,8 @@ Symbol *SymbolTable::addUndefinedFunctio
       reportTypeError(S, File, WASM_SYMBOL_TYPE_FUNCTION);
       return S;
     }
+    if (!ExistingFunction->Signature && Sig)
+      ExistingFunction->Signature = Sig;
     if (IsCalledDirectly && !signatureMatches(ExistingFunction, Sig))
       if (getFunctionVariant(S, Sig, File, &S))
         Replace();




More information about the llvm-commits mailing list