Skip to content
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

sp-runtime-interface does not support 64-bit PolkaVM #7789

Open
2 tasks done
cmichi opened this issue Mar 3, 2025 · 3 comments
Open
2 tasks done

sp-runtime-interface does not support 64-bit PolkaVM #7789

cmichi opened this issue Mar 3, 2025 · 3 comments
Labels
I2-bug The node fails to follow expected behavior. I10-unconfirmed Issue might be valid, but it's not yet known.

Comments

@cmichi
Copy link
Contributor

cmichi commented Mar 3, 2025

Is there an existing issue?

  • I have searched the existing issues

Experiencing problems? Have you tried our Stack Exchange first?

  • This is not a support question.

Description of bug

@koute @athei @pgherveou

sp-runtime-interface can currently only be compiled to 64-bit PolkaVM if the feature disable_target_static_assertions is enabled. Typical parent crates (like sp-core) don't allow forwarding this feature, hence requiring users of e.g. sp-core to hack around this by overwriting/patching their own Cargo.toml.

This is the error currently:

$ pwd
/polkadot-sdk/substrate/primitives/runtime-interface

$ cargo +nightly check --no-default-features --target /polkavm/crates/polkavm-linker/riscv64emac-unknown-none-polkavm.json -Zbuild-std="core,alloc"
    Checking sp-runtime-interface v24.0.0 (/polkadot-sdk/substrate/primitives/runtime-interface)
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
  --> substrate/primitives/runtime-interface/src/impls.rs:47:1
   |
47 | assert_eq_size!(usize, u32);
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: source type: `usize` (64 bits)
   = note: target type: `u32` (32 bits)
   = note: this error originates in the macro `assert_eq_size` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
  --> substrate/primitives/runtime-interface/src/impls.rs:49:1
   |
49 | assert_eq_size!(*const u8, u32);
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: source type: `*const u8` (64 bits)
   = note: target type: `u32` (32 bits)
   = note: this error originates in the macro `assert_eq_size` (in Nightly builds, run with -Z macro-backtrace for more info)

What is the plan here? Initial support for PolkaVM was added to this crate over a year ago, but it broke along the way.

@cmichi cmichi added I10-unconfirmed Issue might be valid, but it's not yet known. I2-bug The node fails to follow expected behavior. labels Mar 3, 2025
@athei
Copy link
Member

athei commented Mar 4, 2025

What is the plan here? Initial support for PolkaVM was added to this crate over a year ago, but it broke along the way.

The plan was to transition runtimes to PolkaVM. However, in the mean time the priorities shifted for PolkaVM to JAM. So we never put in any work to make the transition to 64bit. That said, you can see that sp-runtime-interface has some mentions of riscv64. The error you are hitting should be easily fixable.

tl;dr: PRs welcome that make this crate compile under riscv64.

@bkchr
Copy link
Member

bkchr commented Mar 4, 2025

I doubt that we will ever bring 64bit support for runtimes and if so, it will be much more work than just changing this crate. Basically everything in the runtime is build a round the assumption that we only have 32bit. Not saying that it would not work, but we would probably need to check a lot of code etc.

@koute
Copy link
Contributor

koute commented Mar 5, 2025

What is the plan here? Initial support for PolkaVM was added to this crate over a year ago, but it broke along the way.

It should still work AFAIK, it just needs the 32-bit target.

I doubt that we will ever bring 64bit support for runtimes

Well, we will have to do it if/when we'll transition Polkadot to JAM, assuming we'll want to reuse most of the code so that e.g. the parachains will be able to migrate to JAM just by recompiling.

There is another alternative though. On AMD64 there's this ABI called x32 which essentially uses the 64-bit target with 64-bit registers, but with 32-bit pointers. This is exactly how 64-bit PolkaVM works, it's just we use the normal 64-bit ABI because that's what the upstream supports. So an alternative here could be to add a x32-like RISC-V ABI to LLVM and rustc, which would mean we'd still have a 32-bit usize even on the 64-bit target. (This is not totally trivial per se, but it would probably be doable, and it's much simpler and easier to do than maintaining a fully custom LLVM backend which we definitely don't want to do.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I2-bug The node fails to follow expected behavior. I10-unconfirmed Issue might be valid, but it's not yet known.
Projects
None yet
Development

No branches or pull requests

4 participants