authorgravatar for topolarity@tapscott.meCody Tapscott <topolarity@tapscott.me> 2022-10-31 08:28:16-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-10-31 13:12:37-04:00
log6f2408aab847113cb991058fbcd6d8a8296f1465
tree6cc307f1e59d9518a43c17a37798eac16d39653f
parentd02242661e667e67b07faf69490bb0db3dfd4bf0

link/MachO: Avoid depending on host PATH_MAX

Repeat of a4eb221b9 for the newly-synchronized zld code. Restores ability to compile Zig for WASI.

2 files changed, 5 insertions(+), 10 deletions(-)

src/link/MachO.zig+1-1
......@@ -2982,7 +2982,7 @@ pub fn populateMissingMetadata(self: *MachO) !void {
29822982 }
29832983}
29842984
2985inline fn calcInstallNameLen(cmd_size: u64, name: []const u8, assume_max_path_len: bool) u64 {
2985pub inline fn calcInstallNameLen(cmd_size: u64, name: []const u8, assume_max_path_len: bool) u64 {
29862986 const darwin_path_max = 1024;
29872987 const name_len = if (assume_max_path_len) darwin_path_max else std.mem.len(name) + 1;
29882988 return mem.alignForwardGeneric(u64, cmd_size + name_len, @alignOf(u64));
src/link/MachO/zld.zig+4-9
......@@ -1516,11 +1516,6 @@ pub const Zld = struct {
15161516 }
15171517 }
15181518
1519 inline fn calcInstallNameLen(cmd_size: u64, name: []const u8, assume_max_path_len: bool) u64 {
1520 const name_len = if (assume_max_path_len) std.os.PATH_MAX else std.mem.len(name) + 1;
1521 return mem.alignForwardGeneric(u64, cmd_size + name_len, @alignOf(u64));
1522 }
1523
15241519 fn calcLCsSize(self: *Zld, assume_max_path_len: bool) !u32 {
15251520 const gpa = self.gpa;
15261521
......@@ -1542,7 +1537,7 @@ pub const Zld = struct {
15421537 // LC_DYSYMTAB
15431538 sizeofcmds += @sizeOf(macho.dysymtab_command);
15441539 // LC_LOAD_DYLINKER
1545 sizeofcmds += calcInstallNameLen(
1540 sizeofcmds += MachO.calcInstallNameLen(
15461541 @sizeOf(macho.dylinker_command),
15471542 mem.sliceTo(MachO.default_dyld_path, 0),
15481543 false,
......@@ -1555,7 +1550,7 @@ pub const Zld = struct {
15551550 if (self.options.output_mode == .Lib) {
15561551 sizeofcmds += blk: {
15571552 const install_name = self.options.install_name orelse self.options.emit.?.sub_path;
1558 break :blk calcInstallNameLen(
1553 break :blk MachO.calcInstallNameLen(
15591554 @sizeOf(macho.dylib_command),
15601555 install_name,
15611556 assume_max_path_len,
......@@ -1567,7 +1562,7 @@ pub const Zld = struct {
15671562 var it = RpathIterator.init(gpa, self.options.rpath_list);
15681563 defer it.deinit();
15691564 while (try it.next()) |rpath| {
1570 sizeofcmds += calcInstallNameLen(
1565 sizeofcmds += MachO.calcInstallNameLen(
15711566 @sizeOf(macho.rpath_command),
15721567 rpath,
15731568 assume_max_path_len,
......@@ -1584,7 +1579,7 @@ pub const Zld = struct {
15841579 for (self.referenced_dylibs.keys()) |id| {
15851580 const dylib = self.dylibs.items[id];
15861581 const dylib_id = dylib.id orelse unreachable;
1587 sizeofcmds += calcInstallNameLen(
1582 sizeofcmds += MachO.calcInstallNameLen(
15881583 @sizeOf(macho.dylib_command),
15891584 dylib_id.name,
15901585 assume_max_path_len,