diff --git a/lld/test/wasm/lto/thinlto-signature-mismatch-unknown.ll b/lld/test/wasm/lto/thinlto-signature-mismatch-unknown.ll new file mode 100644 index 0000000000000..2f216e5853ff8 --- /dev/null +++ b/lld/test/wasm/lto/thinlto-signature-mismatch-unknown.ll @@ -0,0 +1,45 @@ +; RUN: rm -rf %t && split-file %s %t && cd %t +; RUN: opt -thinlto-bc a.ll -o a.o +; RUN: opt -thinlto-bc b.ll -o b.o +; RUN: llvm-ar rcs b.a b.o +; RUN: opt -thinlto-bc c.ll -o c.o + +;; Taking the address of the incorrectly declared @foo should not generate a warning. +; RUN: wasm-ld --fatal-warnings --no-entry --export-all a.o b.a -o a.out \ +; RUN: | FileCheck %s --implicit-check-not 'warning' --allow-empty + +;; But we should still warn if we call the function with the wrong signature. +; RUN: not wasm-ld --fatal-warnings --no-entry --export-all a.o b.a c.o -o b.out 2>&1 \ +; RUN: | FileCheck %s --check-prefix=INVALID + +; INVALID: error: function signature mismatch: foo +; INVALID: >>> defined as () -> void +; INVALID: >>> defined as () -> i32 + +;--- a.ll +target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" +target triple = "wasm32-unknown-unknown" + +@ptr = constant ptr @foo +declare void @foo() + +;--- b.ll +target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" +target triple = "wasm32-unknown-unknown" + +define i32 @foo() noinline { +entry: + ret i32 42 +} + +;--- c.ll +target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" +target triple = "wasm32-unknown-unknown" + +declare void @foo() + +define void @invalid() { +entry: + call void @foo() + ret void +} diff --git a/lld/wasm/LTO.cpp b/lld/wasm/LTO.cpp index b9bd48acd6dc1..ab63281012eae 100644 --- a/lld/wasm/LTO.cpp +++ b/lld/wasm/LTO.cpp @@ -108,9 +108,10 @@ BitcodeCompiler::~BitcodeCompiler() = default; static void undefine(Symbol *s) { if (auto f = dyn_cast(s)) + // If the signature is null, there were no calls from non-bitcode objects. replaceSymbol(f, f->getName(), std::nullopt, std::nullopt, 0, f->getFile(), - f->signature); + f->signature, f->signature != nullptr); else if (isa(s)) replaceSymbol(s, s->getName(), 0, s->getFile()); else