authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-11-01 15:43:34+01:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-11-01 15:43:34+01:00
logef0df24626cc6c3cfe0b87164d481eeb26cc57fb
tree54da3ca8bd51daa0858fa00f49dcae3885647abd
parent66bcc55e0196bd43746a09a79668c7c495bd1f89
signaturelock-open Commit is signed but in an unrecognized format.

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.

5 files changed, 37 insertions(+), 0 deletions(-)

test/link.zig+5
......@@ -48,6 +48,11 @@ fn addWasmCases(cases: *tests.StandaloneContext) void {
4848 .use_emulation = true,
4949 });
5050
51 cases.addBuildFile("test/link/wasm/extern-mangle/build.zig", .{
52 .build_modes = true,
53 .requires_stage2 = true,
54 });
55
5156 cases.addBuildFile("test/link/wasm/infer-features/build.zig", .{
5257 .requires_stage2 = true,
5358 });
test/link/wasm/extern-mangle/a.zig created+1
......@@ -0,0 +1 @@
1pub extern "a" fn hello() i32;
test/link/wasm/extern-mangle/b.zig created+1
......@@ -0,0 +1 @@
1pub extern "b" fn hello() i32;
test/link/wasm/extern-mangle/build.zig created+24
......@@ -0,0 +1,24 @@
1const std = @import("std");
2const Builder = std.build.Builder;
3
4pub fn build(b: *Builder) void {
5 const mode = b.standardReleaseOptions();
6
7 const test_step = b.step("test", "Test");
8 test_step.dependOn(b.getInstallStep());
9
10 const lib = b.addSharedLibrary("lib", "lib.zig", .unversioned);
11 lib.setBuildMode(mode);
12 lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
13 lib.install();
14
15 const check_lib = lib.checkObject(.wasm);
16 check_lib.checkStart("Section import");
17 check_lib.checkNext("entries 2"); // a.hello & b.hello
18 check_lib.checkNext("module a");
19 check_lib.checkNext("name hello");
20 check_lib.checkNext("module b");
21 check_lib.checkNext("name hello");
22
23 test_step.dependOn(&check_lib.step);
24}
test/link/wasm/extern-mangle/lib.zig created+6
......@@ -0,0 +1,6 @@
1const a = @import("a.zig").hello;
2const b = @import("b.zig").hello;
3export fn foo() void {
4 _ = a();
5 _ = b();
6}