| ... | @@ -135,7 +135,9 @@ fn resolveAarch64( | ... | @@ -135,7 +135,9 @@ fn resolveAarch64( |
| 135 | inst.pc_relative_address.immlo = @truncate(u2, pages); | 135 | inst.pc_relative_address.immlo = @truncate(u2, pages); |
| 136 | mem.writeIntLittle(u32, &buffer, inst.toU32()); | 136 | mem.writeIntLittle(u32, &buffer, inst.toU32()); |
| 137 | }, | 137 | }, |
| 138 | .ARM64_RELOC_PAGEOFF12 => { | 138 | .ARM64_RELOC_PAGEOFF12, |
| | 139 | .ARM64_RELOC_GOT_LOAD_PAGEOFF12, |
| | 140 | => { |
| 139 | const narrowed = @truncate(u12, @intCast(u64, target_addr)); | 141 | const narrowed = @truncate(u12, @intCast(u64, target_addr)); |
| 140 | if (isArithmeticOp(&buffer)) { | 142 | if (isArithmeticOp(&buffer)) { |
| 141 | var inst = aarch64.Instruction{ | 143 | var inst = aarch64.Instruction{ |
| ... | @@ -170,18 +172,6 @@ fn resolveAarch64( | ... | @@ -170,18 +172,6 @@ fn resolveAarch64( |
| 170 | mem.writeIntLittle(u32, &buffer, inst.toU32()); | 172 | mem.writeIntLittle(u32, &buffer, inst.toU32()); |
| 171 | } | 173 | } |
| 172 | }, | 174 | }, |
| 173 | .ARM64_RELOC_GOT_LOAD_PAGEOFF12 => { | | |
| 174 | const narrowed = @truncate(u12, @intCast(u64, target_addr)); | | |
| 175 | var inst: aarch64.Instruction = .{ | | |
| 176 | .load_store_register = mem.bytesToValue(meta.TagPayload( | | |
| 177 | aarch64.Instruction, | | |
| 178 | aarch64.Instruction.load_store_register, | | |
| 179 | ), &buffer), | | |
| 180 | }; | | |
| 181 | const offset = @divExact(narrowed, 8); | | |
| 182 | inst.load_store_register.offset = offset; | | |
| 183 | mem.writeIntLittle(u32, &buffer, inst.toU32()); | | |
| 184 | }, | | |
| 185 | .ARM64_RELOC_TLVP_LOAD_PAGEOFF12 => { | 175 | .ARM64_RELOC_TLVP_LOAD_PAGEOFF12 => { |
| 186 | const RegInfo = struct { | 176 | const RegInfo = struct { |
| 187 | rd: u5, | 177 | rd: u5, |
| ... | @@ -226,11 +216,8 @@ fn resolveAarch64( | ... | @@ -226,11 +216,8 @@ fn resolveAarch64( |
| 226 | mem.writeIntLittle(u32, &buffer, inst.toU32()); | 216 | mem.writeIntLittle(u32, &buffer, inst.toU32()); |
| 227 | }, | 217 | }, |
| 228 | .ARM64_RELOC_POINTER_TO_GOT => { | 218 | .ARM64_RELOC_POINTER_TO_GOT => { |
| 229 | const result = math.cast( | 219 | const result = @intCast(i32, @intCast(i64, target_addr) - @intCast(i64, source_addr)); |
| 230 | i32, | 220 | mem.writeIntLittle(i32, &buffer, result); |
| 231 | @intCast(i64, target_addr) - @intCast(i64, source_addr), | | |
| 232 | ) orelse return error.Overflow; | | |
| 233 | mem.writeIntLittle(u32, &buffer, @bitCast(u32, result)); | | |
| 234 | }, | 221 | }, |
| 235 | .ARM64_RELOC_SUBTRACTOR => unreachable, | 222 | .ARM64_RELOC_SUBTRACTOR => unreachable, |
| 236 | .ARM64_RELOC_ADDEND => unreachable, | 223 | .ARM64_RELOC_ADDEND => unreachable, |
| ... | @@ -255,10 +242,7 @@ fn resolveX8664( | ... | @@ -255,10 +242,7 @@ fn resolveX8664( |
| 255 | .X86_64_RELOC_GOT_LOAD, | 242 | .X86_64_RELOC_GOT_LOAD, |
| 256 | .X86_64_RELOC_TLV, | 243 | .X86_64_RELOC_TLV, |
| 257 | => { | 244 | => { |
| 258 | const displacement = math.cast( | 245 | const displacement = @intCast(i32, @intCast(i64, target_addr) - @intCast(i64, source_addr) - 4); |
| 259 | i32, | | |
| 260 | @intCast(i64, target_addr) - @intCast(i64, source_addr) - 4, | | |
| 261 | ) orelse return error.Overflow; | | |
| 262 | mem.writeIntLittle(u32, buffer[0..4], @bitCast(u32, displacement)); | 246 | mem.writeIntLittle(u32, buffer[0..4], @bitCast(u32, displacement)); |
| 263 | break :blk buffer[0..4]; | 247 | break :blk buffer[0..4]; |
| 264 | }, | 248 | }, |
| ... | @@ -274,10 +258,7 @@ fn resolveX8664( | ... | @@ -274,10 +258,7 @@ fn resolveX8664( |
| 274 | .X86_64_RELOC_SIGNED_4 => 4, | 258 | .X86_64_RELOC_SIGNED_4 => 4, |
| 275 | else => unreachable, | 259 | else => unreachable, |
| 276 | }; | 260 | }; |
| 277 | const displacement = math.cast( | 261 | const displacement = @intCast(i32, target_addr - @intCast(i64, source_addr + correction + 4)); |
| 278 | i32, | | |
| 279 | target_addr - @intCast(i64, source_addr + correction + 4), | | |
| 280 | ) orelse return error.Overflow; | | |
| 281 | mem.writeIntLittle(u32, buffer[0..4], @bitCast(u32, displacement)); | 262 | mem.writeIntLittle(u32, buffer[0..4], @bitCast(u32, displacement)); |
| 282 | break :blk buffer[0..4]; | 263 | break :blk buffer[0..4]; |
| 283 | }, | 264 | }, |