Browse Source
Merge pull request #3595 from Monadic-Cat/cranelift-jit-arm64call
Add support for `Arm64Call` relocations in `cranelift-jit`
pull/3597/head
Chris Fallin
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
21 additions and
0 deletions
-
cranelift/jit/src/compiled_blob.rs
|
|
@ -81,6 +81,27 @@ impl CompiledBlob { |
|
|
|
write_unaligned(at as *mut i32, pcrel) |
|
|
|
}; |
|
|
|
} |
|
|
|
Reloc::Arm64Call => { |
|
|
|
let base = get_address(name); |
|
|
|
// The instruction is 32 bits long.
|
|
|
|
let iptr = at as *mut u32; |
|
|
|
// The offset encoded in the `bl` instruction is the
|
|
|
|
// number of bytes divided by 4.
|
|
|
|
let diff = ((base as isize) - (at as isize)) >> 2; |
|
|
|
// Sign propagating right shift disposes of the
|
|
|
|
// included bits, so the result is expected to be
|
|
|
|
// either all sign bits or 0, depending on if the original
|
|
|
|
// value was negative or positive.
|
|
|
|
assert!((diff >> 26 == -1) || (diff >> 26 == 0)); |
|
|
|
// The lower 26 bits of the `bl` instruction form the
|
|
|
|
// immediate offset argument.
|
|
|
|
let chop = 32 - 26; |
|
|
|
let imm26 = (diff as u32) << chop >> chop; |
|
|
|
let ins = unsafe { iptr.read_unaligned() } | imm26; |
|
|
|
unsafe { |
|
|
|
iptr.write_unaligned(ins); |
|
|
|
} |
|
|
|
} |
|
|
|
_ => unimplemented!(), |
|
|
|
} |
|
|
|
} |
|
|
|