authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-10-01 02:06:24+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-10-03 00:57:36+02:00
log710a3b37e2f51010dcb37e4d39ba9ac77eddbd82
tree3d6a793baa3e130d26ed6ac06607555f211d55bd
parent125c043abc208842cd7e1deb188136600eb5c3ea
signature Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

link.MachO: Add exhaustive handling for all Apple target triples.


1 files changed, 27 insertions(+), 20 deletions(-)

src/link/MachO.zig+27-20
...@@ -3542,8 +3542,8 @@ pub fn requiresCodeSig(self: MachO) bool {...@@ -3542,8 +3542,8 @@ pub fn requiresCodeSig(self: MachO) bool {
3542 const target = self.getTarget();3542 const target = self.getTarget();
3543 return switch (target.cpu.arch) {3543 return switch (target.cpu.arch) {
3544 .aarch64 => switch (target.os.tag) {3544 .aarch64 => switch (target.os.tag) {
3545 .macos => true,3545 .bridgeos, .driverkit, .macos => true,
3546 .watchos, .tvos, .ios, .visionos => target.abi == .simulator,3546 .ios, .tvos, .visionos, .watchos => target.abi == .simulator,
3547 else => false,3547 else => false,
3548 },3548 },
3549 .x86_64 => false,3549 .x86_64 => false,
...@@ -4172,36 +4172,38 @@ pub const Platform = struct {...@@ -4172,36 +4172,38 @@ pub const Platform = struct {
4172 const cmd = lc.cast(macho.build_version_command).?;4172 const cmd = lc.cast(macho.build_version_command).?;
4173 return .{4173 return .{
4174 .os_tag = switch (cmd.platform) {4174 .os_tag = switch (cmd.platform) {
4175 .MACOS => .macos,4175 .BRIDGEOS => .bridgeos,
4176 .DRIVERKIT => .driverkit,
4176 .IOS, .IOSSIMULATOR => .ios,4177 .IOS, .IOSSIMULATOR => .ios,
4177 .TVOS, .TVOSSIMULATOR => .tvos,
4178 .WATCHOS, .WATCHOSSIMULATOR => .watchos,
4179 .MACCATALYST => .ios,4178 .MACCATALYST => .ios,
4179 .MACOS => .macos,
4180 .TVOS, .TVOSSIMULATOR => .tvos,
4180 .VISIONOS, .VISIONOSSIMULATOR => .visionos,4181 .VISIONOS, .VISIONOSSIMULATOR => .visionos,
4182 .WATCHOS, .WATCHOSSIMULATOR => .watchos,
4181 else => @panic("TODO"),4183 else => @panic("TODO"),
4182 },4184 },
4183 .abi = switch (cmd.platform) {4185 .abi = switch (cmd.platform) {
4184 .MACCATALYST => .macabi,4186 .MACCATALYST => .macabi,
4185 .IOSSIMULATOR,4187 .IOSSIMULATOR,
4186 .TVOSSIMULATOR,4188 .TVOSSIMULATOR,
4187 .WATCHOSSIMULATOR,
4188 .VISIONOSSIMULATOR,4189 .VISIONOSSIMULATOR,
4190 .WATCHOSSIMULATOR,
4189 => .simulator,4191 => .simulator,
4190 else => .none,4192 else => .none,
4191 },4193 },
4192 .version = appleVersionToSemanticVersion(cmd.minos),4194 .version = appleVersionToSemanticVersion(cmd.minos),
4193 };4195 };
4194 },4196 },
4195 .VERSION_MIN_MACOSX,
4196 .VERSION_MIN_IPHONEOS,4197 .VERSION_MIN_IPHONEOS,
4198 .VERSION_MIN_MACOSX,
4197 .VERSION_MIN_TVOS,4199 .VERSION_MIN_TVOS,
4198 .VERSION_MIN_WATCHOS,4200 .VERSION_MIN_WATCHOS,
4199 => {4201 => {
4200 const cmd = lc.cast(macho.version_min_command).?;4202 const cmd = lc.cast(macho.version_min_command).?;
4201 return .{4203 return .{
4202 .os_tag = switch (lc.cmd()) {4204 .os_tag = switch (lc.cmd()) {
4203 .VERSION_MIN_MACOSX => .macos,
4204 .VERSION_MIN_IPHONEOS => .ios,4205 .VERSION_MIN_IPHONEOS => .ios,
4206 .VERSION_MIN_MACOSX => .macos,
4205 .VERSION_MIN_TVOS => .tvos,4207 .VERSION_MIN_TVOS => .tvos,
4206 .VERSION_MIN_WATCHOS => .watchos,4208 .VERSION_MIN_WATCHOS => .watchos,
4207 else => unreachable,4209 else => unreachable,
...@@ -4228,15 +4230,17 @@ pub const Platform = struct {...@@ -4228,15 +4230,17 @@ pub const Platform = struct {
42284230
4229 pub fn toApplePlatform(plat: Platform) macho.PLATFORM {4231 pub fn toApplePlatform(plat: Platform) macho.PLATFORM {
4230 return switch (plat.os_tag) {4232 return switch (plat.os_tag) {
4231 .macos => .MACOS,4233 .bridgeos => .BRIDGEOS,
4234 .driverkit => .DRIVERKIT,
4232 .ios => switch (plat.abi) {4235 .ios => switch (plat.abi) {
4233 .simulator => .IOSSIMULATOR,
4234 .macabi => .MACCATALYST,4236 .macabi => .MACCATALYST,
4237 .simulator => .IOSSIMULATOR,
4235 else => .IOS,4238 else => .IOS,
4236 },4239 },
4240 .macos => .MACOS,
4237 .tvos => if (plat.abi == .simulator) .TVOSSIMULATOR else .TVOS,4241 .tvos => if (plat.abi == .simulator) .TVOSSIMULATOR else .TVOS,
4238 .watchos => if (plat.abi == .simulator) .WATCHOSSIMULATOR else .WATCHOS,
4239 .visionos => if (plat.abi == .simulator) .VISIONOSSIMULATOR else .VISIONOS,4242 .visionos => if (plat.abi == .simulator) .VISIONOSSIMULATOR else .VISIONOS,
4243 .watchos => if (plat.abi == .simulator) .WATCHOSSIMULATOR else .WATCHOS,
4240 else => unreachable,4244 else => unreachable,
4241 };4245 };
4242 }4246 }
...@@ -4305,15 +4309,18 @@ const SupportedPlatforms = struct {...@@ -4305,15 +4309,18 @@ const SupportedPlatforms = struct {
4305// Source: https://github.com/apple-oss-distributions/ld64/blob/59a99ab60399c5e6c49e6945a9e1049c42b71135/src/ld/PlatformSupport.cpp#L524309// Source: https://github.com/apple-oss-distributions/ld64/blob/59a99ab60399c5e6c49e6945a9e1049c42b71135/src/ld/PlatformSupport.cpp#L52
4306// zig fmt: off4310// zig fmt: off
4307const supported_platforms = [_]SupportedPlatforms{4311const supported_platforms = [_]SupportedPlatforms{
4308 .{ .macos, .none, 0xA0E00, 0xA0800 },4312 .{ .bridgeos, .none, 0x010000, 0x010000 },
4309 .{ .ios, .none, 0xC0000, 0x70000 },4313 .{ .driverkit, .none, 0x130000, 0x130000 },
4310 .{ .tvos, .none, 0xC0000, 0x70000 },4314 .{ .ios, .none, 0x0C0000, 0x070000 },
4311 .{ .watchos, .none, 0x50000, 0x20000 },4315 .{ .ios, .macabi, 0x0D0000, 0x0D0000 },
4312 .{ .visionos, .none, 0x10000, 0x10000 },4316 .{ .ios, .simulator, 0x0D0000, 0x080000 },
4313 .{ .ios, .simulator, 0xD0000, 0x80000 },4317 .{ .macos, .none, 0x0A0E00, 0x0A0800 },
4314 .{ .tvos, .simulator, 0xD0000, 0x80000 },4318 .{ .tvos, .none, 0x0C0000, 0x070000 },
4315 .{ .watchos, .simulator, 0x60000, 0x20000 },4319 .{ .tvos, .simulator, 0x0D0000, 0x080000 },
4316 .{ .visionos, .simulator, 0x10000, 0x10000 },4320 .{ .visionos, .none, 0x010000, 0x010000 },
4321 .{ .visionos, .simulator, 0x010000, 0x010000 },
4322 .{ .watchos, .none, 0x050000, 0x020000 },
4323 .{ .watchos, .simulator, 0x060000, 0x020000 },
4317};4324};
4318// zig fmt: on4325// zig fmt: on
43194326