| author | |
| committer | |
| log | a25b780aad5df41bc97ce8ffc700917208be820b |
| tree | b31da546c8760eaceb3a1e724fbc5e1be7b7590f |
| parent | 82a044f4f7997dbbb43d1aa7f8ba956328380371 |
6 files changed, 61 insertions(+), 101 deletions(-)
test/link.zig-8| ... | ... | @@ -107,14 +107,6 @@ pub const cases = [_]Case{ |
| 107 | 107 | .build_root = "test/link/macho/bugs/16628", |
| 108 | 108 | .import = @import("link/macho/bugs/16628/build.zig"), |
| 109 | 109 | }, |
| 110 | .{ | |
| 111 | .build_root = "test/link/macho/entry", | |
| 112 | .import = @import("link/macho/entry/build.zig"), | |
| 113 | }, | |
| 114 | .{ | |
| 115 | .build_root = "test/link/macho/entry_in_archive", | |
| 116 | .import = @import("link/macho/entry_in_archive/build.zig"), | |
| 117 | }, | |
| 118 | 110 | .{ |
| 119 | 111 | .build_root = "test/link/macho/linksection", |
| 120 | 112 | .import = @import("link/macho/linksection/build.zig"), |
test/link/macho.zig+61-1| ... | ... | @@ -18,7 +18,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step { |
| 18 | 18 | |
| 19 | 19 | macho_step.dependOn(testDeadStrip(b, .{ .target = default_target })); |
| 20 | 20 | macho_step.dependOn(testEmptyObject(b, .{ .target = default_target })); |
| 21 | macho_step.dependOn(testEntryPointDylib(b, .{ .target = default_target })); | |
| 21 | macho_step.dependOn(testEntryPoint(b, .{ .target = default_target })); | |
| 22 | 22 | macho_step.dependOn(testHeaderWeakFlags(b, .{ .target = default_target })); |
| 23 | 23 | macho_step.dependOn(testHelloC(b, .{ .target = default_target })); |
| 24 | 24 | macho_step.dependOn(testHelloZig(b, .{ .target = default_target })); |
| ... | ... | @@ -36,6 +36,8 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step { |
| 36 | 36 | |
| 37 | 37 | // Tests requiring symlinks when tested on Windows |
| 38 | 38 | if (build_opts.has_symlinks_windows) { |
| 39 | macho_step.dependOn(testEntryPointArchive(b, .{ .target = default_target })); | |
| 40 | macho_step.dependOn(testEntryPointDylib(b, .{ .target = default_target })); | |
| 39 | 41 | macho_step.dependOn(testDylib(b, .{ .target = default_target })); |
| 40 | 42 | macho_step.dependOn(testNeededLibrary(b, .{ .target = default_target })); |
| 41 | 43 | macho_step.dependOn(testWeakLibrary(b, .{ .target = default_target })); |
| ... | ... | @@ -241,6 +243,64 @@ fn testEmptyObject(b: *Build, opts: Options) *Step { |
| 241 | 243 | return test_step; |
| 242 | 244 | } |
| 243 | 245 | |
| 246 | fn testEntryPoint(b: *Build, opts: Options) *Step { | |
| 247 | const test_step = addTestStep(b, "macho-entry-point", opts); | |
| 248 | ||
| 249 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = | |
| 250 | \\#include<stdio.h> | |
| 251 | \\int non_main() { | |
| 252 | \\ printf("%d", 42); | |
| 253 | \\ return 0; | |
| 254 | \\} | |
| 255 | }); | |
| 256 | exe.entry = .{ .symbol_name = "_non_main" }; | |
| 257 | ||
| 258 | const run = addRunArtifact(exe); | |
| 259 | run.expectStdOutEqual("42"); | |
| 260 | test_step.dependOn(&run.step); | |
| 261 | ||
| 262 | const check = exe.checkObject(); | |
| 263 | check.checkInHeaders(); | |
| 264 | check.checkExact("segname __TEXT"); | |
| 265 | check.checkExtract("vmaddr {vmaddr}"); | |
| 266 | check.checkInHeaders(); | |
| 267 | check.checkExact("cmd MAIN"); | |
| 268 | check.checkExtract("entryoff {entryoff}"); | |
| 269 | check.checkInSymtab(); | |
| 270 | check.checkExtract("{n_value} (__TEXT,__text) external _non_main"); | |
| 271 | check.checkComputeCompare("vmaddr entryoff +", .{ .op = .eq, .value = .{ .variable = "n_value" } }); | |
| 272 | test_step.dependOn(&check.step); | |
| 273 | ||
| 274 | return test_step; | |
| 275 | } | |
| 276 | ||
| 277 | fn testEntryPointArchive(b: *Build, opts: Options) *Step { | |
| 278 | const test_step = addTestStep(b, "macho-entry-point-archive", opts); | |
| 279 | ||
| 280 | const lib = addStaticLibrary(b, opts, .{ .name = "main", .c_source_bytes = "int main() { return 0; }" }); | |
| 281 | ||
| 282 | { | |
| 283 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = "" }); | |
| 284 | exe.root_module.linkSystemLibrary("main", .{}); | |
| 285 | exe.addLibraryPath(lib.getEmittedBinDirectory()); | |
| 286 | ||
| 287 | const run = addRunArtifact(exe); | |
| 288 | test_step.dependOn(&run.step); | |
| 289 | } | |
| 290 | ||
| 291 | { | |
| 292 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = "" }); | |
| 293 | exe.root_module.linkSystemLibrary("main", .{}); | |
| 294 | exe.addLibraryPath(lib.getEmittedBinDirectory()); | |
| 295 | exe.link_gc_sections = true; | |
| 296 | ||
| 297 | const run = addRunArtifact(exe); | |
| 298 | test_step.dependOn(&run.step); | |
| 299 | } | |
| 300 | ||
| 301 | return test_step; | |
| 302 | } | |
| 303 | ||
| 244 | 304 | fn testEntryPointDylib(b: *Build, opts: Options) *Step { |
| 245 | 305 | const test_step = addTestStep(b, "macho-entry-point-dylib", opts); |
| 246 | 306 |
test/link/macho/entry/build.zig deleted-45| ... | ... | @@ -1,45 +0,0 @@ |
| 1 | const std = @import("std"); | |
| 2 | ||
| 3 | pub const requires_symlinks = true; | |
| 4 | ||
| 5 | pub fn build(b: *std.Build) void { | |
| 6 | const test_step = b.step("test", "Test it"); | |
| 7 | b.default_step = test_step; | |
| 8 | ||
| 9 | add(b, test_step, .Debug); | |
| 10 | add(b, test_step, .ReleaseFast); | |
| 11 | add(b, test_step, .ReleaseSmall); | |
| 12 | add(b, test_step, .ReleaseSafe); | |
| 13 | } | |
| 14 | ||
| 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { | |
| 16 | const exe = b.addExecutable(.{ | |
| 17 | .name = "main", | |
| 18 | .optimize = optimize, | |
| 19 | .target = b.resolveTargetQuery(.{ .os_tag = .macos }), | |
| 20 | }); | |
| 21 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} }); | |
| 22 | exe.linkLibC(); | |
| 23 | exe.entry = .{ .symbol_name = "_non_main" }; | |
| 24 | ||
| 25 | const check_exe = exe.checkObject(); | |
| 26 | ||
| 27 | check_exe.checkInHeaders(); | |
| 28 | check_exe.checkExact("segname __TEXT"); | |
| 29 | check_exe.checkExtract("vmaddr {vmaddr}"); | |
| 30 | ||
| 31 | check_exe.checkInHeaders(); | |
| 32 | check_exe.checkExact("cmd MAIN"); | |
| 33 | check_exe.checkExtract("entryoff {entryoff}"); | |
| 34 | ||
| 35 | check_exe.checkInSymtab(); | |
| 36 | check_exe.checkExtract("{n_value} (__TEXT,__text) external _non_main"); | |
| 37 | ||
| 38 | check_exe.checkComputeCompare("vmaddr entryoff +", .{ .op = .eq, .value = .{ .variable = "n_value" } }); | |
| 39 | test_step.dependOn(&check_exe.step); | |
| 40 | ||
| 41 | const run = b.addRunArtifact(exe); | |
| 42 | run.skip_foreign_checks = true; | |
| 43 | run.expectStdOutEqual("42"); | |
| 44 | test_step.dependOn(&run.step); | |
| 45 | } |
test/link/macho/entry/main.c deleted-6| ... | ... | @@ -1,6 +0,0 @@ |
| 1 | #include <stdio.h> | |
| 2 | ||
| 3 | int non_main() { | |
| 4 | printf("%d", 42); | |
| 5 | return 0; | |
| 6 | } |
test/link/macho/entry_in_archive/build.zig deleted-36| ... | ... | @@ -1,36 +0,0 @@ |
| 1 | const std = @import("std"); | |
| 2 | ||
| 3 | pub const requires_symlinks = true; | |
| 4 | ||
| 5 | pub fn build(b: *std.Build) void { | |
| 6 | const test_step = b.step("test", "Test it"); | |
| 7 | b.default_step = test_step; | |
| 8 | ||
| 9 | add(b, test_step, .Debug); | |
| 10 | add(b, test_step, .ReleaseFast); | |
| 11 | add(b, test_step, .ReleaseSmall); | |
| 12 | add(b, test_step, .ReleaseSafe); | |
| 13 | } | |
| 14 | ||
| 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { | |
| 16 | const lib = b.addStaticLibrary(.{ | |
| 17 | .name = "main", | |
| 18 | .optimize = optimize, | |
| 19 | .target = b.resolveTargetQuery(.{ .os_tag = .macos }), | |
| 20 | }); | |
| 21 | lib.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} }); | |
| 22 | lib.linkLibC(); | |
| 23 | ||
| 24 | const exe = b.addExecutable(.{ | |
| 25 | .name = "main", | |
| 26 | .optimize = optimize, | |
| 27 | .target = b.resolveTargetQuery(.{ .os_tag = .macos }), | |
| 28 | }); | |
| 29 | exe.linkLibrary(lib); | |
| 30 | exe.linkLibC(); | |
| 31 | ||
| 32 | const run = b.addRunArtifact(exe); | |
| 33 | run.skip_foreign_checks = true; | |
| 34 | run.expectExitCode(0); | |
| 35 | test_step.dependOn(&run.step); | |
| 36 | } |
test/link/macho/entry_in_archive/main.c deleted-5| ... | ... | @@ -1,5 +0,0 @@ |
| 1 | #include <stdio.h> | |
| 2 | ||
| 3 | int main(int argc, char* argv[]) { | |
| 4 | return 0; | |
| 5 | } |