authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-01-14 18:25:40-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-01-15 15:11:36-08:00
log7ae2f21e2bb23cebb9d3cbfc22b5ac386a7a6235
tree4cf5d12cc7571575c6b20be8dd353ad3fdf2da23
parentb37ad5110cb66330211e930df1d1093963213c48

delete bad linker test: bss

The purpose of this test is unclear. It checks for the existence of bss section which is completely unnecessary since those zeroes can be omitted from the binary. Furthermore the code generated for __wasm_init_memory looks wrong. Finally, the CheckObject DSL is brittle, it only checks for exact matches of entire lines in an ad-hoc text format. Conclusion, it's a bad test, delete it.

4 files changed, 0 insertions(+), 112 deletions(-)

test/link/build.zig.zon-3
......@@ -24,9 +24,6 @@
2424 .wasm_basic_features = .{
2525 .path = "wasm/basic-features",
2626 },
27 .wasm_bss = .{
28 .path = "wasm/bss",
29 },
3027 .wasm_export = .{
3128 .path = "wasm/export",
3229 },
test/link/wasm/bss/build.zig deleted-91
......@@ -1,91 +0,0 @@
1const std = @import("std");
2
3pub const requires_stage2 = true;
4
5pub fn build(b: *std.Build) void {
6 const test_step = b.step("test", "Test");
7 b.default_step = test_step;
8
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
15fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.OptimizeMode, is_safe: bool) void {
16 {
17 const lib = b.addExecutable(.{
18 .name = "lib",
19 .root_module = b.createModule(.{
20 .root_source_file = b.path("lib.zig"),
21 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
22 .optimize = optimize_mode,
23 .strip = false,
24 }),
25 });
26 lib.entry = .disabled;
27 lib.use_llvm = false;
28 lib.use_lld = false;
29 // to make sure the bss segment is emitted, we must import memory
30 lib.import_memory = true;
31 lib.link_gc_sections = false;
32
33 const check_lib = lib.checkObject();
34
35 // since we import memory, make sure it exists with the correct naming
36 check_lib.checkInHeaders();
37 check_lib.checkExact("Section import");
38 check_lib.checkExact("entries 1");
39 check_lib.checkExact("module env"); // default module name is "env"
40 check_lib.checkExact("name memory"); // as per linker specification
41
42 // since we are importing memory, ensure it's not exported
43 check_lib.checkInHeaders();
44 check_lib.checkNotPresent("Section export");
45
46 // validate the name of the stack pointer
47 check_lib.checkInHeaders();
48 check_lib.checkExact("Section custom");
49 check_lib.checkExact("type data_segment");
50 check_lib.checkExact("names 1");
51 // for safe optimization modes `undefined` is stored in data instead of bss.
52 if (is_safe) {
53 check_lib.checkExact("index 0");
54 check_lib.checkExact("name .data");
55 check_lib.checkNotPresent("name .bss");
56 } else {
57 check_lib.checkExact("index 0"); // bss section always last
58 check_lib.checkExact("name .bss");
59 }
60 test_step.dependOn(&check_lib.step);
61 }
62
63 // verify zero'd declaration is stored in bss for all optimization modes.
64 {
65 const lib = b.addExecutable(.{
66 .name = "lib",
67 .root_module = b.createModule(.{
68 .root_source_file = b.path("lib2.zig"),
69 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
70 .optimize = optimize_mode,
71 .strip = false,
72 }),
73 });
74 lib.entry = .disabled;
75 lib.use_llvm = false;
76 lib.use_lld = false;
77 // to make sure the bss segment is emitted, we must import memory
78 lib.import_memory = true;
79 lib.link_gc_sections = false;
80
81 const check_lib = lib.checkObject();
82 check_lib.checkInHeaders();
83 check_lib.checkExact("Section custom");
84 check_lib.checkExact("type data_segment");
85 check_lib.checkExact("names 1");
86 check_lib.checkExact("index 0");
87 check_lib.checkExact("name .bss");
88
89 test_step.dependOn(&check_lib.step);
90 }
91}
test/link/wasm/bss/lib.zig deleted-9
......@@ -1,9 +0,0 @@
1pub var bss: u32 = undefined;
2
3fn foo() callconv(.c) u32 {
4 return bss;
5}
6
7comptime {
8 @export(&foo, .{ .name = "foo", .visibility = .hidden });
9}
test/link/wasm/bss/lib2.zig deleted-9
......@@ -1,9 +0,0 @@
1pub var bss: u32 = 0;
2
3fn foo() callconv(.c) u32 {
4 return bss;
5}
6
7comptime {
8 @export(&foo, .{ .name = "foo", .visibility = .hidden });
9}