-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support PLT entries in cranelift-jit
crate on aarch64
#2735
Comments
cranelift-jit
crate on aarch64
@bnjbvr any thoughts on this? I'm not sure how PLTs ordinarily work on macOS/aarch64 but perhaps it's a simple addition? |
As workaround you could disable the |
This is one of the plt entries of an executable I compiled on my phone: 90 01 00 B0 adrp x16, #0x31000
11 F2 46 F9 ldr x17, [x16, #0xde0]
10 82 37 91 add x16, x16, #0xde0
20 02 1F D6 br x17 |
Tried with https://github.com/bytecodealliance/cranelift-jit-demo diff --git a/Cargo.toml b/Cargo.toml
index 756983f..f6dd93f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -8,7 +8,8 @@ description = "Toy language implemented using cranelift-jit"
edition = "2018"
[dependencies]
-cranelift = "0.69.0"
-cranelift-module = "0.69.0"
-cranelift-jit = "0.69.0"
+cranelift = "0.72.0"
+cranelift-module = "0.72.0"
+cranelift-jit = "0.72.0"
+cranelift-native = "0.72.0"
peg = "0.6"
diff --git a/src/jit.rs b/src/jit.rs
index 160ac36..ffcff04 100644
--- a/src/jit.rs
+++ b/src/jit.rs
@@ -26,7 +26,17 @@ pub struct JIT {
impl Default for JIT {
fn default() -> Self {
- let builder = JITBuilder::new(cranelift_module::default_libcall_names());
+ let mut flag_builder = settings::builder();
+ // On at least AArch64, "colocated" calls use shorter-range relocations,
+ // which might not reach all definitions; we can't handle that here, so
+ // we require long-range relocation types.
+ flag_builder.set("use_colocated_libcalls", "false").unwrap();
+ flag_builder.set("is_pic", "false").unwrap();
+ let isa_builder = cranelift_native::builder().unwrap_or_else(|msg| {
+ panic!("host machine is not supported: {}", msg);
+ });
+ let isa = isa_builder.finish(settings::Flags::new(flag_builder));
+ let builder = JITBuilder::with_isa(isa, cranelift_module::default_libcall_names());
let module = JITModule::new(builder);
Self {
builder_context: FunctionBuilderContext::new(),
I could maybe PR that because I don't see how PIC is really relevant to the demo and it would make it work on more platforms |
I don't know how PLT tables work in MacOS/aarch64 either. It's easy to make it work for our use case (load from pointer into reg + branch into it), but if the linker expects a precise sequence like the one from @bjorn3's comment, we'd need to find what is precisely expected. I don't plan to work on this immediately, yet I'd be happy to try patches if that can help! |
In case of |
Is this related to: bytecodealliance/wasmtime-go#53? |
@octaviopace no, this issue doesn't need to be solved in order to run Wasmtime on macOS/aarch64 (M1) -- the |
Issue #2907 is related to this. |
This involves a workaround for incomplete PIC support in `cranelift_jit` on ARM: bytecodealliance/wasmtime#2735 The workaround is just to disable PIC on that platform, but it unfortunately requires duplicating a little code from the library because the `JITBuilder::new` is hard-coded to use PIC.
Feature
JIT for arm64
Benefit
x86 works and it would be nice to be able to use it on M1 mac as well
Implementation
it currently panics here:
wasmtime/cranelift/jit/src/backend.rs
Lines 183 to 195 in 5fecdfa
Alternatives
only make JIT available on x86
The text was updated successfully, but these errors were encountered: