From f9b3e8c762450c20a13c3f51ab91398f409781fb Mon Sep 17 00:00:00 2001 From: Luuk de Gram Date: Sun, 1 Jan 2023 17:13:12 +0100 Subject: [PATCH] test/link: add test case for exporting data syms --- test/link.zig | 4 +++ test/link/wasm/export-data/build.zig | 41 ++++++++++++++++++++++++++++ test/link/wasm/export-data/lib.zig | 2 ++ 3 files changed, 47 insertions(+) create mode 100644 test/link/wasm/export-data/build.zig create mode 100644 test/link/wasm/export-data/lib.zig diff --git a/test/link.zig b/test/link.zig index 124a30a3b6..2fe62b8068 100644 --- a/test/link.zig +++ b/test/link.zig @@ -47,6 +47,10 @@ fn addWasmCases(cases: *tests.StandaloneContext) void { .requires_stage2 = true, }); + cases.addBuildFile("test/link/wasm/export-data/build.zig", .{ + .build_modes = true, + }); + cases.addBuildFile("test/link/wasm/extern/build.zig", .{ .build_modes = true, .requires_stage2 = true, diff --git a/test/link/wasm/export-data/build.zig b/test/link/wasm/export-data/build.zig new file mode 100644 index 0000000000..3df5c1790c --- /dev/null +++ b/test/link/wasm/export-data/build.zig @@ -0,0 +1,41 @@ +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.use_lld = false; + lib.export_symbol_names = &.{ "foo", "bar" }; + lib.global_base = 0; // put data section at address 0 to make data symbols easier to parse + + const check_lib = lib.checkObject(.wasm); + + check_lib.checkStart("Section global"); + check_lib.checkNext("entries 3"); + check_lib.checkNext("type i32"); // stack pointer so skip other fields + check_lib.checkNext("type i32"); + check_lib.checkNext("mutable false"); + check_lib.checkNext("i32.const {foo_address}"); + check_lib.checkNext("type i32"); + check_lib.checkNext("mutable false"); + check_lib.checkNext("i32.const {bar_address}"); + check_lib.checkComputeCompare("foo_address", .{ .op = .eq, .value = .{ .literal = 0x0c } }); + check_lib.checkComputeCompare("bar_address", .{ .op = .eq, .value = .{ .literal = 0x10 } }); + + check_lib.checkStart("Section export"); + check_lib.checkNext("entries 3"); + check_lib.checkNext("name foo"); + check_lib.checkNext("kind global"); + check_lib.checkNext("index 1"); + check_lib.checkNext("name bar"); + check_lib.checkNext("kind global"); + check_lib.checkNext("index 2"); + + test_step.dependOn(&check_lib.step); +} diff --git a/test/link/wasm/export-data/lib.zig b/test/link/wasm/export-data/lib.zig new file mode 100644 index 0000000000..dffce185fa --- /dev/null +++ b/test/link/wasm/export-data/lib.zig @@ -0,0 +1,2 @@ +export const foo: u32 = 0xbbbbbbbb; +export const bar: u32 = 0xbbbbbbbb;