Skip to content

Commit

Permalink
riscv64: Fix underflow in call relocation handling
Browse files Browse the repository at this point in the history
Under some test case layouts the call relocation
panicking with an underflow. Use `wrapping_sub` to
signal that this is expected.

The fuzzer took a while to generate such a test case.
And I can't introduce it as a regression test because
when running via the regular clif-util run tests the
layout is different and the test case passes!

I think this is because in the fuzzer we only add
one trampoline, while in clif-util we build trampolines
for each funcion in the file.
  • Loading branch information
afonso360 committed Mar 7, 2023
1 parent d3fdb5f commit 41260be
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion cranelift/jit/src/compiled_blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl CompiledBlob {
// Unlike the regular symbol relocations, here both "sub-relocations" point
// to the same address.
let hi20 = pcrel.wrapping_add(0x800) & 0xFFFFF000;
let lo12 = (pcrel - hi20) & 0xFFF;
let lo12 = pcrel.wrapping_sub(hi20) & 0xFFF;

unsafe {
// Do a R_RISCV_PCREL_HI20 on the `auipc`
Expand Down

0 comments on commit 41260be

Please sign in to comment.