[lld] [lld][WebAssembly] Improve import mismatch error reporting (PR #178715)
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 29 10:10:46 PST 2026
https://github.com/sbc100 created https://github.com/llvm/llvm-project/pull/178715
Followup to #178550
>From 9e89c6c0deb5c097f868df212c4f4f7239ef3d0c Mon Sep 17 00:00:00 2001
From: Sam Clegg <sbc at chromium.org>
Date: Thu, 29 Jan 2026 09:43:10 -0800
Subject: [PATCH] [lld][WebAssembly] Improve import mismatch error reporting
Followup to #178550
---
lld/test/wasm/Inputs/import-attributes.s | 9 ----
lld/test/wasm/import-attribute-mismatch.s | 57 +++++++++++++++++++----
lld/wasm/SymbolTable.cpp | 6 +--
3 files changed, 52 insertions(+), 20 deletions(-)
delete mode 100644 lld/test/wasm/Inputs/import-attributes.s
diff --git a/lld/test/wasm/Inputs/import-attributes.s b/lld/test/wasm/Inputs/import-attributes.s
deleted file mode 100644
index 031d472a2e20d..0000000000000
--- a/lld/test/wasm/Inputs/import-attributes.s
+++ /dev/null
@@ -1,9 +0,0 @@
-.functype foo () -> ()
-
- .globl call_foo
-call_foo:
- .functype call_foo () -> ()
- call foo
- end_function
-
- .import_module foo, baz
diff --git a/lld/test/wasm/import-attribute-mismatch.s b/lld/test/wasm/import-attribute-mismatch.s
index 59988dc62f087..81ad8fef322ff 100644
--- a/lld/test/wasm/import-attribute-mismatch.s
+++ b/lld/test/wasm/import-attribute-mismatch.s
@@ -1,17 +1,58 @@
-# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t1.o %s
-# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %S/Inputs/import-attributes.s -o %t2.o
-# RUN: not wasm-ld --export call_foo --allow-undefined -o %t.wasm %t1.o %t2.o 2>&1 | FileCheck %s
+# RUN: split-file %s %t
+# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -mattr=+reference-types -mattr=+exception-handling -o %t/main.o %t/main.s
+# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -mattr=+reference-types -mattr=+exception-handling -o %t/other.o %t/other.s
+# RUN: not wasm-ld --export call_foo --allow-undefined -o %t.wasm %t/main.o %t/other.o 2>&1 | FileCheck %s
+
+#--- main.s
.functype foo () -> ()
+.tabletype mytable, funcref
+.globaltype myglobal, i32
+.globaltype myglobal, i32
+.tagtype mytag i32
- .globl _start
+.globl _start
_start:
.functype _start () -> ()
- call foo
+ i32.const foo
+ call_indirect mytable, () -> ()
+ global.get myglobal
+ throw mytag
end_function
-.import_module foo, bar
+#--- other.s
+
+.functype foo () -> ()
+.globaltype myglobal, i32
+.tabletype mytable, funcref
+.tagtype mytag i32
+
+.globl call_foo
+call_foo:
+ .functype call_foo () -> ()
+ i32.const foo
+ call_indirect mytable, () -> ()
+ global.get myglobal
+ throw mytag
+ end_function
+
+.import_module foo, mod1
+.import_module mytable, mod2
+.import_module myglobal, mod3
+.import_module mytag, mod4
# CHECK: wasm-ld: error: import module mismatch for symbol: foo
-# CHECK: >>> defined as bar in {{.*}}1.o
-# CHECK: >>> defined as baz in {{.*}}2.o
+# CHECK-NEXT: >>> defined as env in {{.*}}main.o
+# CHECK-NEXT: >>> defined as mod1 in {{.*}}other.o
+
+# CHECK: wasm-ld: error: import module mismatch for symbol: mytable
+# CHECK-NEXT: >>> defined as env in {{.*}}main.o
+# CHECK-NEXT: >>> defined as mod2 in {{.*}}other.o
+
+# CHECK: wasm-ld: error: import module mismatch for symbol: myglobal
+# CHECK-NEXT: >>> defined as env in {{.*}}main.o
+# CHECK-NEXT: >>> defined as mod3 in {{.*}}other.o
+
+# CHECK: wasm-ld: error: import module mismatch for symbol: mytag
+# CHECK-NEXT: >>> defined as env in {{.*}}main.o
+# CHECK-NEXT: >>> defined as mod4 in {{.*}}other.o
diff --git a/lld/wasm/SymbolTable.cpp b/lld/wasm/SymbolTable.cpp
index 33a68b5defd72..cd74073bb6e37 100644
--- a/lld/wasm/SymbolTable.cpp
+++ b/lld/wasm/SymbolTable.cpp
@@ -736,7 +736,7 @@ Symbol *SymbolTable::addUndefinedGlobal(StringRef name,
else if (s->isDefined())
checkGlobalType(s, file, type);
else
- updateExistingUndefined(s, flags, file);
+ updateExistingUndefined(s, flags, file, importName, importModule);
return s;
}
@@ -762,7 +762,7 @@ Symbol *SymbolTable::addUndefinedTable(StringRef name,
else if (s->isDefined())
checkTableType(s, file, type);
else
- updateExistingUndefined(s, flags, file);
+ updateExistingUndefined(s, flags, file, importName, importModule);
return s;
}
@@ -788,7 +788,7 @@ Symbol *SymbolTable::addUndefinedTag(StringRef name,
else if (s->isDefined())
checkTagType(s, file, sig);
else
- updateExistingUndefined(s, flags, file);
+ updateExistingUndefined(s, flags, file, importName, importModule);
return s;
}
More information about the llvm-commits
mailing list