aboutsummaryrefslogtreecommitdiff
path: root/src/link/Elf
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2023-10-31 04:26:57 -0400
committerJacob Young <jacobly0@users.noreply.github.com>2023-10-31 21:37:35 -0400
commitd890e817610dd75feef55c1f7983190852c622a5 (patch)
tree679d13309da35aa957a9d20d28671d9b8673b5a1 /src/link/Elf
parent50cdb65784937965b5871037ff40bc34d8eb14af (diff)
downloadzig-d890e817610dd75feef55c1f7983190852c622a5.tar.gz
zig-d890e817610dd75feef55c1f7983190852c622a5.zip
mem: fix ub in writeInt
Use inline to vastly simplify the exposed API. This allows a comptime-known endian parameter to be propogated, making extra functions for a specific endianness completely unnecessary.
Diffstat (limited to 'src/link/Elf')
-rw-r--r--src/link/Elf/Atom.zig84
-rw-r--r--src/link/Elf/eh_frame.zig28
-rw-r--r--src/link/Elf/synthetic_sections.zig30
3 files changed, 72 insertions, 70 deletions
diff --git a/src/link/Elf/Atom.zig b/src/link/Elf/Atom.zig
index bb988a678f..f3b41f2e10 100644
--- a/src/link/Elf/Atom.zig
+++ b/src/link/Elf/Atom.zig
@@ -786,43 +786,43 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) !void {
elf.R_X86_64_PLT32,
elf.R_X86_64_PC32,
- => try cwriter.writeIntLittle(i32, @as(i32, @intCast(S + A - P))),
+ => try cwriter.writeInt(i32, @as(i32, @intCast(S + A - P)), .Little),
- elf.R_X86_64_GOTPCREL => try cwriter.writeIntLittle(i32, @as(i32, @intCast(G + GOT + A - P))),
- elf.R_X86_64_GOTPC32 => try cwriter.writeIntLittle(i32, @as(i32, @intCast(GOT + A - P))),
- elf.R_X86_64_GOTPC64 => try cwriter.writeIntLittle(i64, GOT + A - P),
+ elf.R_X86_64_GOTPCREL => try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A - P)), .Little),
+ elf.R_X86_64_GOTPC32 => try cwriter.writeInt(i32, @as(i32, @intCast(GOT + A - P)), .Little),
+ elf.R_X86_64_GOTPC64 => try cwriter.writeInt(i64, GOT + A - P, .Little),
elf.R_X86_64_GOTPCRELX => {
if (!target.flags.import and !target.isIFunc(elf_file) and !target.isAbs(elf_file)) blk: {
x86_64.relaxGotpcrelx(code[r_offset - 2 ..]) catch break :blk;
- try cwriter.writeIntLittle(i32, @as(i32, @intCast(S + A - P)));
+ try cwriter.writeInt(i32, @as(i32, @intCast(S + A - P)), .Little);
continue;
}
- try cwriter.writeIntLittle(i32, @as(i32, @intCast(G + GOT + A - P)));
+ try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A - P)), .Little);
},
elf.R_X86_64_REX_GOTPCRELX => {
if (!target.flags.import and !target.isIFunc(elf_file) and !target.isAbs(elf_file)) blk: {
x86_64.relaxRexGotpcrelx(code[r_offset - 3 ..]) catch break :blk;
- try cwriter.writeIntLittle(i32, @as(i32, @intCast(S + A - P)));
+ try cwriter.writeInt(i32, @as(i32, @intCast(S + A - P)), .Little);
continue;
}
- try cwriter.writeIntLittle(i32, @as(i32, @intCast(G + GOT + A - P)));
+ try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A - P)), .Little);
},
- elf.R_X86_64_32 => try cwriter.writeIntLittle(u32, @as(u32, @truncate(@as(u64, @intCast(S + A))))),
- elf.R_X86_64_32S => try cwriter.writeIntLittle(i32, @as(i32, @truncate(S + A))),
+ elf.R_X86_64_32 => try cwriter.writeInt(u32, @as(u32, @truncate(@as(u64, @intCast(S + A)))), .Little),
+ elf.R_X86_64_32S => try cwriter.writeInt(i32, @as(i32, @truncate(S + A)), .Little),
- elf.R_X86_64_TPOFF32 => try cwriter.writeIntLittle(i32, @as(i32, @truncate(S + A - TP))),
- elf.R_X86_64_TPOFF64 => try cwriter.writeIntLittle(i64, S + A - TP),
+ elf.R_X86_64_TPOFF32 => try cwriter.writeInt(i32, @as(i32, @truncate(S + A - TP)), .Little),
+ elf.R_X86_64_TPOFF64 => try cwriter.writeInt(i64, S + A - TP, .Little),
- elf.R_X86_64_DTPOFF32 => try cwriter.writeIntLittle(i32, @as(i32, @truncate(S + A - DTP))),
- elf.R_X86_64_DTPOFF64 => try cwriter.writeIntLittle(i64, S + A - DTP),
+ elf.R_X86_64_DTPOFF32 => try cwriter.writeInt(i32, @as(i32, @truncate(S + A - DTP)), .Little),
+ elf.R_X86_64_DTPOFF64 => try cwriter.writeInt(i64, S + A - DTP, .Little),
elf.R_X86_64_TLSGD => {
if (target.flags.has_tlsgd) {
const S_ = @as(i64, @intCast(target.tlsGdAddress(elf_file)));
- try cwriter.writeIntLittle(i32, @as(i32, @intCast(S_ + A - P)));
+ try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .Little);
} else if (target.flags.has_gottp) {
const S_ = @as(i64, @intCast(target.gotTpAddress(elf_file)));
try x86_64.relaxTlsGdToIe(self, rels[i .. i + 2], @intCast(S_ - P), elf_file, &stream);
@@ -843,7 +843,7 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) !void {
if (elf_file.got.tlsld_index) |entry_index| {
const tlsld_entry = elf_file.got.entries.items[entry_index];
const S_ = @as(i64, @intCast(tlsld_entry.address(elf_file)));
- try cwriter.writeIntLittle(i32, @as(i32, @intCast(S_ + A - P)));
+ try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .Little);
} else {
try x86_64.relaxTlsLdToLe(
self,
@@ -859,10 +859,10 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) !void {
elf.R_X86_64_GOTPC32_TLSDESC => {
if (target.flags.has_tlsdesc) {
const S_ = @as(i64, @intCast(target.tlsDescAddress(elf_file)));
- try cwriter.writeIntLittle(i32, @as(i32, @intCast(S_ + A - P)));
+ try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .Little);
} else {
try x86_64.relaxGotPcTlsDesc(code[r_offset - 3 ..]);
- try cwriter.writeIntLittle(i32, @as(i32, @intCast(S - TP)));
+ try cwriter.writeInt(i32, @as(i32, @intCast(S - TP)), .Little);
}
},
@@ -874,18 +874,18 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) !void {
elf.R_X86_64_GOTTPOFF => {
if (target.flags.has_gottp) {
const S_ = @as(i64, @intCast(target.gotTpAddress(elf_file)));
- try cwriter.writeIntLittle(i32, @as(i32, @intCast(S_ + A - P)));
+ try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .Little);
} else {
x86_64.relaxGotTpOff(code[r_offset - 3 ..]) catch unreachable;
- try cwriter.writeIntLittle(i32, @as(i32, @intCast(S - TP)));
+ try cwriter.writeInt(i32, @as(i32, @intCast(S - TP)), .Little);
}
},
- elf.R_X86_64_GOT32 => try cwriter.writeIntLittle(i32, @as(i32, @intCast(G + GOT + A))),
+ elf.R_X86_64_GOT32 => try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A)), .Little),
// Zig custom relocations
- Elf.R_X86_64_ZIG_GOT32 => try cwriter.writeIntLittle(u32, @as(u32, @intCast(ZIG_GOT + A))),
- Elf.R_X86_64_ZIG_GOTPCREL => try cwriter.writeIntLittle(i32, @as(i32, @intCast(ZIG_GOT + A - P))),
+ Elf.R_X86_64_ZIG_GOT32 => try cwriter.writeInt(u32, @as(u32, @intCast(ZIG_GOT + A)), .Little),
+ Elf.R_X86_64_ZIG_GOTPCREL => try cwriter.writeInt(i32, @as(i32, @intCast(ZIG_GOT + A - P)), .Little),
else => {},
}
@@ -920,7 +920,7 @@ fn resolveDynAbsReloc(
.copyrel,
.cplt,
.none,
- => try writer.writeIntLittle(i32, @as(i32, @truncate(S + A))),
+ => try writer.writeInt(i32, @as(i32, @truncate(S + A)), .Little),
.dyn_copyrel => {
if (is_writeable or elf_file.base.options.z_nocopyreloc) {
@@ -932,7 +932,7 @@ fn resolveDynAbsReloc(
});
try applyDynamicReloc(A, elf_file, writer);
} else {
- try writer.writeIntLittle(i32, @as(i32, @truncate(S + A)));
+ try writer.writeInt(i32, @as(i32, @truncate(S + A)), .Little);
}
},
@@ -946,7 +946,7 @@ fn resolveDynAbsReloc(
});
try applyDynamicReloc(A, elf_file, writer);
} else {
- try writer.writeIntLittle(i32, @as(i32, @truncate(S + A)));
+ try writer.writeInt(i32, @as(i32, @truncate(S + A)), .Little);
}
},
@@ -984,7 +984,7 @@ fn resolveDynAbsReloc(
fn applyDynamicReloc(value: i64, elf_file: *Elf, writer: anytype) !void {
_ = elf_file;
// if (elf_file.options.apply_dynamic_relocs) {
- try writer.writeIntLittle(i64, value);
+ try writer.writeInt(i64, value, .Little);
// }
}
@@ -1058,22 +1058,22 @@ pub fn resolveRelocsNonAlloc(self: Atom, elf_file: *Elf, code: []u8, undefs: any
switch (r_type) {
elf.R_X86_64_NONE => unreachable,
- elf.R_X86_64_8 => try cwriter.writeIntLittle(u8, @as(u8, @bitCast(@as(i8, @intCast(S + A))))),
- elf.R_X86_64_16 => try cwriter.writeIntLittle(u16, @as(u16, @bitCast(@as(i16, @intCast(S + A))))),
- elf.R_X86_64_32 => try cwriter.writeIntLittle(u32, @as(u32, @bitCast(@as(i32, @intCast(S + A))))),
- elf.R_X86_64_32S => try cwriter.writeIntLittle(i32, @as(i32, @intCast(S + A))),
- elf.R_X86_64_64 => try cwriter.writeIntLittle(i64, S + A),
- elf.R_X86_64_DTPOFF32 => try cwriter.writeIntLittle(i32, @as(i32, @intCast(S + A - DTP))),
- elf.R_X86_64_DTPOFF64 => try cwriter.writeIntLittle(i64, S + A - DTP),
- elf.R_X86_64_GOTOFF64 => try cwriter.writeIntLittle(i64, S + A - GOT),
- elf.R_X86_64_GOTPC64 => try cwriter.writeIntLittle(i64, GOT + A),
+ elf.R_X86_64_8 => try cwriter.writeInt(u8, @as(u8, @bitCast(@as(i8, @intCast(S + A)))), .Little),
+ elf.R_X86_64_16 => try cwriter.writeInt(u16, @as(u16, @bitCast(@as(i16, @intCast(S + A)))), .Little),
+ elf.R_X86_64_32 => try cwriter.writeInt(u32, @as(u32, @bitCast(@as(i32, @intCast(S + A)))), .Little),
+ elf.R_X86_64_32S => try cwriter.writeInt(i32, @as(i32, @intCast(S + A)), .Little),
+ elf.R_X86_64_64 => try cwriter.writeInt(i64, S + A, .Little),
+ elf.R_X86_64_DTPOFF32 => try cwriter.writeInt(i32, @as(i32, @intCast(S + A - DTP)), .Little),
+ elf.R_X86_64_DTPOFF64 => try cwriter.writeInt(i64, S + A - DTP, .Little),
+ elf.R_X86_64_GOTOFF64 => try cwriter.writeInt(i64, S + A - GOT, .Little),
+ elf.R_X86_64_GOTPC64 => try cwriter.writeInt(i64, GOT + A, .Little),
elf.R_X86_64_SIZE32 => {
const size = @as(i64, @intCast(target.elfSym(elf_file).st_size));
- try cwriter.writeIntLittle(u32, @as(u32, @bitCast(@as(i32, @intCast(size + A)))));
+ try cwriter.writeInt(u32, @as(u32, @bitCast(@as(i32, @intCast(size + A)))), .Little);
},
elf.R_X86_64_SIZE64 => {
const size = @as(i64, @intCast(target.elfSym(elf_file).st_size));
- try cwriter.writeIntLittle(i64, @as(i64, @intCast(size + A)));
+ try cwriter.writeInt(i64, @as(i64, @intCast(size + A)), .Little);
},
else => try self.reportUnhandledRelocError(rel, elf_file),
}
@@ -1254,7 +1254,7 @@ const x86_64 = struct {
0x64, 0x48, 0x8b, 0x04, 0x25, 0, 0, 0, 0, // movq %fs:0,%rax
0x48, 0x03, 0x05, 0, 0, 0, 0, // add foo@gottpoff(%rip), %rax
};
- std.mem.writeIntLittle(i32, insts[12..][0..4], value - 12);
+ std.mem.writeInt(i32, insts[12..][0..4], value - 12, .Little);
try stream.seekBy(-4);
try writer.writeAll(&insts);
},
@@ -1292,7 +1292,7 @@ const x86_64 = struct {
0x64, 0x48, 0x8b, 0, // mov %fs:(%rax), %rax
0x48, 0x2d, 0, 0, 0, 0, // sub $tls_size, %rax
};
- std.mem.writeIntLittle(i32, insts[8..][0..4], value);
+ std.mem.writeInt(i32, insts[8..][0..4], value, .Little);
try stream.seekBy(-3);
try writer.writeAll(&insts);
},
@@ -1306,7 +1306,7 @@ const x86_64 = struct {
0x48, 0x2d, 0, 0, 0, 0, // sub $tls_size, %rax
0x90, // nop
};
- std.mem.writeIntLittle(i32, insts[8..][0..4], value);
+ std.mem.writeInt(i32, insts[8..][0..4], value, .Little);
try stream.seekBy(-3);
try writer.writeAll(&insts);
},
@@ -1392,7 +1392,7 @@ const x86_64 = struct {
0x64, 0x48, 0x8b, 0x04, 0x25, 0, 0, 0, 0, // movq %fs:0,%rax
0x48, 0x81, 0xc0, 0, 0, 0, 0, // add $tp_offset, %rax
};
- std.mem.writeIntLittle(i32, insts[12..][0..4], value);
+ std.mem.writeInt(i32, insts[12..][0..4], value, .Little);
try stream.seekBy(-4);
try writer.writeAll(&insts);
relocs_log.debug(" relaxing {} and {}", .{
diff --git a/src/link/Elf/eh_frame.zig b/src/link/Elf/eh_frame.zig
index 468f673a9a..3f291f9a77 100644
--- a/src/link/Elf/eh_frame.zig
+++ b/src/link/Elf/eh_frame.zig
@@ -33,7 +33,7 @@ pub const Fde = struct {
pub fn ciePointer(fde: Fde, elf_file: *Elf) u32 {
const fde_data = fde.data(elf_file);
- return std.mem.readIntLittle(u32, fde_data[4..8]);
+ return std.mem.readInt(u32, fde_data[4..8], .Little);
}
pub fn calcSize(fde: Fde) usize {
@@ -217,10 +217,10 @@ pub const Iterator = struct {
var stream = std.io.fixedBufferStream(it.data[it.pos..]);
const reader = stream.reader();
- var size = try reader.readIntLittle(u32);
+ var size = try reader.readInt(u32, .Little);
if (size == 0xFFFFFFFF) @panic("TODO");
- const id = try reader.readIntLittle(u32);
+ const id = try reader.readInt(u32, .Little);
const record = Record{
.tag = if (id == 0) .cie else .fde,
.offset = it.pos,
@@ -298,10 +298,10 @@ fn resolveReloc(rec: anytype, sym: *const Symbol, rel: elf.Elf64_Rela, elf_file:
var where = contents[offset..];
switch (rel.r_type()) {
- elf.R_X86_64_32 => std.mem.writeIntLittle(i32, where[0..4], @as(i32, @truncate(S + A))),
- elf.R_X86_64_64 => std.mem.writeIntLittle(i64, where[0..8], S + A),
- elf.R_X86_64_PC32 => std.mem.writeIntLittle(i32, where[0..4], @as(i32, @intCast(S - P + A))),
- elf.R_X86_64_PC64 => std.mem.writeIntLittle(i64, where[0..8], S - P + A),
+ elf.R_X86_64_32 => std.mem.writeInt(i32, where[0..4], @as(i32, @truncate(S + A)), .Little),
+ elf.R_X86_64_64 => std.mem.writeInt(i64, where[0..8], S + A, .Little),
+ elf.R_X86_64_PC32 => std.mem.writeInt(i32, where[0..4], @as(i32, @intCast(S - P + A)), .Little),
+ elf.R_X86_64_PC64 => std.mem.writeInt(i64, where[0..8], S - P + A, .Little),
else => unreachable,
}
}
@@ -338,10 +338,11 @@ pub fn writeEhFrame(elf_file: *Elf, writer: anytype) !void {
const contents = try gpa.dupe(u8, fde.data(elf_file));
defer gpa.free(contents);
- std.mem.writeIntLittle(
+ std.mem.writeInt(
i32,
contents[4..8],
- @as(i32, @truncate(@as(i64, @intCast(fde.out_offset + 4)) - @as(i64, @intCast(fde.cie(elf_file).out_offset)))),
+ @truncate(@as(i64, @intCast(fde.out_offset + 4)) - @as(i64, @intCast(fde.cie(elf_file).out_offset))),
+ .Little,
);
for (fde.relocs(elf_file)) |rel| {
@@ -353,7 +354,7 @@ pub fn writeEhFrame(elf_file: *Elf, writer: anytype) !void {
}
}
- try writer.writeIntLittle(u32, 0);
+ try writer.writeInt(u32, 0, .Little);
}
pub fn writeEhFrameHdr(elf_file: *Elf, writer: anytype) !void {
@@ -365,14 +366,15 @@ pub fn writeEhFrameHdr(elf_file: *Elf, writer: anytype) !void {
const eh_frame_shdr = elf_file.shdrs.items[elf_file.eh_frame_section_index.?];
const eh_frame_hdr_shdr = elf_file.shdrs.items[elf_file.eh_frame_hdr_section_index.?];
const num_fdes = @as(u32, @intCast(@divExact(eh_frame_hdr_shdr.sh_size - eh_frame_hdr_header_size, 8)));
- try writer.writeIntLittle(
+ try writer.writeInt(
u32,
@as(u32, @bitCast(@as(
i32,
@truncate(@as(i64, @intCast(eh_frame_shdr.sh_addr)) - @as(i64, @intCast(eh_frame_hdr_shdr.sh_addr)) - 4),
))),
+ .Little,
);
- try writer.writeIntLittle(u32, num_fdes);
+ try writer.writeInt(u32, num_fdes, .Little);
const Entry = struct {
init_addr: u32,
@@ -401,7 +403,7 @@ pub fn writeEhFrameHdr(elf_file: *Elf, writer: anytype) !void {
const S = @as(i64, @intCast(sym.address(.{}, elf_file)));
const A = rel.r_addend;
entries.appendAssumeCapacity(.{
- .init_addr = @as(u32, @bitCast(@as(i32, @truncate(S + A - @as(i64, @intCast(eh_frame_hdr_shdr.sh_addr)))))),
+ .init_addr = @bitCast(@as(i32, @truncate(S + A - @as(i64, @intCast(eh_frame_hdr_shdr.sh_addr))))),
.fde_addr = @as(
u32,
@bitCast(@as(i32, @truncate(P - @as(i64, @intCast(eh_frame_hdr_shdr.sh_addr))))),
diff --git a/src/link/Elf/synthetic_sections.zig b/src/link/Elf/synthetic_sections.zig
index 91b9cc1248..0d78aea322 100644
--- a/src/link/Elf/synthetic_sections.zig
+++ b/src/link/Elf/synthetic_sections.zig
@@ -878,9 +878,9 @@ pub const PltSection = struct {
0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp qword ptr [rip] -> .got.plt[2]
};
var disp = @as(i64, @intCast(got_plt_addr + 8)) - @as(i64, @intCast(plt_addr + 8)) - 4;
- mem.writeIntLittle(i32, preamble[8..][0..4], @as(i32, @intCast(disp)));
+ mem.writeInt(i32, preamble[8..][0..4], @as(i32, @intCast(disp)), .Little);
disp = @as(i64, @intCast(got_plt_addr + 16)) - @as(i64, @intCast(plt_addr + 14)) - 4;
- mem.writeIntLittle(i32, preamble[14..][0..4], @as(i32, @intCast(disp)));
+ mem.writeInt(i32, preamble[14..][0..4], @as(i32, @intCast(disp)), .Little);
try writer.writeAll(&preamble);
try writer.writeByteNTimes(0xcc, preamble_size - preamble.len);
@@ -894,8 +894,8 @@ pub const PltSection = struct {
0x41, 0xbb, 0x00, 0x00, 0x00, 0x00, // mov r11d, N
0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp qword ptr [rip] -> .got.plt[N]
};
- mem.writeIntLittle(i32, entry[6..][0..4], @as(i32, @intCast(i)));
- mem.writeIntLittle(i32, entry[12..][0..4], @as(i32, @intCast(disp)));
+ mem.writeInt(i32, entry[6..][0..4], @as(i32, @intCast(i)), .Little);
+ mem.writeInt(i32, entry[12..][0..4], @as(i32, @intCast(disp)), .Little);
try writer.writeAll(&entry);
}
}
@@ -971,17 +971,17 @@ pub const GotPltSection = struct {
{
// [0]: _DYNAMIC
const symbol = elf_file.symbol(elf_file.dynamic_index.?);
- try writer.writeIntLittle(u64, symbol.value);
+ try writer.writeInt(u64, symbol.value, .Little);
}
// [1]: 0x0
// [2]: 0x0
- try writer.writeIntLittle(u64, 0x0);
- try writer.writeIntLittle(u64, 0x0);
+ try writer.writeInt(u64, 0x0, .Little);
+ try writer.writeInt(u64, 0x0, .Little);
if (elf_file.plt_section_index) |shndx| {
const plt_addr = elf_file.shdrs.items[shndx].sh_addr;
for (0..elf_file.plt.symbols.items.len) |_| {
// [N]: .plt
- try writer.writeIntLittle(u64, plt_addr);
+ try writer.writeInt(u64, plt_addr, .Little);
}
}
}
@@ -1023,7 +1023,7 @@ pub const PltGotSection = struct {
0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp qword ptr [rip] -> .got[N]
0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
};
- mem.writeIntLittle(i32, entry[6..][0..4], @as(i32, @intCast(disp)));
+ mem.writeInt(i32, entry[6..][0..4], @as(i32, @intCast(disp)), .Little);
try writer.writeAll(&entry);
}
}
@@ -1258,8 +1258,8 @@ pub const HashSection = struct {
}
try hs.buffer.ensureTotalCapacityPrecise(gpa, (2 + nsyms * 2) * 4);
- hs.buffer.writer(gpa).writeIntLittle(u32, @as(u32, @intCast(nsyms))) catch unreachable;
- hs.buffer.writer(gpa).writeIntLittle(u32, @as(u32, @intCast(nsyms))) catch unreachable;
+ hs.buffer.writer(gpa).writeInt(u32, @as(u32, @intCast(nsyms)), .Little) catch unreachable;
+ hs.buffer.writer(gpa).writeInt(u32, @as(u32, @intCast(nsyms)), .Little) catch unreachable;
hs.buffer.writer(gpa).writeAll(mem.sliceAsBytes(buckets)) catch unreachable;
hs.buffer.writer(gpa).writeAll(mem.sliceAsBytes(chains)) catch unreachable;
}
@@ -1322,10 +1322,10 @@ pub const GnuHashSection = struct {
var counting = std.io.countingWriter(writer);
const cwriter = counting.writer();
- try cwriter.writeIntLittle(u32, hash.num_buckets);
- try cwriter.writeIntLittle(u32, export_off);
- try cwriter.writeIntLittle(u32, hash.num_bloom);
- try cwriter.writeIntLittle(u32, bloom_shift);
+ try cwriter.writeInt(u32, hash.num_buckets, .Little);
+ try cwriter.writeInt(u32, export_off, .Little);
+ try cwriter.writeInt(u32, hash.num_bloom, .Little);
+ try cwriter.writeInt(u32, bloom_shift, .Little);
const gpa = elf_file.base.allocator;
const hashes = try gpa.alloc(u32, exports.len);