| author | |
| committer | |
| log | 2d09540a636ab6ef2ca5087f18d55bbc259cd652 |
| tree | 47dc569218ff7be2c28f2960a093d947643268dd |
| parent | 6e56a8df20395749b21b3857952dae1c227aacf1 |
4 files changed, 48 insertions(+), 0 deletions(-)
lib/std/build.zig+7| ... | ... | @@ -1582,6 +1582,9 @@ pub const LibExeObjStep = struct { |
| 1582 | 1582 | /// (Darwin) Path to entitlements file |
| 1583 | 1583 | entitlements: ?[]const u8 = null, |
| 1584 | 1584 | |
| 1585 | /// (Darwin) Size of the pagezero segment. | |
| 1586 | pagezero_size: ?u64 = null, | |
| 1587 | ||
| 1585 | 1588 | /// Position Independent Code |
| 1586 | 1589 | force_pic: ?bool = null, |
| 1587 | 1590 | |
| ... | ... | @@ -2638,6 +2641,10 @@ pub const LibExeObjStep = struct { |
| 2638 | 2641 | if (self.entitlements) |entitlements| { |
| 2639 | 2642 | try zig_args.appendSlice(&[_][]const u8{ "--entitlements", entitlements }); |
| 2640 | 2643 | } |
| 2644 | if (self.pagezero_size) |pagezero_size| { | |
| 2645 | const size = try std.fmt.allocPrint(builder.allocator, "{x}", .{pagezero_size}); | |
| 2646 | try zig_args.appendSlice(&[_][]const u8{ "-pagezero_size", size }); | |
| 2647 | } | |
| 2641 | 2648 | |
| 2642 | 2649 | if (self.bundle_compiler_rt) |x| { |
| 2643 | 2650 | if (x) { |
test/link.zig+4| ... | ... | @@ -28,6 +28,10 @@ pub fn addCases(cases: *tests.StandaloneContext) void { |
| 28 | 28 | }); |
| 29 | 29 | |
| 30 | 30 | if (builtin.os.tag == .macos) { |
| 31 | cases.addBuildFile("test/link/pagezero/build.zig", .{ | |
| 32 | .build_modes = false, | |
| 33 | }); | |
| 34 | ||
| 31 | 35 | cases.addBuildFile("test/link/dylib/build.zig", .{ |
| 32 | 36 | .build_modes = true, |
| 33 | 37 | }); |
test/link/pagezero/build.zig created+34| ... | ... | @@ -0,0 +1,34 @@ |
| 1 | const std = @import("std"); | |
| 2 | const Builder = std.build.Builder; | |
| 3 | ||
| 4 | pub fn build(b: *Builder) void { | |
| 5 | const mode = b.standardReleaseOptions(); | |
| 6 | ||
| 7 | const test_step = b.step("test", "Test"); | |
| 8 | ||
| 9 | const exe = b.addExecutable("main", null); | |
| 10 | exe.setBuildMode(mode); | |
| 11 | exe.addCSourceFile("main.c", &.{}); | |
| 12 | exe.linkLibC(); | |
| 13 | exe.pagezero_size = 0x4000; | |
| 14 | ||
| 15 | var name: [16]u8 = undefined; | |
| 16 | std.mem.set(u8, &name, 0); | |
| 17 | std.mem.copy(u8, &name, "__PAGEZERO"); | |
| 18 | const pagezero_seg = std.macho.segment_command_64{ | |
| 19 | .cmdsize = @sizeOf(std.macho.segment_command_64), | |
| 20 | .segname = name, | |
| 21 | .vmaddr = 0, | |
| 22 | .vmsize = 0x4000, | |
| 23 | .fileoff = 0, | |
| 24 | .filesize = 0, | |
| 25 | .maxprot = 0, | |
| 26 | .initprot = 0, | |
| 27 | .nsects = 0, | |
| 28 | .flags = 0, | |
| 29 | }; | |
| 30 | const check_file = std.build.CheckFileStep.create(b, exe.getOutputSource(), &[_][]const u8{std.mem.asBytes(&pagezero_seg)}); | |
| 31 | ||
| 32 | test_step.dependOn(b.getInstallStep()); | |
| 33 | test_step.dependOn(&check_file.step); | |
| 34 | } |
test/link/pagezero/main.c created+3| ... | ... | @@ -0,0 +1,3 @@ |
| 1 | int main(int argc, char* argv[]) { | |
| 2 | return 0; | |
| 3 | } |