authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-01-14 20:52:44-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-01-15 15:11:37-08:00
log42602dc96bcc0c10d5fe04e24c47f67dd7e27d32
tree31f4fa41632931eae69cb2776bf602d2653e7ea1
parent50d053f31c8fc391be613b27e4971ee85a418e5b

test/link/wasm/export-data: update expected behavior

Object being linked has neither functions nor globals named "foo" or "bar" and so these names correctly fail to be exported when creating an executable.

1 files changed, 9 insertions(+), 33 deletions(-)

test/link/wasm/export-data/build.zig+9-33
......@@ -4,48 +4,24 @@ pub fn build(b: *std.Build) void {
44 const test_step = b.step("test", "Test");
55 b.default_step = test_step;
66
7 if (@import("builtin").os.tag == .windows) {
8 // TODO: Fix open handle in wasm-linker refraining rename from working on Windows.
9 return;
10 }
11
127 const lib = b.addExecutable(.{
138 .name = "lib",
149 .root_module = b.createModule(.{
1510 .root_source_file = b.path("lib.zig"),
16 .optimize = .ReleaseSafe, // to make the output deterministic in address positions
11 .optimize = .Debug,
1712 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
1813 }),
1914 });
2015 lib.entry = .disabled;
2116 lib.use_lld = false;
2217 lib.root_module.export_symbol_names = &.{ "foo", "bar" };
23 lib.global_base = 0; // put data section at address 0 to make data symbols easier to parse
24
25 const check_lib = lib.checkObject();
26
27 check_lib.checkInHeaders();
28 check_lib.checkExact("Section global");
29 check_lib.checkExact("entries 3");
30 check_lib.checkExact("type i32"); // stack pointer so skip other fields
31 check_lib.checkExact("type i32");
32 check_lib.checkExact("mutable false");
33 check_lib.checkExtract("i32.const {foo_address}");
34 check_lib.checkExact("type i32");
35 check_lib.checkExact("mutable false");
36 check_lib.checkExtract("i32.const {bar_address}");
37 check_lib.checkComputeCompare("foo_address", .{ .op = .eq, .value = .{ .literal = 4 } });
38 check_lib.checkComputeCompare("bar_address", .{ .op = .eq, .value = .{ .literal = 0 } });
39
40 check_lib.checkInHeaders();
41 check_lib.checkExact("Section export");
42 check_lib.checkExact("entries 3");
43 check_lib.checkExact("name foo");
44 check_lib.checkExact("kind global");
45 check_lib.checkExact("index 1");
46 check_lib.checkExact("name bar");
47 check_lib.checkExact("kind global");
48 check_lib.checkExact("index 2");
18 // Object being linked has neither functions nor globals named "foo" or "bar" and
19 // so these names correctly fail to be exported when creating an executable.
20 lib.expect_errors = .{ .exact = &.{
21 "error: manually specified export name 'foo' undefined",
22 "error: manually specified export name 'bar' undefined",
23 } };
24 _ = lib.getEmittedBin();
4925
50 test_step.dependOn(&check_lib.step);
26 test_step.dependOn(&lib.step);
5127}