Skip to content

Commit

Permalink
test/link: add linker test to verify mangling
Browse files Browse the repository at this point in the history
This adds a simple linker test to ensure the built library contains
an import entry for each extern function call that was mangled.
  • Loading branch information
Luukdegram committed Nov 1, 2022
1 parent 66bcc55 commit ef0df24
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/link.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
1 change: 1 addition & 0 deletions test/link/wasm/extern-mangle/a.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub extern "a" fn hello() i32;
1 change: 1 addition & 0 deletions test/link/wasm/extern-mangle/b.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub extern "b" fn hello() i32;
24 changes: 24 additions & 0 deletions test/link/wasm/extern-mangle/build.zig
Original file line number Diff line number Diff line change
@@ -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);
}
6 changes: 6 additions & 0 deletions test/link/wasm/extern-mangle/lib.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const a = @import("a.zig").hello;
const b = @import("b.zig").hello;
export fn foo() void {
_ = a();
_ = b();
}

0 comments on commit ef0df24

Please sign in to comment.