Skip to content

Commit fecfc59

Browse files
committed
[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: emscripten-core/emscripten#8995 Subscribers: dschuff, jgravelle-google, aheejin, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67015 llvm-svn: 370509
1 parent 6ccd673 commit fecfc59

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lld/test/wasm/signature-mismatch-unknown.ll

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
; RUN: wasm-ld --fatal-warnings -o %t.wasm %t.ret32.o %t.main.o
44
; RUN: wasm-ld --fatal-warnings -o %t.wasm %t.main.o %t.ret32.o
55

6+
; Also test the case where there are two different object files that contains
7+
; referneces ret32:
8+
; %t.main.o: Does not call ret32 directly; used the wrong signature.
9+
; %t.call-ret32.o: Calls ret32 directly; uses the correct signature.
10+
; RUN: llc -filetype=obj %p/Inputs/call-ret32.ll -o %t.call-ret32.o
11+
; RUN: wasm-ld --export=call_ret32 --fatal-warnings -o %t.wasm %t.main.o %t.call-ret32.o %t.ret32.o
12+
; RUN: wasm-ld --export=call_ret32 --fatal-warnings -o %t.wasm %t.call-ret32.o %t.main.o %t.ret32.o
13+
614
target triple = "wasm32-unknown-unknown"
715

816
; Function declartion with incorrect signature.

lld/wasm/SymbolTable.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,16 @@ Symbol *SymbolTable::addUndefinedFunction(StringRef name, StringRef importName,
425425
}
426426
if (!existingFunction->signature && sig)
427427
existingFunction->signature = sig;
428-
if (isCalledDirectly && !signatureMatches(existingFunction, sig))
429-
if (getFunctionVariant(s, sig, file, &s))
428+
if (isCalledDirectly && !signatureMatches(existingFunction, sig)) {
429+
auto* existingUndefined = dyn_cast<UndefinedFunction>(existingFunction);
430+
// If the existing undefined functions is not called direcltly then let
431+
// this one take precedence. Otherwise the existing function is either
432+
// direclty called or defined, in which case we need a function variant.
433+
if (existingUndefined && !existingUndefined->isCalledDirectly)
430434
replaceSym();
435+
else if (getFunctionVariant(s, sig, file, &s))
436+
replaceSym();
437+
}
431438
}
432439

433440
return s;

0 commit comments

Comments
 (0)