authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-06-20 14:26:57+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-06-20 14:26:59+02:00
log8752db3285060c6f2d85c0fa744c44094239a792
treece9809fd8d6f92bf0d502cd1f50e3d7a43fb6c64
parent753e2b86396abb6bb614bff25b18d8fd82a809d8

macho: -pagezero_size is always in hex

This matches the behavior of other linkers out there including `ld64` and `lld`.

2 files changed, 16 insertions(+), 4 deletions(-)

src/link/MachO.zig+1-1
...@@ -4377,7 +4377,7 @@ fn populateMissingMetadata(self: *MachO) !void {...@@ -4377,7 +4377,7 @@ fn populateMissingMetadata(self: *MachO) !void {
4377 if (self.pagezero_segment_cmd_index == null) blk: {4377 if (self.pagezero_segment_cmd_index == null) blk: {
4378 if (aligned_pagezero_vmsize == 0) break :blk;4378 if (aligned_pagezero_vmsize == 0) break :blk;
4379 if (aligned_pagezero_vmsize != pagezero_vmsize) {4379 if (aligned_pagezero_vmsize != pagezero_vmsize) {
4380 log.warn("requested __PAGEZERO size is not page aligned", .{});4380 log.warn("requested __PAGEZERO size (0x{x}) is not page aligned", .{pagezero_vmsize});
4381 log.warn(" rounding down to 0x{x}", .{aligned_pagezero_vmsize});4381 log.warn(" rounding down to 0x{x}", .{aligned_pagezero_vmsize});
4382 }4382 }
4383 self.pagezero_segment_cmd_index = @intCast(u16, self.load_commands.items.len);4383 self.pagezero_segment_cmd_index = @intCast(u16, self.load_commands.items.len);
src/main.zig+15-3
...@@ -447,7 +447,7 @@ const usage_build_generic =...@@ -447,7 +447,7 @@ const usage_build_generic =
447 \\ -F[dir] (Darwin) add search path for frameworks447 \\ -F[dir] (Darwin) add search path for frameworks
448 \\ -install_name=[value] (Darwin) add dylib's install name448 \\ -install_name=[value] (Darwin) add dylib's install name
449 \\ --entitlements [path] (Darwin) add path to entitlements file for embedding in code signature449 \\ --entitlements [path] (Darwin) add path to entitlements file for embedding in code signature
450 \\ -pagezero_size [value] (Darwin) size of the __PAGEZERO segment450 \\ -pagezero_size [value] (Darwin) size of the __PAGEZERO segment in hexadecimal notation
451 \\ --import-memory (WebAssembly) import memory from the environment451 \\ --import-memory (WebAssembly) import memory from the environment
452 \\ --import-table (WebAssembly) import function table from the host environment452 \\ --import-table (WebAssembly) import function table from the host environment
453 \\ --export-table (WebAssembly) export function table to the host environment453 \\ --export-table (WebAssembly) export function table to the host environment
...@@ -914,7 +914,7 @@ fn buildOutputType(...@@ -914,7 +914,7 @@ fn buildOutputType(
914 const next_arg = args_iter.next() orelse {914 const next_arg = args_iter.next() orelse {
915 fatal("expected parameter after {s}", .{arg});915 fatal("expected parameter after {s}", .{arg});
916 };916 };
917 pagezero_size = std.fmt.parseUnsigned(u64, next_arg, 0) catch |err| {917 pagezero_size = std.fmt.parseUnsigned(u64, eatIntPrefix(next_arg, 16), 16) catch |err| {
918 fatal("unable to parse '{s}': {s}", .{ arg, @errorName(err) });918 fatal("unable to parse '{s}': {s}", .{ arg, @errorName(err) });
919 };919 };
920 } else if (mem.eql(u8, arg, "-T") or mem.eql(u8, arg, "--script")) {920 } else if (mem.eql(u8, arg, "-T") or mem.eql(u8, arg, "--script")) {
...@@ -1662,7 +1662,7 @@ fn buildOutputType(...@@ -1662,7 +1662,7 @@ fn buildOutputType(
1662 fatal("expected linker arg after '{s}'", .{arg});1662 fatal("expected linker arg after '{s}'", .{arg});
1663 }1663 }
1664 const next_arg = linker_args.items[i];1664 const next_arg = linker_args.items[i];
1665 pagezero_size = std.fmt.parseUnsigned(u64, next_arg, 0) catch |err| {1665 pagezero_size = std.fmt.parseUnsigned(u64, eatIntPrefix(next_arg, 16), 16) catch |err| {
1666 fatal("unable to parse '{s}': {s}", .{ arg, @errorName(err) });1666 fatal("unable to parse '{s}': {s}", .{ arg, @errorName(err) });
1667 };1667 };
1668 } else if (mem.eql(u8, arg, "--gc-sections")) {1668 } else if (mem.eql(u8, arg, "--gc-sections")) {
...@@ -5067,6 +5067,18 @@ pub fn cmdChangelist(...@@ -5067,6 +5067,18 @@ pub fn cmdChangelist(
5067 try bw.flush();5067 try bw.flush();
5068}5068}
50695069
5070fn eatIntPrefix(arg: []const u8, radix: u8) []const u8 {
5071 if (arg.len > 2 and arg[0] == '0') {
5072 switch (std.ascii.toLower(arg[1])) {
5073 'b' => if (radix == 2) return arg[2..],
5074 'o' => if (radix == 8) return arg[2..],
5075 'x' => if (radix == 16) return arg[2..],
5076 else => {},
5077 }
5078 }
5079 return arg;
5080}
5081
5070fn parseIntSuffix(arg: []const u8, prefix_len: usize) u64 {5082fn parseIntSuffix(arg: []const u8, prefix_len: usize) u64 {
5071 return std.fmt.parseUnsigned(u64, arg[prefix_len..], 0) catch |err| {5083 return std.fmt.parseUnsigned(u64, arg[prefix_len..], 0) catch |err| {
5072 fatal("unable to parse '{s}': {s}", .{ arg, @errorName(err) });5084 fatal("unable to parse '{s}': {s}", .{ arg, @errorName(err) });