Skip to content

Commit

Permalink
Merge pull request #532 from ehaas/cbe-workaround
Browse files Browse the repository at this point in the history
Zig workaround: don't use packed structs larger than 128 bits.
  • Loading branch information
Vexu authored Nov 2, 2023
2 parents 68095d5 + a1b4bd6 commit 87b6124
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
6 changes: 4 additions & 2 deletions deps/zig/codegen/x86_64.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
\\
Expand Down
5 changes: 2 additions & 3 deletions src/Diagnostics.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/object/Elf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Symbol = struct {
info: u8,
};

const Relocation = packed struct {
const Relocation = struct {
symbol: *Symbol,
addend: i64,
offset: u48,
Expand Down
4 changes: 2 additions & 2 deletions src/target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 87b6124

Please sign in to comment.