test/link: add test case for exporting data syms

This commit is contained in:
Luuk de Gram 2023-01-01 17:13:12 +01:00
parent e475ddb08e
commit f9b3e8c762
No known key found for this signature in database
GPG Key ID: A8CFE58E4DC7D664
3 changed files with 47 additions and 0 deletions

View File

@ -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,

View File

@ -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);
}

View File

@ -0,0 +1,2 @@
export const foo: u32 = 0xbbbbbbbb;
export const bar: u32 = 0xbbbbbbbb;