| author | |
| committer | |
| log | 2c0c86944ef202788ba7489fe14df12194b720d9 |
| tree | 296e6e6f8af7a7e13baa9a7a80facdde759df468 |
| parent | 9533628ca08e8ca1a111c0cb0842d4d45706ea2d |
4 files changed, 109 insertions(+), 144 deletions(-)
test/link.zig-4| ... | @@ -127,10 +127,6 @@ pub const cases = [_]Case{ | ... | @@ -127,10 +127,6 @@ pub const cases = [_]Case{ |
| 127 | .build_root = "test/link/macho/entry_in_archive", | 127 | .build_root = "test/link/macho/entry_in_archive", |
| 128 | .import = @import("link/macho/entry_in_archive/build.zig"), | 128 | .import = @import("link/macho/entry_in_archive/build.zig"), |
| 129 | }, | 129 | }, |
| 130 | .{ | ||
| 131 | .build_root = "test/link/macho/headerpad", | ||
| 132 | .import = @import("link/macho/headerpad/build.zig"), | ||
| 133 | }, | ||
| 134 | .{ | 130 | .{ |
| 135 | .build_root = "test/link/macho/linksection", | 131 | .build_root = "test/link/macho/linksection", |
| 136 | .import = @import("link/macho/linksection/build.zig"), | 132 | .import = @import("link/macho/linksection/build.zig"), |
test/link/macho.zig+109| ... | @@ -24,6 +24,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step { | ... | @@ -24,6 +24,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step { |
| 24 | 24 | ||
| 25 | // Tests requiring presence of macOS SDK in system path | 25 | // Tests requiring presence of macOS SDK in system path |
| 26 | if (build_opts.has_macos_sdk) { | 26 | if (build_opts.has_macos_sdk) { |
| 27 | macho_step.dependOn(testHeaderpad(b, .{ .target = b.host })); | ||
| 27 | macho_step.dependOn(testNeededFramework(b, .{ .target = b.host })); | 28 | macho_step.dependOn(testNeededFramework(b, .{ .target = b.host })); |
| 28 | } | 29 | } |
| 29 | } | 30 | } |
| ... | @@ -166,6 +167,113 @@ fn testEntryPointDylib(b: *Build, opts: Options) *Step { | ... | @@ -166,6 +167,113 @@ fn testEntryPointDylib(b: *Build, opts: Options) *Step { |
| 166 | return test_step; | 167 | return test_step; |
| 167 | } | 168 | } |
| 168 | 169 | ||
| 170 | fn testHeaderpad(b: *Build, opts: Options) *Step { | ||
| 171 | const test_step = addTestStep(b, "macho-headerpad", opts); | ||
| 172 | |||
| 173 | const addExe = struct { | ||
| 174 | fn addExe(bb: *Build, o: Options, name: []const u8) *Compile { | ||
| 175 | const exe = addExecutable(bb, o, .{ | ||
| 176 | .name = name, | ||
| 177 | .c_source_bytes = "int main() { return 0; }", | ||
| 178 | }); | ||
| 179 | exe.linkFramework("CoreFoundation"); | ||
| 180 | exe.linkFramework("Foundation"); | ||
| 181 | exe.linkFramework("Cocoa"); | ||
| 182 | exe.linkFramework("CoreGraphics"); | ||
| 183 | exe.linkFramework("CoreHaptics"); | ||
| 184 | exe.linkFramework("CoreAudio"); | ||
| 185 | exe.linkFramework("AVFoundation"); | ||
| 186 | exe.linkFramework("CoreImage"); | ||
| 187 | exe.linkFramework("CoreLocation"); | ||
| 188 | exe.linkFramework("CoreML"); | ||
| 189 | exe.linkFramework("CoreVideo"); | ||
| 190 | exe.linkFramework("CoreText"); | ||
| 191 | exe.linkFramework("CryptoKit"); | ||
| 192 | exe.linkFramework("GameKit"); | ||
| 193 | exe.linkFramework("SwiftUI"); | ||
| 194 | exe.linkFramework("StoreKit"); | ||
| 195 | exe.linkFramework("SpriteKit"); | ||
| 196 | return exe; | ||
| 197 | } | ||
| 198 | }.addExe; | ||
| 199 | |||
| 200 | { | ||
| 201 | const exe = addExe(b, opts, "main1"); | ||
| 202 | exe.headerpad_max_install_names = true; | ||
| 203 | |||
| 204 | const check = exe.checkObject(); | ||
| 205 | check.checkInHeaders(); | ||
| 206 | check.checkExact("sectname __text"); | ||
| 207 | check.checkExtract("offset {offset}"); | ||
| 208 | switch (opts.target.result.cpu.arch) { | ||
| 209 | .aarch64 => check.checkComputeCompare("offset", .{ .op = .gte, .value = .{ .literal = 0x4000 } }), | ||
| 210 | .x86_64 => check.checkComputeCompare("offset", .{ .op = .gte, .value = .{ .literal = 0x1000 } }), | ||
| 211 | else => unreachable, | ||
| 212 | } | ||
| 213 | test_step.dependOn(&check.step); | ||
| 214 | |||
| 215 | const run = addRunArtifact(exe); | ||
| 216 | run.expectExitCode(0); | ||
| 217 | test_step.dependOn(&run.step); | ||
| 218 | } | ||
| 219 | |||
| 220 | { | ||
| 221 | const exe = addExe(b, opts, "main2"); | ||
| 222 | exe.headerpad_size = 0x10000; | ||
| 223 | |||
| 224 | const check = exe.checkObject(); | ||
| 225 | check.checkInHeaders(); | ||
| 226 | check.checkExact("sectname __text"); | ||
| 227 | check.checkExtract("offset {offset}"); | ||
| 228 | check.checkComputeCompare("offset", .{ .op = .gte, .value = .{ .literal = 0x10000 } }); | ||
| 229 | test_step.dependOn(&check.step); | ||
| 230 | |||
| 231 | const run = addRunArtifact(exe); | ||
| 232 | run.expectExitCode(0); | ||
| 233 | test_step.dependOn(&run.step); | ||
| 234 | } | ||
| 235 | |||
| 236 | { | ||
| 237 | const exe = addExe(b, opts, "main3"); | ||
| 238 | exe.headerpad_max_install_names = true; | ||
| 239 | exe.headerpad_size = 0x10000; | ||
| 240 | |||
| 241 | const check = exe.checkObject(); | ||
| 242 | check.checkInHeaders(); | ||
| 243 | check.checkExact("sectname __text"); | ||
| 244 | check.checkExtract("offset {offset}"); | ||
| 245 | check.checkComputeCompare("offset", .{ .op = .gte, .value = .{ .literal = 0x10000 } }); | ||
| 246 | test_step.dependOn(&check.step); | ||
| 247 | |||
| 248 | const run = addRunArtifact(exe); | ||
| 249 | run.expectExitCode(0); | ||
| 250 | test_step.dependOn(&run.step); | ||
| 251 | } | ||
| 252 | |||
| 253 | { | ||
| 254 | const exe = addExe(b, opts, "main4"); | ||
| 255 | exe.headerpad_max_install_names = true; | ||
| 256 | exe.headerpad_size = 0x1000; | ||
| 257 | |||
| 258 | const check = exe.checkObject(); | ||
| 259 | check.checkInHeaders(); | ||
| 260 | check.checkExact("sectname __text"); | ||
| 261 | check.checkExtract("offset {offset}"); | ||
| 262 | switch (opts.target.result.cpu.arch) { | ||
| 263 | .aarch64 => check.checkComputeCompare("offset", .{ .op = .gte, .value = .{ .literal = 0x4000 } }), | ||
| 264 | .x86_64 => check.checkComputeCompare("offset", .{ .op = .gte, .value = .{ .literal = 0x1000 } }), | ||
| 265 | else => unreachable, | ||
| 266 | } | ||
| 267 | test_step.dependOn(&check.step); | ||
| 268 | |||
| 269 | const run = addRunArtifact(exe); | ||
| 270 | run.expectExitCode(0); | ||
| 271 | test_step.dependOn(&run.step); | ||
| 272 | } | ||
| 273 | |||
| 274 | return test_step; | ||
| 275 | } | ||
| 276 | |||
| 169 | // Adapted from https://github.com/llvm/llvm-project/blob/main/lld/test/MachO/weak-header-flags.s | 277 | // Adapted from https://github.com/llvm/llvm-project/blob/main/lld/test/MachO/weak-header-flags.s |
| 170 | fn testHeaderWeakFlags(b: *Build, opts: Options) *Step { | 278 | fn testHeaderWeakFlags(b: *Build, opts: Options) *Step { |
| 171 | const test_step = addTestStep(b, "macho-header-weak-flags", opts); | 279 | const test_step = addTestStep(b, "macho-header-weak-flags", opts); |
| ... | @@ -537,5 +645,6 @@ const std = @import("std"); | ... | @@ -537,5 +645,6 @@ const std = @import("std"); |
| 537 | 645 | ||
| 538 | const Build = std.Build; | 646 | const Build = std.Build; |
| 539 | const BuildOptions = link.BuildOptions; | 647 | const BuildOptions = link.BuildOptions; |
| 648 | const Compile = Step.Compile; | ||
| 540 | const Options = link.Options; | 649 | const Options = link.Options; |
| 541 | const Step = Build.Step; | 650 | const Step = Build.Step; |
test/link/macho/headerpad/build.zig deleted-137| ... | @@ -1,137 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | pub const requires_symlinks = true; | ||
| 5 | pub const requires_macos_sdk = true; | ||
| 6 | |||
| 7 | pub fn build(b: *std.Build) void { | ||
| 8 | const test_step = b.step("test", "Test it"); | ||
| 9 | b.default_step = test_step; | ||
| 10 | |||
| 11 | add(b, test_step, .Debug); | ||
| 12 | add(b, test_step, .ReleaseFast); | ||
| 13 | add(b, test_step, .ReleaseSmall); | ||
| 14 | add(b, test_step, .ReleaseSafe); | ||
| 15 | } | ||
| 16 | |||
| 17 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { | ||
| 18 | { | ||
| 19 | // Test -headerpad_max_install_names | ||
| 20 | const exe = simpleExe(b, optimize, "headerpad_max_install_names"); | ||
| 21 | exe.headerpad_max_install_names = true; | ||
| 22 | |||
| 23 | const check = exe.checkObject(); | ||
| 24 | check.checkInHeaders(); | ||
| 25 | check.checkExact("sectname __text"); | ||
| 26 | check.checkExtract("offset {offset}"); | ||
| 27 | |||
| 28 | switch (builtin.cpu.arch) { | ||
| 29 | .aarch64 => { | ||
| 30 | check.checkComputeCompare("offset", .{ .op = .gte, .value = .{ .literal = 0x4000 } }); | ||
| 31 | }, | ||
| 32 | .x86_64 => { | ||
| 33 | check.checkComputeCompare("offset", .{ .op = .gte, .value = .{ .literal = 0x1000 } }); | ||
| 34 | }, | ||
| 35 | else => unreachable, | ||
| 36 | } | ||
| 37 | |||
| 38 | test_step.dependOn(&check.step); | ||
| 39 | |||
| 40 | const run = b.addRunArtifact(exe); | ||
| 41 | test_step.dependOn(&run.step); | ||
| 42 | } | ||
| 43 | |||
| 44 | { | ||
| 45 | // Test -headerpad | ||
| 46 | const exe = simpleExe(b, optimize, "headerpad"); | ||
| 47 | exe.headerpad_size = 0x10000; | ||
| 48 | |||
| 49 | const check = exe.checkObject(); | ||
| 50 | check.checkInHeaders(); | ||
| 51 | check.checkExact("sectname __text"); | ||
| 52 | check.checkExtract("offset {offset}"); | ||
| 53 | check.checkComputeCompare("offset", .{ .op = .gte, .value = .{ .literal = 0x10000 } }); | ||
| 54 | |||
| 55 | test_step.dependOn(&check.step); | ||
| 56 | |||
| 57 | const run = b.addRunArtifact(exe); | ||
| 58 | test_step.dependOn(&run.step); | ||
| 59 | } | ||
| 60 | |||
| 61 | { | ||
| 62 | // Test both flags with -headerpad overriding -headerpad_max_install_names | ||
| 63 | const exe = simpleExe(b, optimize, "headerpad_overriding"); | ||
| 64 | exe.headerpad_max_install_names = true; | ||
| 65 | exe.headerpad_size = 0x10000; | ||
| 66 | |||
| 67 | const check = exe.checkObject(); | ||
| 68 | check.checkInHeaders(); | ||
| 69 | check.checkExact("sectname __text"); | ||
| 70 | check.checkExtract("offset {offset}"); | ||
| 71 | check.checkComputeCompare("offset", .{ .op = .gte, .value = .{ .literal = 0x10000 } }); | ||
| 72 | |||
| 73 | test_step.dependOn(&check.step); | ||
| 74 | |||
| 75 | const run = b.addRunArtifact(exe); | ||
| 76 | test_step.dependOn(&run.step); | ||
| 77 | } | ||
| 78 | |||
| 79 | { | ||
| 80 | // Test both flags with -headerpad_max_install_names overriding -headerpad | ||
| 81 | const exe = simpleExe(b, optimize, "headerpad_max_install_names_overriding"); | ||
| 82 | exe.headerpad_size = 0x1000; | ||
| 83 | exe.headerpad_max_install_names = true; | ||
| 84 | |||
| 85 | const check = exe.checkObject(); | ||
| 86 | check.checkInHeaders(); | ||
| 87 | check.checkExact("sectname __text"); | ||
| 88 | check.checkExtract("offset {offset}"); | ||
| 89 | |||
| 90 | switch (builtin.cpu.arch) { | ||
| 91 | .aarch64 => { | ||
| 92 | check.checkComputeCompare("offset", .{ .op = .gte, .value = .{ .literal = 0x4000 } }); | ||
| 93 | }, | ||
| 94 | .x86_64 => { | ||
| 95 | check.checkComputeCompare("offset", .{ .op = .gte, .value = .{ .literal = 0x1000 } }); | ||
| 96 | }, | ||
| 97 | else => unreachable, | ||
| 98 | } | ||
| 99 | |||
| 100 | test_step.dependOn(&check.step); | ||
| 101 | |||
| 102 | const run = b.addRunArtifact(exe); | ||
| 103 | test_step.dependOn(&run.step); | ||
| 104 | } | ||
| 105 | } | ||
| 106 | |||
| 107 | fn simpleExe( | ||
| 108 | b: *std.Build, | ||
| 109 | optimize: std.builtin.OptimizeMode, | ||
| 110 | name: []const u8, | ||
| 111 | ) *std.Build.Step.Compile { | ||
| 112 | const exe = b.addExecutable(.{ | ||
| 113 | .name = name, | ||
| 114 | .optimize = optimize, | ||
| 115 | .target = b.host, | ||
| 116 | }); | ||
| 117 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} }); | ||
| 118 | exe.linkLibC(); | ||
| 119 | exe.linkFramework("CoreFoundation"); | ||
| 120 | exe.linkFramework("Foundation"); | ||
| 121 | exe.linkFramework("Cocoa"); | ||
| 122 | exe.linkFramework("CoreGraphics"); | ||
| 123 | exe.linkFramework("CoreHaptics"); | ||
| 124 | exe.linkFramework("CoreAudio"); | ||
| 125 | exe.linkFramework("AVFoundation"); | ||
| 126 | exe.linkFramework("CoreImage"); | ||
| 127 | exe.linkFramework("CoreLocation"); | ||
| 128 | exe.linkFramework("CoreML"); | ||
| 129 | exe.linkFramework("CoreVideo"); | ||
| 130 | exe.linkFramework("CoreText"); | ||
| 131 | exe.linkFramework("CryptoKit"); | ||
| 132 | exe.linkFramework("GameKit"); | ||
| 133 | exe.linkFramework("SwiftUI"); | ||
| 134 | exe.linkFramework("StoreKit"); | ||
| 135 | exe.linkFramework("SpriteKit"); | ||
| 136 | return exe; | ||
| 137 | } | ||
test/link/macho/headerpad/main.c deleted-3| ... | @@ -1,3 +0,0 @@ | ||
| 1 | int main(int argc, char* argv[]) { | ||
| 2 | return 0; | ||
| 3 | } | ||