aboutsummaryrefslogtreecommitdiff
path: root/src/link/Coff/Relocation.zig
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/Coff/Relocation.zig
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/Coff/Relocation.zig')
-rw-r--r--src/link/Coff/Relocation.zig21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/link/Coff/Relocation.zig b/src/link/Coff/Relocation.zig
index ded7483667..050ab0d9be 100644
--- a/src/link/Coff/Relocation.zig
+++ b/src/link/Coff/Relocation.zig
@@ -137,7 +137,7 @@ fn resolveAarch64(self: Relocation, ctx: Context) void {
};
inst.pc_relative_address.immhi = @as(u19, @truncate(pages >> 2));
inst.pc_relative_address.immlo = @as(u2, @truncate(pages));
- mem.writeIntLittle(u32, buffer[0..4], inst.toU32());
+ mem.writeInt(u32, buffer[0..4], inst.toU32(), .Little);
},
.got_pageoff, .import_pageoff, .pageoff => {
assert(!self.pcrel);
@@ -151,7 +151,7 @@ fn resolveAarch64(self: Relocation, ctx: Context) void {
), buffer[0..4]),
};
inst.add_subtract_immediate.imm12 = narrowed;
- mem.writeIntLittle(u32, buffer[0..4], inst.toU32());
+ mem.writeInt(u32, buffer[0..4], inst.toU32(), .Little);
} else {
var inst = aarch64.Instruction{
.load_store_register = mem.bytesToValue(meta.TagPayload(
@@ -173,18 +173,19 @@ fn resolveAarch64(self: Relocation, ctx: Context) void {
}
};
inst.load_store_register.offset = offset;
- mem.writeIntLittle(u32, buffer[0..4], inst.toU32());
+ mem.writeInt(u32, buffer[0..4], inst.toU32(), .Little);
}
},
.direct => {
assert(!self.pcrel);
switch (self.length) {
- 2 => mem.writeIntLittle(
+ 2 => mem.writeInt(
u32,
buffer[0..4],
@as(u32, @truncate(ctx.target_vaddr + ctx.image_base)),
+ .Little,
),
- 3 => mem.writeIntLittle(u64, buffer[0..8], ctx.target_vaddr + ctx.image_base),
+ 3 => mem.writeInt(u64, buffer[0..8], ctx.target_vaddr + ctx.image_base, .Little),
else => unreachable,
}
},
@@ -207,17 +208,17 @@ fn resolveX86(self: Relocation, ctx: Context) void {
.got, .import => {
assert(self.pcrel);
const disp = @as(i32, @intCast(ctx.target_vaddr)) - @as(i32, @intCast(ctx.source_vaddr)) - 4;
- mem.writeIntLittle(i32, buffer[0..4], disp);
+ mem.writeInt(i32, buffer[0..4], disp, .Little);
},
.direct => {
if (self.pcrel) {
const disp = @as(i32, @intCast(ctx.target_vaddr)) - @as(i32, @intCast(ctx.source_vaddr)) - 4;
- mem.writeIntLittle(i32, buffer[0..4], disp);
+ mem.writeInt(i32, buffer[0..4], disp, .Little);
} else switch (ctx.ptr_width) {
- .p32 => mem.writeIntLittle(u32, buffer[0..4], @as(u32, @intCast(ctx.target_vaddr + ctx.image_base))),
+ .p32 => mem.writeInt(u32, buffer[0..4], @as(u32, @intCast(ctx.target_vaddr + ctx.image_base)), .Little),
.p64 => switch (self.length) {
- 2 => mem.writeIntLittle(u32, buffer[0..4], @as(u32, @truncate(ctx.target_vaddr + ctx.image_base))),
- 3 => mem.writeIntLittle(u64, buffer[0..8], ctx.target_vaddr + ctx.image_base),
+ 2 => mem.writeInt(u32, buffer[0..4], @as(u32, @truncate(ctx.target_vaddr + ctx.image_base)), .Little),
+ 3 => mem.writeInt(u64, buffer[0..8], ctx.target_vaddr + ctx.image_base, .Little),
else => unreachable,
},
}