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 {...@@ -2982,7 +2982,7 @@ pub fn populateMissingMetadata(self: *MachO) !void {
2982 }2982 }
2983}2983}
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 {
2986 const darwin_path_max = 1024;2986 const darwin_path_max = 1024;
2987 const name_len = if (assume_max_path_len) darwin_path_max else std.mem.len(name) + 1;2987 const name_len = if (assume_max_path_len) darwin_path_max else std.mem.len(name) + 1;
2988 return mem.alignForwardGeneric(u64, cmd_size + name_len, @alignOf(u64));2988 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 {...@@ -1516,11 +1516,6 @@ pub const Zld = struct {
1516 }1516 }
1517 }1517 }
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
1524 fn calcLCsSize(self: *Zld, assume_max_path_len: bool) !u32 {1519 fn calcLCsSize(self: *Zld, assume_max_path_len: bool) !u32 {
1525 const gpa = self.gpa;1520 const gpa = self.gpa;
15261521
...@@ -1542,7 +1537,7 @@ pub const Zld = struct {...@@ -1542,7 +1537,7 @@ pub const Zld = struct {
1542 // LC_DYSYMTAB1537 // LC_DYSYMTAB
1543 sizeofcmds += @sizeOf(macho.dysymtab_command);1538 sizeofcmds += @sizeOf(macho.dysymtab_command);
1544 // LC_LOAD_DYLINKER1539 // LC_LOAD_DYLINKER
1545 sizeofcmds += calcInstallNameLen(1540 sizeofcmds += MachO.calcInstallNameLen(
1546 @sizeOf(macho.dylinker_command),1541 @sizeOf(macho.dylinker_command),
1547 mem.sliceTo(MachO.default_dyld_path, 0),1542 mem.sliceTo(MachO.default_dyld_path, 0),
1548 false,1543 false,
...@@ -1555,7 +1550,7 @@ pub const Zld = struct {...@@ -1555,7 +1550,7 @@ pub const Zld = struct {
1555 if (self.options.output_mode == .Lib) {1550 if (self.options.output_mode == .Lib) {
1556 sizeofcmds += blk: {1551 sizeofcmds += blk: {
1557 const install_name = self.options.install_name orelse self.options.emit.?.sub_path;1552 const install_name = self.options.install_name orelse self.options.emit.?.sub_path;
1558 break :blk calcInstallNameLen(1553 break :blk MachO.calcInstallNameLen(
1559 @sizeOf(macho.dylib_command),1554 @sizeOf(macho.dylib_command),
1560 install_name,1555 install_name,
1561 assume_max_path_len,1556 assume_max_path_len,
...@@ -1567,7 +1562,7 @@ pub const Zld = struct {...@@ -1567,7 +1562,7 @@ pub const Zld = struct {
1567 var it = RpathIterator.init(gpa, self.options.rpath_list);1562 var it = RpathIterator.init(gpa, self.options.rpath_list);
1568 defer it.deinit();1563 defer it.deinit();
1569 while (try it.next()) |rpath| {1564 while (try it.next()) |rpath| {
1570 sizeofcmds += calcInstallNameLen(1565 sizeofcmds += MachO.calcInstallNameLen(
1571 @sizeOf(macho.rpath_command),1566 @sizeOf(macho.rpath_command),
1572 rpath,1567 rpath,
1573 assume_max_path_len,1568 assume_max_path_len,
...@@ -1584,7 +1579,7 @@ pub const Zld = struct {...@@ -1584,7 +1579,7 @@ pub const Zld = struct {
1584 for (self.referenced_dylibs.keys()) |id| {1579 for (self.referenced_dylibs.keys()) |id| {
1585 const dylib = self.dylibs.items[id];1580 const dylib = self.dylibs.items[id];
1586 const dylib_id = dylib.id orelse unreachable;1581 const dylib_id = dylib.id orelse unreachable;
1587 sizeofcmds += calcInstallNameLen(1582 sizeofcmds += MachO.calcInstallNameLen(
1588 @sizeOf(macho.dylib_command),1583 @sizeOf(macho.dylib_command),
1589 dylib_id.name,1584 dylib_id.name,
1590 assume_max_path_len,1585 assume_max_path_len,