Skip to content

Commit f9b3e8c

Browse files
committed
test/link: add test case for exporting data syms
1 parent e475ddb commit f9b3e8c

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

test/link.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ fn addWasmCases(cases: *tests.StandaloneContext) void {
4747
.requires_stage2 = true,
4848
});
4949

50+
cases.addBuildFile("test/link/wasm/export-data/build.zig", .{
51+
.build_modes = true,
52+
});
53+
5054
cases.addBuildFile("test/link/wasm/extern/build.zig", .{
5155
.build_modes = true,
5256
.requires_stage2 = true,
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const std = @import("std");
2+
const Builder = std.build.Builder;
3+
4+
pub 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.use_lld = false;
14+
lib.export_symbol_names = &.{ "foo", "bar" };
15+
lib.global_base = 0; // put data section at address 0 to make data symbols easier to parse
16+
17+
const check_lib = lib.checkObject(.wasm);
18+
19+
check_lib.checkStart("Section global");
20+
check_lib.checkNext("entries 3");
21+
check_lib.checkNext("type i32"); // stack pointer so skip other fields
22+
check_lib.checkNext("type i32");
23+
check_lib.checkNext("mutable false");
24+
check_lib.checkNext("i32.const {foo_address}");
25+
check_lib.checkNext("type i32");
26+
check_lib.checkNext("mutable false");
27+
check_lib.checkNext("i32.const {bar_address}");
28+
check_lib.checkComputeCompare("foo_address", .{ .op = .eq, .value = .{ .literal = 0x0c } });
29+
check_lib.checkComputeCompare("bar_address", .{ .op = .eq, .value = .{ .literal = 0x10 } });
30+
31+
check_lib.checkStart("Section export");
32+
check_lib.checkNext("entries 3");
33+
check_lib.checkNext("name foo");
34+
check_lib.checkNext("kind global");
35+
check_lib.checkNext("index 1");
36+
check_lib.checkNext("name bar");
37+
check_lib.checkNext("kind global");
38+
check_lib.checkNext("index 2");
39+
40+
test_step.dependOn(&check_lib.step);
41+
}

test/link/wasm/export-data/lib.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const foo: u32 = 0xbbbbbbbb;
2+
export const bar: u32 = 0xbbbbbbbb;

0 commit comments

Comments
 (0)