mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 07:32:44 +00:00
test/link: add test case for exporting data syms
This commit is contained in:
parent
e475ddb08e
commit
f9b3e8c762
@ -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,
|
||||
|
41
test/link/wasm/export-data/build.zig
Normal file
41
test/link/wasm/export-data/build.zig
Normal 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);
|
||||
}
|
2
test/link/wasm/export-data/lib.zig
Normal file
2
test/link/wasm/export-data/lib.zig
Normal file
@ -0,0 +1,2 @@
|
||||
export const foo: u32 = 0xbbbbbbbb;
|
||||
export const bar: u32 = 0xbbbbbbbb;
|
Loading…
Reference in New Issue
Block a user