link-tests: test pagezero_size option for macho

This commit is contained in:
Jakub Konka
2022-06-20 18:25:20 +02:00
parent 6e56a8df20
commit 2d09540a63
4 changed files with 48 additions and 0 deletions

View File

@@ -1582,6 +1582,9 @@ pub const LibExeObjStep = struct {
/// (Darwin) Path to entitlements file
entitlements: ?[]const u8 = null,
/// (Darwin) Size of the pagezero segment.
pagezero_size: ?u64 = null,
/// Position Independent Code
force_pic: ?bool = null,
@@ -2638,6 +2641,10 @@ pub const LibExeObjStep = struct {
if (self.entitlements) |entitlements| {
try zig_args.appendSlice(&[_][]const u8{ "--entitlements", entitlements });
}
if (self.pagezero_size) |pagezero_size| {
const size = try std.fmt.allocPrint(builder.allocator, "{x}", .{pagezero_size});
try zig_args.appendSlice(&[_][]const u8{ "-pagezero_size", size });
}
if (self.bundle_compiler_rt) |x| {
if (x) {

View File

@@ -28,6 +28,10 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
});
if (builtin.os.tag == .macos) {
cases.addBuildFile("test/link/pagezero/build.zig", .{
.build_modes = false,
});
cases.addBuildFile("test/link/dylib/build.zig", .{
.build_modes = true,
});

View File

@@ -0,0 +1,34 @@
const std = @import("std");
const Builder = std.build.Builder;
pub fn build(b: *Builder) void {
const mode = b.standardReleaseOptions();
const test_step = b.step("test", "Test");
const exe = b.addExecutable("main", null);
exe.setBuildMode(mode);
exe.addCSourceFile("main.c", &.{});
exe.linkLibC();
exe.pagezero_size = 0x4000;
var name: [16]u8 = undefined;
std.mem.set(u8, &name, 0);
std.mem.copy(u8, &name, "__PAGEZERO");
const pagezero_seg = std.macho.segment_command_64{
.cmdsize = @sizeOf(std.macho.segment_command_64),
.segname = name,
.vmaddr = 0,
.vmsize = 0x4000,
.fileoff = 0,
.filesize = 0,
.maxprot = 0,
.initprot = 0,
.nsects = 0,
.flags = 0,
};
const check_file = std.build.CheckFileStep.create(b, exe.getOutputSource(), &[_][]const u8{std.mem.asBytes(&pagezero_seg)});
test_step.dependOn(b.getInstallStep());
test_step.dependOn(&check_file.step);
}

View File

@@ -0,0 +1,3 @@
int main(int argc, char* argv[]) {
return 0;
}