authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-03-04 00:02:09+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-03-04 17:28:03-05:00
log3c924abb69db4d508165857ca1c54696a77645ce
tree7cca2c41173b27c163c151519d0bafebd467f3e5
parent8363b951788a666802d6bbd6364eb973e2dbc09a

std.zig.llvm.bitcode_writer: Fix word byte order on big endian systems.

The bitcode format always uses little endian words. Prior to this commit, a bitcode file produced on e.g. aarch64_be or s390x would fail to be loaded by LLVM.

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

lib/std/zig/llvm/bitcode_writer.zig+4-4
......@@ -68,13 +68,13 @@ pub fn BitcodeWriter(comptime types: []const type) type {
6868 in_bits -= n;
6969
7070 if (self.bit_count != 0) return;
71 try self.buffer.append(self.bit_buffer);
71 try self.buffer.append(std.mem.nativeToLittle(u32, self.bit_buffer));
7272 self.bit_buffer = 0;
7373 }
7474
7575 // Write 32-bit chunks of input bits
7676 while (in_bits >= 32) {
77 try self.buffer.append(@truncate(in_buffer));
77 try self.buffer.append(std.mem.nativeToLittle(u32, @truncate(in_buffer)));
7878
7979 in_buffer >>= 31;
8080 in_buffer >>= 1;
......@@ -153,7 +153,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {
153153 pub fn alignTo32(self: *BcWriter) Error!void {
154154 if (self.bit_count == 0) return;
155155
156 try self.buffer.append(self.bit_buffer);
156 try self.buffer.append(std.mem.nativeToLittle(u32, self.bit_buffer));
157157 self.bit_buffer = 0;
158158 self.bit_count = 0;
159159 }
......@@ -209,7 +209,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {
209209 try self.bitcode.alignTo32();
210210
211211 // Set the number of words in the block at the start of the block
212 self.bitcode.buffer.items[self.start] = @truncate(self.bitcode.length() - self.start - 1);
212 self.bitcode.buffer.items[self.start] = std.mem.nativeToLittle(u32, @truncate(self.bitcode.length() - self.start - 1));
213213 }
214214
215215 pub fn writeUnabbrev(self: *Self, code: u32, values: []const u64) Error!void {