aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2024-01-13 18:09:32 +0100
committerJakub Konka <kubkon@jakubkonka.com>2024-01-24 12:34:39 +0100
commit6cdcf61a5ce193104c3c0f14189014f65bcd104d (patch)
tree46ee9a48bf658d7506b32aaad1b244dc9419b3d8 /test
parentaa50bca1516f6fc2c9d6c7ca66ef8585b4b5e197 (diff)
downloadzig-6cdcf61a5ce193104c3c0f14189014f65bcd104d.tar.gz
zig-6cdcf61a5ce193104c3c0f14189014f65bcd104d.zip
test/link/macho: upgrade and migrate dead_strip test
Diffstat (limited to 'test')
-rw-r--r--test/link.zig4
-rw-r--r--test/link/macho.zig82
-rw-r--r--test/link/macho/dead_strip/build.zig58
-rw-r--r--test/link/macho/dead_strip/main.c14
4 files changed, 82 insertions, 76 deletions
diff --git a/test/link.zig b/test/link.zig
index 49d06b80c9..a8cdfe19ad 100644
--- a/test/link.zig
+++ b/test/link.zig
@@ -108,10 +108,6 @@ pub const cases = [_]Case{
.import = @import("link/macho/bugs/16628/build.zig"),
},
.{
- .build_root = "test/link/macho/dead_strip",
- .import = @import("link/macho/dead_strip/build.zig"),
- },
- .{
.build_root = "test/link/macho/dead_strip_dylibs",
.import = @import("link/macho/dead_strip_dylibs/build.zig"),
},
diff --git a/test/link/macho.zig b/test/link/macho.zig
index d52ffc98d1..77e4531a96 100644
--- a/test/link/macho.zig
+++ b/test/link/macho.zig
@@ -8,12 +8,94 @@ pub fn testAll(b: *std.Build) *Step {
.os_tag = .macos,
});
+ macho_step.dependOn(testDeadStrip(b, .{ .target = default_target }));
macho_step.dependOn(testEntryPointDylib(b, .{ .target = default_target }));
macho_step.dependOn(testSectionBoundarySymbols(b, .{ .target = default_target }));
return macho_step;
}
+fn testDeadStrip(b: *std.Build, opts: Options) *Step {
+ const test_step = addTestStep(b, "macho-dead-strip", opts);
+
+ const obj = addObject(b, opts, .{ .name = "a", .cpp_source_bytes =
+ \\#include <stdio.h>
+ \\int two() { return 2; }
+ \\int live_var1 = 1;
+ \\int live_var2 = two();
+ \\int dead_var1 = 3;
+ \\int dead_var2 = 4;
+ \\void live_fn1() {}
+ \\void live_fn2() { live_fn1(); }
+ \\void dead_fn1() {}
+ \\void dead_fn2() { dead_fn1(); }
+ \\int main() {
+ \\ printf("%d %d\n", live_var1, live_var2);
+ \\ live_fn2();
+ \\}
+ });
+
+ {
+ const exe = addExecutable(b, opts, .{ .name = "no_dead_strip" });
+ exe.addObject(obj);
+ exe.link_gc_sections = false;
+
+ const check = exe.checkObject();
+ check.checkInSymtab();
+ check.checkContains("live_var1");
+ check.checkInSymtab();
+ check.checkContains("live_var2");
+ check.checkInSymtab();
+ check.checkContains("dead_var1");
+ check.checkInSymtab();
+ check.checkContains("dead_var2");
+ check.checkInSymtab();
+ check.checkContains("live_fn1");
+ check.checkInSymtab();
+ check.checkContains("live_fn2");
+ check.checkInSymtab();
+ check.checkContains("dead_fn1");
+ check.checkInSymtab();
+ check.checkContains("dead_fn2");
+ test_step.dependOn(&check.step);
+
+ const run = addRunArtifact(exe);
+ run.expectStdOutEqual("1 2\n");
+ test_step.dependOn(&run.step);
+ }
+
+ {
+ const exe = addExecutable(b, opts, .{ .name = "yes_dead_strip" });
+ exe.addObject(obj);
+ exe.link_gc_sections = true;
+
+ const check = exe.checkObject();
+ check.checkInSymtab();
+ check.checkContains("live_var1");
+ check.checkInSymtab();
+ check.checkContains("live_var2");
+ check.checkInSymtab();
+ check.checkNotPresent("dead_var1");
+ check.checkInSymtab();
+ check.checkNotPresent("dead_var2");
+ check.checkInSymtab();
+ check.checkContains("live_fn1");
+ check.checkInSymtab();
+ check.checkContains("live_fn2");
+ check.checkInSymtab();
+ check.checkNotPresent("dead_fn1");
+ check.checkInSymtab();
+ check.checkNotPresent("dead_fn2");
+ test_step.dependOn(&check.step);
+
+ const run = addRunArtifact(exe);
+ run.expectStdOutEqual("1 2\n");
+ test_step.dependOn(&run.step);
+ }
+
+ return test_step;
+}
+
fn testEntryPointDylib(b: *std.Build, opts: Options) *Step {
const test_step = addTestStep(b, "macho-entry-point-dylib", opts);
diff --git a/test/link/macho/dead_strip/build.zig b/test/link/macho/dead_strip/build.zig
deleted file mode 100644
index a5bb28df9f..0000000000
--- a/test/link/macho/dead_strip/build.zig
+++ /dev/null
@@ -1,58 +0,0 @@
-const std = @import("std");
-
-pub const requires_symlinks = true;
-
-pub fn build(b: *std.Build) void {
- const optimize: std.builtin.OptimizeMode = .Debug;
- const target = b.resolveTargetQuery(.{ .os_tag = .macos });
-
- const test_step = b.step("test", "Test the program");
- b.default_step = test_step;
-
- {
- // Without -dead_strip, we expect `iAmUnused` symbol present
- const exe = createScenario(b, optimize, target, "no-gc");
-
- const check = exe.checkObject();
- check.checkInSymtab();
- check.checkContains("(__TEXT,__text) external _iAmUnused");
- test_step.dependOn(&check.step);
-
- const run = b.addRunArtifact(exe);
- run.skip_foreign_checks = true;
- run.expectStdOutEqual("Hello!\n");
- test_step.dependOn(&run.step);
- }
-
- {
- // With -dead_strip, no `iAmUnused` symbol should be present
- const exe = createScenario(b, optimize, target, "yes-gc");
- exe.link_gc_sections = true;
-
- const check = exe.checkObject();
- check.checkInSymtab();
- check.checkNotPresent("(__TEXT,__text) external _iAmUnused");
- test_step.dependOn(&check.step);
-
- const run = b.addRunArtifact(exe);
- run.skip_foreign_checks = true;
- run.expectStdOutEqual("Hello!\n");
- test_step.dependOn(&run.step);
- }
-}
-
-fn createScenario(
- b: *std.Build,
- optimize: std.builtin.OptimizeMode,
- target: std.Build.ResolvedTarget,
- name: []const u8,
-) *std.Build.Step.Compile {
- const exe = b.addExecutable(.{
- .name = name,
- .optimize = optimize,
- .target = target,
- });
- exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} });
- exe.linkLibC();
- return exe;
-}
diff --git a/test/link/macho/dead_strip/main.c b/test/link/macho/dead_strip/main.c
deleted file mode 100644
index 4756e2ca13..0000000000
--- a/test/link/macho/dead_strip/main.c
+++ /dev/null
@@ -1,14 +0,0 @@
-#include <stdio.h>
-
-void printMe() {
- printf("Hello!\n");
-}
-
-int main(int argc, char* argv[]) {
- printMe();
- return 0;
-}
-
-void iAmUnused() {
- printf("YOU SHALL NOT PASS!\n");
-}