| ... | ... | @@ -6,38 +6,78 @@ pub fn build(b: *std.Build) void { |
| 6 | 6 | const test_step = b.step("test", "Test"); |
| 7 | 7 | b.default_step = test_step; |
| 8 | 8 | |
| 9 | | const lib = b.addSharedLibrary(.{ |
| 10 | | .name = "lib", |
| 11 | | .root_source_file = .{ .path = "lib.zig" }, |
| 12 | | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, |
| 13 | | .optimize = .Debug, |
| 14 | | }); |
| 15 | | lib.use_llvm = false; |
| 16 | | lib.use_lld = false; |
| 17 | | lib.strip = false; |
| 18 | | // to make sure the bss segment is emitted, we must import memory |
| 19 | | lib.import_memory = true; |
| 20 | | lib.install(); |
| 21 | | |
| 22 | | const check_lib = lib.checkObject(); |
| 23 | | |
| 24 | | // since we import memory, make sure it exists with the correct naming |
| 25 | | check_lib.checkStart("Section import"); |
| 26 | | check_lib.checkNext("entries 1"); |
| 27 | | check_lib.checkNext("module env"); // default module name is "env" |
| 28 | | check_lib.checkNext("name memory"); // as per linker specification |
| 29 | | |
| 30 | | // since we are importing memory, ensure it's not exported |
| 31 | | check_lib.checkNotPresent("Section export"); |
| 32 | | |
| 33 | | // validate the name of the stack pointer |
| 34 | | check_lib.checkStart("Section custom"); |
| 35 | | check_lib.checkNext("type data_segment"); |
| 36 | | check_lib.checkNext("names 2"); |
| 37 | | check_lib.checkNext("index 0"); |
| 38 | | check_lib.checkNext("name .rodata"); |
| 39 | | check_lib.checkNext("index 1"); // bss section always last |
| 40 | | check_lib.checkNext("name .bss"); |
| 41 | | |
| 42 | | test_step.dependOn(&check_lib.step); |
| 9 | add(b, test_step, .Debug, true); |
| 10 | add(b, test_step, .ReleaseFast, false); |
| 11 | add(b, test_step, .ReleaseSmall, false); |
| 12 | add(b, test_step, .ReleaseSafe, true); |
| 13 | } |
| 14 | |
| 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.OptimizeMode, is_safe: bool) void { |
| 16 | { |
| 17 | const lib = b.addSharedLibrary(.{ |
| 18 | .name = "lib", |
| 19 | .root_source_file = .{ .path = "lib.zig" }, |
| 20 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, |
| 21 | .optimize = optimize_mode, |
| 22 | }); |
| 23 | lib.use_llvm = false; |
| 24 | lib.use_lld = false; |
| 25 | lib.strip = false; |
| 26 | // to make sure the bss segment is emitted, we must import memory |
| 27 | lib.import_memory = true; |
| 28 | |
| 29 | const check_lib = lib.checkObject(); |
| 30 | |
| 31 | // since we import memory, make sure it exists with the correct naming |
| 32 | check_lib.checkStart("Section import"); |
| 33 | check_lib.checkNext("entries 1"); |
| 34 | check_lib.checkNext("module env"); // default module name is "env" |
| 35 | check_lib.checkNext("name memory"); // as per linker specification |
| 36 | |
| 37 | // since we are importing memory, ensure it's not exported |
| 38 | check_lib.checkNotPresent("Section export"); |
| 39 | |
| 40 | // validate the name of the stack pointer |
| 41 | check_lib.checkStart("Section custom"); |
| 42 | check_lib.checkNext("type data_segment"); |
| 43 | check_lib.checkNext("names 2"); |
| 44 | check_lib.checkNext("index 0"); |
| 45 | check_lib.checkNext("name .rodata"); |
| 46 | // for safe optimization modes `undefined` is stored in data instead of bss. |
| 47 | if (is_safe) { |
| 48 | check_lib.checkNext("index 1"); |
| 49 | check_lib.checkNext("name .data"); |
| 50 | check_lib.checkNotPresent("name .bss"); |
| 51 | } else { |
| 52 | check_lib.checkNext("index 1"); // bss section always last |
| 53 | check_lib.checkNext("name .bss"); |
| 54 | } |
| 55 | test_step.dependOn(&check_lib.step); |
| 56 | } |
| 57 | |
| 58 | // verify zero'd declaration is stored in bss for all optimization modes. |
| 59 | { |
| 60 | const lib = b.addSharedLibrary(.{ |
| 61 | .name = "lib", |
| 62 | .root_source_file = .{ .path = "lib2.zig" }, |
| 63 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, |
| 64 | .optimize = optimize_mode, |
| 65 | }); |
| 66 | lib.use_llvm = false; |
| 67 | lib.use_lld = false; |
| 68 | lib.strip = false; |
| 69 | // to make sure the bss segment is emitted, we must import memory |
| 70 | lib.import_memory = true; |
| 71 | |
| 72 | const check_lib = lib.checkObject(); |
| 73 | check_lib.checkStart("Section custom"); |
| 74 | check_lib.checkNext("type data_segment"); |
| 75 | check_lib.checkNext("names 2"); |
| 76 | check_lib.checkNext("index 0"); |
| 77 | check_lib.checkNext("name .rodata"); |
| 78 | check_lib.checkNext("index 1"); |
| 79 | check_lib.checkNext("name .bss"); |
| 80 | |
| 81 | test_step.dependOn(&check_lib.step); |
| 82 | } |
| 43 | 83 | } |