authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-03-26 01:06:14+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-03-26 08:48:38+01:00
log13b1050d4c898d472d424f9067d990df12eff3fb
tree636efdfb4e796d1b72a02dc5053c36340db83922
parent6bdb45beafbd72a4f70092257dd1e15a5c356558
signature Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

link.MachO.Dylib: allow aarch64-macos to match arm64e-macos TBD entries

closes https://codeberg.org/ziglang/zig/issues/31658

1 files changed, 25 insertions(+), 25 deletions(-)

src/link/MachO/Dylib.zig+25-25
......@@ -707,34 +707,36 @@ pub const TargetMatcher = struct {
707707 .cpu_arch = cpu_arch,
708708 .platform = platform,
709709 };
710 const apple_string = try targetToAppleString(allocator, cpu_arch, platform);
711 try self.target_strings.append(allocator, apple_string);
712710
713 switch (platform) {
714 .IOSSIMULATOR, .TVOSSIMULATOR, .WATCHOSSIMULATOR, .VISIONOSSIMULATOR => {
715 // For Apple simulator targets, linking gets tricky as we need to link against the simulator
716 // hosts dylibs too.
717 const host_target = try targetToAppleString(allocator, cpu_arch, .MACOS);
718 try self.target_strings.append(allocator, host_target);
719 },
711 try self.addTargetStrings(cpuArchToAppleString(cpu_arch));
712 // In Xcode 26.4, Apple unified their TBD files from having separate `arm64-macos` and `arm64e-macos`
713 // entries to having just the latter, presumably because the symbol lists are identical anyway. It
714 // sure would have been nice if they settled on the former as the unified name so as not to break the
715 // world, but evidently we can't have nice things.
716 if (cpu_arch == .aarch64) try self.addTargetStrings("arm64e");
717
718 return self;
719 }
720
721 fn addTargetStrings(self: *TargetMatcher, arch: []const u8) !void {
722 try self.target_strings.append(self.allocator, try std.fmt.allocPrint(
723 self.allocator,
724 "{s}-{s}",
725 .{ arch, platformToAppleString(self.platform) },
726 ));
727
728 switch (self.platform) {
720729 .MACCATALYST => {
721730 // Mac Catalyst is allowed to link macOS libraries in a TBD because Apple were apparently too lazy
722731 // to add the proper target strings despite doing so in other places in the format???
723 try self.target_strings.append(allocator, try targetToAppleString(allocator, cpu_arch, .MACOS));
732 try self.target_strings.append(self.allocator, try std.fmt.allocPrint(self.allocator, "{s}-macos", .{arch}));
724733 },
725 .MACOS => {
726 // Turns out that around 10.13/10.14 macOS release version, Apple changed the target tags in
727 // tbd files from `macosx` to `macos`. In order to be compliant and therefore actually support
728 // linking on older platforms against `libSystem.tbd`, we add `<cpu_arch>-macosx` to target_strings.
729 const fallback_target = try std.fmt.allocPrint(allocator, "{s}-macosx", .{
730 cpuArchToAppleString(cpu_arch),
731 });
732 try self.target_strings.append(allocator, fallback_target);
734 .IOSSIMULATOR, .TVOSSIMULATOR, .WATCHOSSIMULATOR, .VISIONOSSIMULATOR => {
735 // For Apple simulator targets, we need to link against the simulator host's libraries too.
736 try self.target_strings.append(self.allocator, try std.fmt.allocPrint(self.allocator, "{s}-macos", .{arch}));
733737 },
734738 else => {},
735739 }
736
737 return self;
738740 }
739741
740742 pub fn deinit(self: *TargetMatcher) void {
......@@ -744,7 +746,7 @@ pub const TargetMatcher = struct {
744746 self.target_strings.deinit(self.allocator);
745747 }
746748
747 inline fn cpuArchToAppleString(cpu_arch: std.Target.Cpu.Arch) []const u8 {
749 fn cpuArchToAppleString(cpu_arch: std.Target.Cpu.Arch) []const u8 {
748750 return switch (cpu_arch) {
749751 .aarch64 => "arm64",
750752 .x86_64 => "x86_64",
......@@ -752,9 +754,8 @@ pub const TargetMatcher = struct {
752754 };
753755 }
754756
755 pub fn targetToAppleString(allocator: Allocator, cpu_arch: std.Target.Cpu.Arch, platform: macho.PLATFORM) ![]const u8 {
756 const arch = cpuArchToAppleString(cpu_arch);
757 const plat = switch (platform) {
757 fn platformToAppleString(platform: macho.PLATFORM) []const u8 {
758 return switch (platform) {
758759 .MACOS => "macos",
759760 .IOS => "ios",
760761 .TVOS => "tvos",
......@@ -769,7 +770,6 @@ pub const TargetMatcher = struct {
769770 .DRIVERKIT => "driverkit",
770771 else => unreachable,
771772 };
772 return std.fmt.allocPrint(allocator, "{s}-{s}", .{ arch, plat });
773773 }
774774
775775 fn hasValue(stack: []const []const u8, needle: []const u8) bool {