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 {...@@ -4,48 +4,24 @@ pub fn build(b: *std.Build) void {
4 const test_step = b.step("test", "Test");4 const test_step = b.step("test", "Test");
5 b.default_step = test_step;5 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
12 const lib = b.addExecutable(.{7 const lib = b.addExecutable(.{
13 .name = "lib",8 .name = "lib",
14 .root_module = b.createModule(.{9 .root_module = b.createModule(.{
15 .root_source_file = b.path("lib.zig"),10 .root_source_file = b.path("lib.zig"),
16 .optimize = .ReleaseSafe, // to make the output deterministic in address positions11 .optimize = .Debug,
17 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),12 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
18 }),13 }),
19 });14 });
20 lib.entry = .disabled;15 lib.entry = .disabled;
21 lib.use_lld = false;16 lib.use_lld = false;
22 lib.root_module.export_symbol_names = &.{ "foo", "bar" };17 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 parse18 // Object being linked has neither functions nor globals named "foo" or "bar" and
2419 // so these names correctly fail to be exported when creating an executable.
25 const check_lib = lib.checkObject();20 lib.expect_errors = .{ .exact = &.{
2621 "error: manually specified export name 'foo' undefined",
27 check_lib.checkInHeaders();22 "error: manually specified export name 'bar' undefined",
28 check_lib.checkExact("Section global");23 } };
29 check_lib.checkExact("entries 3");24 _ = lib.getEmittedBin();
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");
4925
50 test_step.dependOn(&check_lib.step);26 test_step.dependOn(&lib.step);
51}27}