authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-02-04 05:48:25+01:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-02-04 22:58:38-05:00
logeaa6218f09d12fc84a29462f8287c0e6ecfd6739
treeb7d649de3f0f5185dbf2c5b75905edd33f271cf3
parentf5dbcd1cb4374be619ba0b18e40a069a7e860d93

x86_64: fix errors compiling the compiler

This fixes issues targetting both `x86_64-linux` and `x86_64-macos` with the self-hosted backend.

5 files changed, 55 insertions(+), 24 deletions(-)

lib/std/crypto/Certificate/Bundle/macos.zig+2-2
......@@ -21,7 +21,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
2121 const reader = stream.reader();
2222
2323 const db_header = try reader.readStructEndian(ApplDbHeader, .big);
24 assert(mem.eql(u8, "kych", &@as([4]u8, @bitCast(db_header.signature))));
24 assert(mem.eql(u8, &db_header.signature, "kych"));
2525
2626 try stream.seekTo(db_header.schema_offset);
2727
......@@ -73,7 +73,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
7373}
7474
7575const ApplDbHeader = extern struct {
76 signature: @Vector(4, u8),
76 signature: [4]u8,
7777 version: u32,
7878 header_size: u32,
7979 schema_offset: u32,
lib/std/crypto/tls/Client.zig+39-12
......@@ -452,11 +452,20 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
452452 if (ciphertext.len > cleartext_buf.len) return error.TlsRecordOverflow;
453453 const cleartext = cleartext_buf[0..ciphertext.len];
454454 const auth_tag = record_decoder.array(P.AEAD.tag_length).*;
455 const V = @Vector(P.AEAD.nonce_length, u8);
456 const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8);
457 const operand: V = pad ++ @as([8]u8, @bitCast(big(read_seq)));
455 const nonce = if (builtin.zig_backend == .stage2_x86_64 and
456 P.AEAD.nonce_length > comptime std.simd.suggestVectorLength(u8) orelse 1)
457 nonce: {
458 var nonce = p.server_handshake_iv;
459 const operand = std.mem.readInt(u64, nonce[nonce.len - 8 ..], .big);
460 std.mem.writeInt(u64, nonce[nonce.len - 8 ..], operand ^ read_seq, .big);
461 break :nonce nonce;
462 } else nonce: {
463 const V = @Vector(P.AEAD.nonce_length, u8);
464 const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8);
465 const operand: V = pad ++ @as([8]u8, @bitCast(big(read_seq)));
466 break :nonce @as(V, p.server_handshake_iv) ^ operand;
467 };
458468 read_seq += 1;
459 const nonce = @as(V, p.server_handshake_iv) ^ operand;
460469 P.AEAD.decrypt(cleartext, ciphertext, auth_tag, record_header, nonce, p.server_handshake_key) catch
461470 return error.TlsBadRecordMac;
462471 break :c cleartext;
......@@ -806,7 +815,6 @@ fn prepareCiphertextRecord(
806815 switch (c.application_cipher) {
807816 inline else => |*p| {
808817 const P = @TypeOf(p.*);
809 const V = @Vector(P.AEAD.nonce_length, u8);
810818 const overhead_len = tls.record_header_len + P.AEAD.tag_length + 1;
811819 const close_notify_alert_reserved = tls.close_notify_alert.len + overhead_len;
812820 while (true) {
......@@ -838,10 +846,20 @@ fn prepareCiphertextRecord(
838846 ciphertext_end += ciphertext_len;
839847 const auth_tag = ciphertext_buf[ciphertext_end..][0..P.AEAD.tag_length];
840848 ciphertext_end += auth_tag.len;
841 const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8);
842 const operand: V = pad ++ @as([8]u8, @bitCast(big(c.write_seq)));
849 const nonce = if (builtin.zig_backend == .stage2_x86_64 and
850 P.AEAD.nonce_length > comptime std.simd.suggestVectorLength(u8) orelse 1)
851 nonce: {
852 var nonce = p.client_iv;
853 const operand = std.mem.readInt(u64, nonce[nonce.len - 8 ..], .big);
854 std.mem.writeInt(u64, nonce[nonce.len - 8 ..], operand ^ c.write_seq, .big);
855 break :nonce nonce;
856 } else nonce: {
857 const V = @Vector(P.AEAD.nonce_length, u8);
858 const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8);
859 const operand: V = pad ++ @as([8]u8, @bitCast(big(c.write_seq)));
860 break :nonce @as(V, p.client_iv) ^ operand;
861 };
843862 c.write_seq += 1; // TODO send key_update on overflow
844 const nonce = @as(V, p.client_iv) ^ operand;
845863 P.AEAD.encrypt(ciphertext, auth_tag, cleartext, ad, nonce, p.client_key);
846864
847865 const record = ciphertext_buf[record_start..ciphertext_end];
......@@ -1102,15 +1120,24 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
11021120 const cleartext = switch (c.application_cipher) {
11031121 inline else => |*p| c: {
11041122 const P = @TypeOf(p.*);
1105 const V = @Vector(P.AEAD.nonce_length, u8);
11061123 const ad = frag[in - 5 ..][0..5];
11071124 const ciphertext_len = record_len - P.AEAD.tag_length;
11081125 const ciphertext = frag[in..][0..ciphertext_len];
11091126 in += ciphertext_len;
11101127 const auth_tag = frag[in..][0..P.AEAD.tag_length].*;
1111 const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8);
1112 const operand: V = pad ++ @as([8]u8, @bitCast(big(c.read_seq)));
1113 const nonce: [P.AEAD.nonce_length]u8 = @as(V, p.server_iv) ^ operand;
1128 const nonce = if (builtin.zig_backend == .stage2_x86_64 and
1129 P.AEAD.nonce_length > comptime std.simd.suggestVectorLength(u8) orelse 1)
1130 nonce: {
1131 var nonce = p.server_iv;
1132 const operand = std.mem.readInt(u64, nonce[nonce.len - 8 ..], .big);
1133 std.mem.writeInt(u64, nonce[nonce.len - 8 ..], operand ^ c.read_seq, .big);
1134 break :nonce nonce;
1135 } else nonce: {
1136 const V = @Vector(P.AEAD.nonce_length, u8);
1137 const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8);
1138 const operand: V = pad ++ @as([8]u8, @bitCast(big(c.read_seq)));
1139 break :nonce @as(V, p.server_iv) ^ operand;
1140 };
11141141 const out_buf = vp.peek();
11151142 const cleartext_buf = if (ciphertext.len <= out_buf.len)
11161143 out_buf
src/Sema.zig+2-1
......@@ -20136,6 +20136,7 @@ fn finishStructInit(
2013620136 },
2013720137 else => |e| return e,
2013820138 };
20139 try sema.resolveStructFieldInits(struct_ty);
2013920140 try sema.queueFullTypeResolution(struct_ty);
2014020141 const struct_val = try block.addAggregateInit(struct_ty, field_inits);
2014120142 return sema.coerce(block, result_ty, struct_val, init_src);
......@@ -35939,7 +35940,7 @@ pub fn resolveTypeFully(sema: *Sema, ty: Type) CompileError!void {
3593935940 return sema.resolveTypeFully(ty.childType(mod));
3594035941 },
3594135942 .Struct => switch (mod.intern_pool.indexToKey(ty.toIntern())) {
35942 .struct_type => return sema.resolveStructFully(ty),
35943 .struct_type => try sema.resolveStructFully(ty),
3594335944 .anon_struct_type => |tuple| {
3594435945 for (tuple.types.get(ip)) |field_ty| {
3594535946 try sema.resolveTypeFully(Type.fromInterned(field_ty));
src/TypedValue.zig+8-6
......@@ -310,11 +310,6 @@ pub fn print(
310310 return writer.writeAll(" }");
311311 },
312312 .ptr => |ptr| {
313 if (ptr.addr == .int) {}
314
315 const ptr_ty = ip.indexToKey(ty.toIntern()).ptr_type;
316 if (ptr_ty.flags.size == .Slice) {}
317
318313 switch (ptr.addr) {
319314 .decl => |decl_index| {
320315 const decl = mod.declPtr(decl_index);
......@@ -348,7 +343,14 @@ pub fn print(
348343 .val = Value.fromInterned(field_val_ip),
349344 }, writer, level - 1, mod);
350345 },
351 .int => unreachable,
346 .int => |int_ip| {
347 try writer.writeAll("@ptrFromInt(");
348 try print(.{
349 .ty = Type.usize,
350 .val = Value.fromInterned(int_ip),
351 }, writer, level - 1, mod);
352 try writer.writeByte(')');
353 },
352354 .eu_payload => |eu_ip| {
353355 try writer.writeAll("(payload of ");
354356 try print(.{
src/codegen/llvm/Builder.zig+4-3
......@@ -9978,10 +9978,10 @@ fn fnTypeAssumeCapacity(
99789978 }
99799979 pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool {
99809980 const rhs_data = ctx.builder.type_items.items[rhs_index];
9981 if (rhs_data.tag != tag) return false;
99819982 var rhs_extra = ctx.builder.typeExtraDataTrail(Type.Function, rhs_data.data);
99829983 const rhs_params = rhs_extra.trail.next(rhs_extra.data.params_len, Type, ctx.builder);
9983 return rhs_data.tag == tag and lhs_key.ret == rhs_extra.data.ret and
9984 std.mem.eql(Type, lhs_key.params, rhs_params);
9984 return lhs_key.ret == rhs_extra.data.ret and std.mem.eql(Type, lhs_key.params, rhs_params);
99859985 }
99869986 };
99879987 const gop = self.type_map.getOrPutAssumeCapacityAdapted(
......@@ -10161,9 +10161,10 @@ fn structTypeAssumeCapacity(
1016110161 }
1016210162 pub fn eql(ctx: @This(), lhs_key: []const Type, _: void, rhs_index: usize) bool {
1016310163 const rhs_data = ctx.builder.type_items.items[rhs_index];
10164 if (rhs_data.tag != tag) return false;
1016410165 var rhs_extra = ctx.builder.typeExtraDataTrail(Type.Structure, rhs_data.data);
1016510166 const rhs_fields = rhs_extra.trail.next(rhs_extra.data.fields_len, Type, ctx.builder);
10166 return rhs_data.tag == tag and std.mem.eql(Type, lhs_key, rhs_fields);
10167 return std.mem.eql(Type, lhs_key, rhs_fields);
1016710168 }
1016810169 };
1016910170 const gop = self.type_map.getOrPutAssumeCapacityAdapted(fields, Adapter{ .builder = self });