aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuuk de Gram <luuk@degram.dev>2022-11-01 15:43:34 +0100
committerLuuk de Gram <luuk@degram.dev>2022-11-01 15:43:34 +0100
commitef0df24626cc6c3cfe0b87164d481eeb26cc57fb (patch)
tree54da3ca8bd51daa0858fa00f49dcae3885647abd
parent66bcc55e0196bd43746a09a79668c7c495bd1f89 (diff)
downloadzig-ef0df24626cc6c3cfe0b87164d481eeb26cc57fb.tar.gz
zig-ef0df24626cc6c3cfe0b87164d481eeb26cc57fb.zip
test/link: add linker test to verify mangling
This adds a simple linker test to ensure the built library contains an import entry for each extern function call that was mangled.
-rw-r--r--test/link.zig5
-rw-r--r--test/link/wasm/extern-mangle/a.zig1
-rw-r--r--test/link/wasm/extern-mangle/b.zig1
-rw-r--r--test/link/wasm/extern-mangle/build.zig24
-rw-r--r--test/link/wasm/extern-mangle/lib.zig6
5 files changed, 37 insertions, 0 deletions
diff --git a/test/link.zig b/test/link.zig
index 40635b86a0..c94dc2f4a0 100644
--- a/test/link.zig
+++ b/test/link.zig
@@ -48,6 +48,11 @@ fn addWasmCases(cases: *tests.StandaloneContext) void {
.use_emulation = true,
});
+ cases.addBuildFile("test/link/wasm/extern-mangle/build.zig", .{
+ .build_modes = true,
+ .requires_stage2 = true,
+ });
+
cases.addBuildFile("test/link/wasm/infer-features/build.zig", .{
.requires_stage2 = true,
});
diff --git a/test/link/wasm/extern-mangle/a.zig b/test/link/wasm/extern-mangle/a.zig
new file mode 100644
index 0000000000..98ff08774c
--- /dev/null
+++ b/test/link/wasm/extern-mangle/a.zig
@@ -0,0 +1 @@
+pub extern "a" fn hello() i32;
diff --git a/test/link/wasm/extern-mangle/b.zig b/test/link/wasm/extern-mangle/b.zig
new file mode 100644
index 0000000000..06dfb5b79f
--- /dev/null
+++ b/test/link/wasm/extern-mangle/b.zig
@@ -0,0 +1 @@
+pub extern "b" fn hello() i32;
diff --git a/test/link/wasm/extern-mangle/build.zig b/test/link/wasm/extern-mangle/build.zig
new file mode 100644
index 0000000000..f2916c35a7
--- /dev/null
+++ b/test/link/wasm/extern-mangle/build.zig
@@ -0,0 +1,24 @@
+const std = @import("std");
+const Builder = std.build.Builder;
+
+pub fn build(b: *Builder) void {
+ const mode = b.standardReleaseOptions();
+
+ const test_step = b.step("test", "Test");
+ test_step.dependOn(b.getInstallStep());
+
+ const lib = b.addSharedLibrary("lib", "lib.zig", .unversioned);
+ lib.setBuildMode(mode);
+ lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
+ lib.install();
+
+ const check_lib = lib.checkObject(.wasm);
+ check_lib.checkStart("Section import");
+ check_lib.checkNext("entries 2"); // a.hello & b.hello
+ check_lib.checkNext("module a");
+ check_lib.checkNext("name hello");
+ check_lib.checkNext("module b");
+ check_lib.checkNext("name hello");
+
+ test_step.dependOn(&check_lib.step);
+}
diff --git a/test/link/wasm/extern-mangle/lib.zig b/test/link/wasm/extern-mangle/lib.zig
new file mode 100644
index 0000000000..d2f2126c7c
--- /dev/null
+++ b/test/link/wasm/extern-mangle/lib.zig
@@ -0,0 +1,6 @@
+const a = @import("a.zig").hello;
+const b = @import("b.zig").hello;
+export fn foo() void {
+ _ = a();
+ _ = b();
+}