diff options
-rw-r--r-- | lld/test/wasm/signature-mismatch-unknown.ll | 8 | ||||
-rw-r--r-- | lld/wasm/SymbolTable.cpp | 11 |
2 files changed, 17 insertions, 2 deletions
diff --git a/lld/test/wasm/signature-mismatch-unknown.ll b/lld/test/wasm/signature-mismatch-unknown.ll index 65bb31511d1..9bd97db50f1 100644 --- a/lld/test/wasm/signature-mismatch-unknown.ll +++ b/lld/test/wasm/signature-mismatch-unknown.ll @@ -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. diff --git a/lld/wasm/SymbolTable.cpp b/lld/wasm/SymbolTable.cpp index c46eec41146..44417b076c7 100644 --- a/lld/wasm/SymbolTable.cpp +++ b/lld/wasm/SymbolTable.cpp @@ -425,9 +425,16 @@ Symbol *SymbolTable::addUndefinedFunction(StringRef name, StringRef importName, } 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; |