summaryrefslogtreecommitdiffstats
path: root/tests/run-make/wasm-symbols-different-module
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/run-make/wasm-symbols-different-module
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/run-make/wasm-symbols-different-module')
-rw-r--r--tests/run-make/wasm-symbols-different-module/Makefile28
-rw-r--r--tests/run-make/wasm-symbols-different-module/bar.rs33
-rw-r--r--tests/run-make/wasm-symbols-different-module/baz.rs22
-rw-r--r--tests/run-make/wasm-symbols-different-module/foo.rs23
-rw-r--r--tests/run-make/wasm-symbols-different-module/log.rs16
-rw-r--r--tests/run-make/wasm-symbols-different-module/verify-imports.js32
6 files changed, 154 insertions, 0 deletions
diff --git a/tests/run-make/wasm-symbols-different-module/Makefile b/tests/run-make/wasm-symbols-different-module/Makefile
new file mode 100644
index 000000000..9e657222d
--- /dev/null
+++ b/tests/run-make/wasm-symbols-different-module/Makefile
@@ -0,0 +1,28 @@
+include ../../run-make-fulldeps/tools.mk
+
+# only-wasm32-bare
+
+all:
+ $(RUSTC) foo.rs --target wasm32-unknown-unknown
+ $(NODE) verify-imports.js $(TMPDIR)/foo.wasm a/foo b/foo
+ $(RUSTC) foo.rs --target wasm32-unknown-unknown -C lto
+ $(NODE) verify-imports.js $(TMPDIR)/foo.wasm a/foo b/foo
+ $(RUSTC) foo.rs --target wasm32-unknown-unknown -O
+ $(NODE) verify-imports.js $(TMPDIR)/foo.wasm a/foo b/foo
+ $(RUSTC) foo.rs --target wasm32-unknown-unknown -O -C lto
+ $(NODE) verify-imports.js $(TMPDIR)/foo.wasm a/foo b/foo
+
+ $(RUSTC) bar.rs --target wasm32-unknown-unknown
+ $(NODE) verify-imports.js $(TMPDIR)/bar.wasm m1/f m1/g m2/f
+ $(RUSTC) bar.rs --target wasm32-unknown-unknown -C lto
+ $(NODE) verify-imports.js $(TMPDIR)/bar.wasm m1/f m1/g m2/f
+ $(RUSTC) bar.rs --target wasm32-unknown-unknown -O
+ $(NODE) verify-imports.js $(TMPDIR)/bar.wasm m1/f m1/g m2/f
+ $(RUSTC) bar.rs --target wasm32-unknown-unknown -O -C lto
+ $(NODE) verify-imports.js $(TMPDIR)/bar.wasm m1/f m1/g m2/f
+
+ $(RUSTC) baz.rs --target wasm32-unknown-unknown
+ $(NODE) verify-imports.js $(TMPDIR)/baz.wasm sqlite/allocate sqlite/deallocate
+
+ $(RUSTC) log.rs --target wasm32-unknown-unknown
+ $(NODE) verify-imports.js $(TMPDIR)/log.wasm test/log
diff --git a/tests/run-make/wasm-symbols-different-module/bar.rs b/tests/run-make/wasm-symbols-different-module/bar.rs
new file mode 100644
index 000000000..7567060d7
--- /dev/null
+++ b/tests/run-make/wasm-symbols-different-module/bar.rs
@@ -0,0 +1,33 @@
+//! Issue #50021
+
+#![crate_type = "cdylib"]
+
+mod m1 {
+ #[link(wasm_import_module = "m1")]
+ extern "C" {
+ pub fn f();
+ }
+ #[link(wasm_import_module = "m1")]
+ extern "C" {
+ pub fn g();
+ }
+}
+
+mod m2 {
+ #[link(wasm_import_module = "m2")]
+ extern "C" {
+ pub fn f(_: i32);
+ }
+}
+
+#[no_mangle]
+pub unsafe fn run() {
+ m1::f();
+ m1::g();
+
+ // In generated code, expected:
+ // (import "m2" "f" (func $f (param i32)))
+ // but got:
+ // (import "m1" "f" (func $f (param i32)))
+ m2::f(0);
+}
diff --git a/tests/run-make/wasm-symbols-different-module/baz.rs b/tests/run-make/wasm-symbols-different-module/baz.rs
new file mode 100644
index 000000000..fbb78619b
--- /dev/null
+++ b/tests/run-make/wasm-symbols-different-module/baz.rs
@@ -0,0 +1,22 @@
+//! Issue #63562
+
+#![crate_type = "cdylib"]
+
+mod foo {
+ #[link(wasm_import_module = "sqlite")]
+ extern "C" {
+ pub fn allocate(size: usize) -> i32;
+ pub fn deallocate(ptr: i32, size: usize);
+ }
+}
+
+#[no_mangle]
+pub extern "C" fn allocate() {
+ unsafe {
+ foo::allocate(1);
+ foo::deallocate(1, 2);
+ }
+}
+
+#[no_mangle]
+pub extern "C" fn deallocate() {}
diff --git a/tests/run-make/wasm-symbols-different-module/foo.rs b/tests/run-make/wasm-symbols-different-module/foo.rs
new file mode 100644
index 000000000..a4ba7e714
--- /dev/null
+++ b/tests/run-make/wasm-symbols-different-module/foo.rs
@@ -0,0 +1,23 @@
+#![crate_type = "cdylib"]
+
+mod a {
+ #[link(wasm_import_module = "a")]
+ extern "C" {
+ pub fn foo();
+ }
+}
+
+mod b {
+ #[link(wasm_import_module = "b")]
+ extern "C" {
+ pub fn foo();
+ }
+}
+
+#[no_mangle]
+pub fn start() {
+ unsafe {
+ a::foo();
+ b::foo();
+ }
+}
diff --git a/tests/run-make/wasm-symbols-different-module/log.rs b/tests/run-make/wasm-symbols-different-module/log.rs
new file mode 100644
index 000000000..ea3e0b4b2
--- /dev/null
+++ b/tests/run-make/wasm-symbols-different-module/log.rs
@@ -0,0 +1,16 @@
+//! Issue #56309
+
+#![crate_type = "cdylib"]
+
+#[link(wasm_import_module = "test")]
+extern "C" {
+ fn log(message_data: u32, message_size: u32);
+}
+
+#[no_mangle]
+pub fn main() {
+ let message = "Hello, world!";
+ unsafe {
+ log(message.as_ptr() as u32, message.len() as u32);
+ }
+}
diff --git a/tests/run-make/wasm-symbols-different-module/verify-imports.js b/tests/run-make/wasm-symbols-different-module/verify-imports.js
new file mode 100644
index 000000000..7e9f90cf8
--- /dev/null
+++ b/tests/run-make/wasm-symbols-different-module/verify-imports.js
@@ -0,0 +1,32 @@
+const fs = require('fs');
+const process = require('process');
+const assert = require('assert');
+const buffer = fs.readFileSync(process.argv[2]);
+
+let m = new WebAssembly.Module(buffer);
+let list = WebAssembly.Module.imports(m);
+console.log('imports', list);
+if (list.length !== process.argv.length - 3)
+ throw new Error("wrong number of imports")
+
+const imports = new Map();
+for (let i = 3; i < process.argv.length; i++) {
+ const [module, name] = process.argv[i].split('/');
+ if (!imports.has(module))
+ imports.set(module, new Map());
+ imports.get(module).set(name, true);
+}
+
+for (let i of list) {
+ if (imports.get(i.module) === undefined || imports.get(i.module).get(i.name) === undefined)
+ throw new Error(`didn't find import of ${i.module}::${i.name}`);
+ imports.get(i.module).delete(i.name);
+
+ if (imports.get(i.module).size === 0)
+ imports.delete(i.module);
+}
+
+console.log(imports);
+if (imports.size !== 0) {
+ throw new Error('extra imports');
+}