From 0bc211010efe9efe3b1d2e44b58d14e0ef444904 Mon Sep 17 00:00:00 2001 From: Evan Haas Date: Wed, 1 Nov 2023 12:16:21 -0700 Subject: [PATCH 1/2] Zig workaround: don't use packed structs larger than 128 bits. The C backend currently can't handle them --- src/Diagnostics.zig | 5 ++--- src/object/Elf.zig | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Diagnostics.zig b/src/Diagnostics.zig index 64ab6ca5..9229d01e 100644 --- a/src/Diagnostics.zig +++ b/src/Diagnostics.zig @@ -70,10 +70,9 @@ pub const Message = struct { pub const Tag = std.meta.DeclEnum(messages); -// u4 to avoid any possible packed struct issues -pub const Kind = enum(u4) { @"fatal error", @"error", note, warning, off, default }; +pub const Kind = enum { @"fatal error", @"error", note, warning, off, default }; -pub const Options = packed struct { +pub const Options = struct { // do not directly use these, instead add `const NAME = true;` all: Kind = .default, extra: Kind = .default, diff --git a/src/object/Elf.zig b/src/object/Elf.zig index 6493e5dc..b7e5c516 100644 --- a/src/object/Elf.zig +++ b/src/object/Elf.zig @@ -20,7 +20,7 @@ const Symbol = struct { info: u8, }; -const Relocation = packed struct { +const Relocation = struct { symbol: *Symbol, addend: i64, offset: u48, From a1b4bd6044e50dd10ceabb6b1fbd0b973ff266fd Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Thu, 2 Nov 2023 12:55:11 +0200 Subject: [PATCH 2/2] snake-case std.builtin.Endian --- deps/zig/codegen/x86_64.zig | 6 ++++-- src/Compilation.zig | 2 +- src/target.zig | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/deps/zig/codegen/x86_64.zig b/deps/zig/codegen/x86_64.zig index de99ba52..4b2c4f8b 100644 --- a/deps/zig/codegen/x86_64.zig +++ b/deps/zig/codegen/x86_64.zig @@ -176,19 +176,21 @@ pub const Encoder = struct { /// Directly write a number to the code array with big endianness pub fn writeIntBig(self: Self, comptime T: type, value: T) void { - mem.writeIntBig( + mem.writeInt( T, self.code.addManyAsArrayAssumeCapacity(@divExact(@typeInfo(T).Int.bits, 8)), value, + .big, ); } /// Directly write a number to the code array with little endianness pub fn writeIntLittle(self: Self, comptime T: type, value: T) void { - mem.writeIntLittle( + mem.writeInt( T, self.code.addManyAsArrayAssumeCapacity(@divExact(@typeInfo(T).Int.bits, 8)), value, + .little, ); } diff --git a/src/Compilation.zig b/src/Compilation.zig index 49846b8a..f026cbc2 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -404,7 +404,7 @@ pub fn generateBuiltinMacros(comp: *Compilation) !Source { \\#define __ORDER_PDP_ENDIAN__ 3412 \\ ); - if (comp.target.cpu.arch.endian() == .Little) try w.writeAll( + if (comp.target.cpu.arch.endian() == .little) try w.writeAll( \\#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ \\#define __LITTLE_ENDIAN__ 1 \\ diff --git a/src/target.zig b/src/target.zig index 2d38b2a3..526fce33 100644 --- a/src/target.zig +++ b/src/target.zig @@ -397,8 +397,8 @@ pub fn ldEmulationOption(target: std.Target, arm_endianness: ?std.builtin.Endian .thumb, .thumbeb, => switch (arm_endianness orelse target.cpu.arch.endian()) { - .Little => "armelf_linux_eabi", - .Big => "armelfb_linux_eabi", + .little => "armelf_linux_eabi", + .big => "armelfb_linux_eabi", }, .aarch64 => "aarch64linux", .aarch64_be => "aarch64linuxb",