[PATCH] D50721: [WebAssembly] Preserve function signatures during LTO

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 28 09:51:53 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL343340: [WebAssembly] Preserve function signatures during LTO (authored by sbc, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D50721

Files:
  lld/trunk/test/wasm/lto/signature-mismatch.ll
  lld/trunk/wasm/LTO.cpp
  lld/trunk/wasm/SymbolTable.cpp


Index: lld/trunk/test/wasm/lto/signature-mismatch.ll
===================================================================
--- lld/trunk/test/wasm/lto/signature-mismatch.ll
+++ lld/trunk/test/wasm/lto/signature-mismatch.ll
@@ -0,0 +1,19 @@
+; RUN: llc -filetype=obj -o %t.o %s
+; RUN: llvm-as %S/Inputs/archive.ll -o %t1.o
+; RUN: not wasm-ld --fatal-warnings %t.o %t1.o -o %t.wasm 2>&1 | FileCheck %s
+
+; Test that functions defined in bitcode correctly report signature
+; mistmaches with existing undefined sybmols in normal objects.
+
+target triple = "wasm32-unknown-unknown"
+
+; f is defined to take no argument in archive.ll which is compiled to bitcode
+declare void @f(i32);
+
+define void @_start() {
+  call void @f(i32 0)
+  ret void
+}
+
+; CHECK: >>> defined as (I32) -> void in {{.*}}signature-mismatch.ll.tmp1.o
+; CHECK: >>> defined as () -> void in lto.tmp
Index: lld/trunk/wasm/SymbolTable.cpp
===================================================================
--- lld/trunk/wasm/SymbolTable.cpp
+++ lld/trunk/wasm/SymbolTable.cpp
@@ -201,7 +201,9 @@
 Symbol *SymbolTable::addDefinedFunction(StringRef Name, uint32_t Flags,
                                         InputFile *File,
                                         InputFunction *Function) {
-  LLVM_DEBUG(dbgs() << "addDefinedFunction: " << Name << "\n");
+  LLVM_DEBUG(dbgs() << "addDefinedFunction: " << Name << " ["
+                    << (Function ? toString(Function->Signature) : "none")
+                    << "]\n");
   Symbol *S;
   bool WasInserted;
   std::tie(S, WasInserted) = insert(Name, File);
@@ -214,8 +216,16 @@
   if (Function)
     checkFunctionType(S, File, &Function->Signature);
 
-  if (shouldReplace(S, File, Flags))
-    replaceSymbol<DefinedFunction>(S, Name, Flags, File, Function);
+  if (shouldReplace(S, File, Flags)) {
+    // If the new defined function doesn't have signture (i.e. bitcode
+    // functions) but the old symbols does then preserve the old signature
+    const WasmSignature *OldSig = nullptr;
+    if (auto* F = dyn_cast<FunctionSymbol>(S))
+      OldSig = F->FunctionType;
+    auto NewSym = replaceSymbol<DefinedFunction>(S, Name, Flags, File, Function);
+    if (!NewSym->FunctionType)
+      NewSym->FunctionType = OldSig;
+  }
   return S;
 }
 
@@ -263,7 +273,8 @@
 Symbol *SymbolTable::addUndefinedFunction(StringRef Name, uint32_t Flags,
                                           InputFile *File,
                                           const WasmSignature *Sig) {
-  LLVM_DEBUG(dbgs() << "addUndefinedFunction: " << Name << "\n");
+  LLVM_DEBUG(dbgs() << "addUndefinedFunction: " << Name <<
+             " [" << (Sig ? toString(*Sig) : "none") << "]\n");
 
   Symbol *S;
   bool WasInserted;
Index: lld/trunk/wasm/LTO.cpp
===================================================================
--- lld/trunk/wasm/LTO.cpp
+++ lld/trunk/wasm/LTO.cpp
@@ -72,10 +72,11 @@
 BitcodeCompiler::~BitcodeCompiler() = default;
 
 static void undefine(Symbol *S) {
-  if (isa<DefinedFunction>(S))
-    replaceSymbol<UndefinedFunction>(S, S->getName(), 0);
+  if (auto F = dyn_cast<DefinedFunction>(S))
+    replaceSymbol<UndefinedFunction>(F, F->getName(), 0, F->getFile(),
+                                     F->FunctionType);
   else if (isa<DefinedData>(S))
-    replaceSymbol<UndefinedData>(S, S->getName(), 0);
+    replaceSymbol<UndefinedData>(S, S->getName(), 0, S->getFile());
   else
     llvm_unreachable("unexpected symbol kind");
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50721.167504.patch
Type: text/x-patch
Size: 3476 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180928/ad0200f2/attachment-0001.bin>


More information about the llvm-commits mailing list