diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2024-01-15 10:14:39 +0100 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2024-01-24 12:34:40 +0100 |
| commit | a25b780aad5df41bc97ce8ffc700917208be820b (patch) | |
| tree | b31da546c8760eaceb3a1e724fbc5e1be7b7590f | |
| parent | 82a044f4f7997dbbb43d1aa7f8ba956328380371 (diff) | |
| download | zig-a25b780aad5df41bc97ce8ffc700917208be820b.tar.gz zig-a25b780aad5df41bc97ce8ffc700917208be820b.zip | |
test/link/macho: upgrade entry and entry in archive tests
| -rw-r--r-- | test/link.zig | 8 | ||||
| -rw-r--r-- | test/link/macho.zig | 62 | ||||
| -rw-r--r-- | test/link/macho/entry/build.zig | 45 | ||||
| -rw-r--r-- | test/link/macho/entry/main.c | 6 | ||||
| -rw-r--r-- | test/link/macho/entry_in_archive/build.zig | 36 | ||||
| -rw-r--r-- | test/link/macho/entry_in_archive/main.c | 5 |
6 files changed, 61 insertions, 101 deletions
diff --git a/test/link.zig b/test/link.zig index f0d6c87ec9..7fc18a141c 100644 --- a/test/link.zig +++ b/test/link.zig @@ -108,14 +108,6 @@ pub const cases = [_]Case{ .import = @import("link/macho/bugs/16628/build.zig"), }, .{ - .build_root = "test/link/macho/entry", - .import = @import("link/macho/entry/build.zig"), - }, - .{ - .build_root = "test/link/macho/entry_in_archive", - .import = @import("link/macho/entry_in_archive/build.zig"), - }, - .{ .build_root = "test/link/macho/linksection", .import = @import("link/macho/linksection/build.zig"), }, diff --git a/test/link/macho.zig b/test/link/macho.zig index 6dede6a973..66c4b7eb38 100644 --- a/test/link/macho.zig +++ b/test/link/macho.zig @@ -18,7 +18,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step { macho_step.dependOn(testDeadStrip(b, .{ .target = default_target })); macho_step.dependOn(testEmptyObject(b, .{ .target = default_target })); - macho_step.dependOn(testEntryPointDylib(b, .{ .target = default_target })); + macho_step.dependOn(testEntryPoint(b, .{ .target = default_target })); macho_step.dependOn(testHeaderWeakFlags(b, .{ .target = default_target })); macho_step.dependOn(testHelloC(b, .{ .target = default_target })); macho_step.dependOn(testHelloZig(b, .{ .target = default_target })); @@ -36,6 +36,8 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step { // Tests requiring symlinks when tested on Windows if (build_opts.has_symlinks_windows) { + macho_step.dependOn(testEntryPointArchive(b, .{ .target = default_target })); + macho_step.dependOn(testEntryPointDylib(b, .{ .target = default_target })); macho_step.dependOn(testDylib(b, .{ .target = default_target })); macho_step.dependOn(testNeededLibrary(b, .{ .target = default_target })); macho_step.dependOn(testWeakLibrary(b, .{ .target = default_target })); @@ -241,6 +243,64 @@ fn testEmptyObject(b: *Build, opts: Options) *Step { return test_step; } +fn testEntryPoint(b: *Build, opts: Options) *Step { + const test_step = addTestStep(b, "macho-entry-point", opts); + + const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = + \\#include<stdio.h> + \\int non_main() { + \\ printf("%d", 42); + \\ return 0; + \\} + }); + exe.entry = .{ .symbol_name = "_non_main" }; + + const run = addRunArtifact(exe); + run.expectStdOutEqual("42"); + test_step.dependOn(&run.step); + + const check = exe.checkObject(); + check.checkInHeaders(); + check.checkExact("segname __TEXT"); + check.checkExtract("vmaddr {vmaddr}"); + check.checkInHeaders(); + check.checkExact("cmd MAIN"); + check.checkExtract("entryoff {entryoff}"); + check.checkInSymtab(); + check.checkExtract("{n_value} (__TEXT,__text) external _non_main"); + check.checkComputeCompare("vmaddr entryoff +", .{ .op = .eq, .value = .{ .variable = "n_value" } }); + test_step.dependOn(&check.step); + + return test_step; +} + +fn testEntryPointArchive(b: *Build, opts: Options) *Step { + const test_step = addTestStep(b, "macho-entry-point-archive", opts); + + const lib = addStaticLibrary(b, opts, .{ .name = "main", .c_source_bytes = "int main() { return 0; }" }); + + { + const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = "" }); + exe.root_module.linkSystemLibrary("main", .{}); + exe.addLibraryPath(lib.getEmittedBinDirectory()); + + const run = addRunArtifact(exe); + test_step.dependOn(&run.step); + } + + { + const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = "" }); + exe.root_module.linkSystemLibrary("main", .{}); + exe.addLibraryPath(lib.getEmittedBinDirectory()); + exe.link_gc_sections = true; + + const run = addRunArtifact(exe); + test_step.dependOn(&run.step); + } + + return test_step; +} + fn testEntryPointDylib(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "macho-entry-point-dylib", opts); diff --git a/test/link/macho/entry/build.zig b/test/link/macho/entry/build.zig deleted file mode 100644 index 0ef717f292..0000000000 --- a/test/link/macho/entry/build.zig +++ /dev/null @@ -1,45 +0,0 @@ -const std = @import("std"); - -pub const requires_symlinks = true; - -pub fn build(b: *std.Build) void { - const test_step = b.step("test", "Test it"); - b.default_step = test_step; - - add(b, test_step, .Debug); - add(b, test_step, .ReleaseFast); - add(b, test_step, .ReleaseSmall); - add(b, test_step, .ReleaseSafe); -} - -fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { - const exe = b.addExecutable(.{ - .name = "main", - .optimize = optimize, - .target = b.resolveTargetQuery(.{ .os_tag = .macos }), - }); - exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} }); - exe.linkLibC(); - exe.entry = .{ .symbol_name = "_non_main" }; - - const check_exe = exe.checkObject(); - - check_exe.checkInHeaders(); - check_exe.checkExact("segname __TEXT"); - check_exe.checkExtract("vmaddr {vmaddr}"); - - check_exe.checkInHeaders(); - check_exe.checkExact("cmd MAIN"); - check_exe.checkExtract("entryoff {entryoff}"); - - check_exe.checkInSymtab(); - check_exe.checkExtract("{n_value} (__TEXT,__text) external _non_main"); - - check_exe.checkComputeCompare("vmaddr entryoff +", .{ .op = .eq, .value = .{ .variable = "n_value" } }); - test_step.dependOn(&check_exe.step); - - const run = b.addRunArtifact(exe); - run.skip_foreign_checks = true; - run.expectStdOutEqual("42"); - test_step.dependOn(&run.step); -} diff --git a/test/link/macho/entry/main.c b/test/link/macho/entry/main.c deleted file mode 100644 index 5fc58fc465..0000000000 --- a/test/link/macho/entry/main.c +++ /dev/null @@ -1,6 +0,0 @@ -#include <stdio.h> - -int non_main() { - printf("%d", 42); - return 0; -} diff --git a/test/link/macho/entry_in_archive/build.zig b/test/link/macho/entry_in_archive/build.zig deleted file mode 100644 index 72f340b204..0000000000 --- a/test/link/macho/entry_in_archive/build.zig +++ /dev/null @@ -1,36 +0,0 @@ -const std = @import("std"); - -pub const requires_symlinks = true; - -pub fn build(b: *std.Build) void { - const test_step = b.step("test", "Test it"); - b.default_step = test_step; - - add(b, test_step, .Debug); - add(b, test_step, .ReleaseFast); - add(b, test_step, .ReleaseSmall); - add(b, test_step, .ReleaseSafe); -} - -fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { - const lib = b.addStaticLibrary(.{ - .name = "main", - .optimize = optimize, - .target = b.resolveTargetQuery(.{ .os_tag = .macos }), - }); - lib.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} }); - lib.linkLibC(); - - const exe = b.addExecutable(.{ - .name = "main", - .optimize = optimize, - .target = b.resolveTargetQuery(.{ .os_tag = .macos }), - }); - exe.linkLibrary(lib); - exe.linkLibC(); - - const run = b.addRunArtifact(exe); - run.skip_foreign_checks = true; - run.expectExitCode(0); - test_step.dependOn(&run.step); -} diff --git a/test/link/macho/entry_in_archive/main.c b/test/link/macho/entry_in_archive/main.c deleted file mode 100644 index b9f6deb5be..0000000000 --- a/test/link/macho/entry_in_archive/main.c +++ /dev/null @@ -1,5 +0,0 @@ -#include <stdio.h> - -int main(int argc, char* argv[]) { - return 0; -} |
