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

Plugin ABI is reliant on Rust toolchain version #335

Open
StefanBossbaly opened this issue Nov 29, 2023 · 0 comments
Open

Plugin ABI is reliant on Rust toolchain version #335

StefanBossbaly opened this issue Nov 29, 2023 · 0 comments

Comments

@StefanBossbaly
Copy link
Contributor

Description of Problem

Currently export_extn_metadata! will export the extn_library_create_metadata symbol with C-style linkage. This symbol will return a CExtnMetadata struct which also has C-style memory layout. However CExtnMetadata has fields of String type, which are not ABI stable. This means that plugins compiled using different toolchain versions that what Ripple was compiled in might not agree on the memory layout of a String. This will cause segfaults as the Plugin will construct what it considers to be a String and load_extn_library_metadata() will attempt to call the constructor and read the constructed strings, which have a different memory layout.

Sets to reproduce

  1. Compile local extn plugin with latest Rust version (1.73 as of writing this)
  2. Compile Ripple (because of rust-toolchain.toml version 1.69 of the toolchain will be used)
  3. Move extn shared object to Ripple workspace, update the configuration manifest to load local extn
  4. Run Ripple
  5. Watch the following fireworks

Output from Ripple

2023-11-28-21:14:59.767[DEBUG][ripple_sdk::extn::ffi::ffi_library][gateway]-Symbol extracted from library
log level debug
2023-11-28-21:14:59.768[INFO][ripple_sdk::extn::ffi::ffi_library][sec_manager]-exported symbols in library [{"fulfills":"[\"\\\"json_rpsee\\\"\"]","id":"ripple:extn:jsonrpsee:sec_manager","required_version":"1.0.0"}]
/home/workuser/.cargo/bin/ripple: line 63: 97631 Segmentation fault      THUNDER_HOST=${2} cargo run --features local_dev core/main

GDB Stacktrace

(gdb) bt
#0  __memcpy_generic () at ../sysdeps/aarch64/multiarch/../memcpy.S:131
#1  0x0000aaaae4bad9c0 in core::intrinsics::copy_nonoverlapping<u8> () at library/core/src/intrinsics.rs:2374
#2  core::ptr::const_ptr::{impl#0}::copy_to_nonoverlapping<u8> () at library/core/src/ptr/const_ptr.rs:1279
#3  alloc::slice::hack::{impl#1}::to_vec<u8, alloc::alloc::Global> () at library/alloc/src/slice.rs:167
#4  alloc::slice::hack::to_vec<u8, alloc::alloc::Global> () at library/alloc/src/slice.rs:111
#5  alloc::slice::{impl#0}::to_vec_in<u8, alloc::alloc::Global> () at library/alloc/src/slice.rs:441
#6  alloc::vec::{impl#11}::clone<u8, alloc::alloc::Global> () at library/alloc/src/vec/mod.rs:2655
#7  alloc::string::{impl#6}::clone () at library/alloc/src/string.rs:1992
#8  0x0000aaaae46d2700 in ripple_sdk::extn::ffi::ffi_library::{impl#0}::try_into (self=0xaaaaf5ffaf10) at core/sdk/src/extn/ffi/ffi_library.rs:58
#9  0x0000aaaae453ebc8 in ripple_sdk::extn::ffi::ffi_library::load_extn_library_metadata (lib=0xffffce4e8e08)
    at core/sdk/src/extn/ffi/ffi_library.rs:177
#10 0x0000aaaae3f8f254 in ripple::bootstrap::extn::load_extn_metadata_step::LoadExtensionMetadataStep::load_extension_library<alloc::string::String> (
    filename=..., entry=...) at core/main/src/bootstrap/extn/load_extn_metadata_step.rs:42
#11 0x0000aaaae3f8fcd8 in ripple::bootstrap::extn::load_extn_metadata_step::{impl#1}::setup::{async_block#0} (_task_context=0xffffce4f08c0)
    at core/main/src/bootstrap/extn/load_extn_metadata_step.rs:80
#12 0x0000aaaae426f600 in core::future::future::{impl#1}::poll<alloc::boxed::Box<(dyn core::future::future::Future<Output=core::result::Result<(), ripple_sdk::utils::error::RippleError>> + core::marker::Send), alloc::alloc::Global>> (self=..., cx=0xffffce4f08c0)

Solutions

  1. Added a section to the README that specifics that 1.69 must be used.
  2. Instead of using String use a C-Style string (ASCII chars with a null terminator) and then convert to Rust string then you won't have this problem since the ABI will be using C data structures which have been ABI stable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant