Difference between cross and zigbuild
⚓ Rust 📅 2025-11-05 👤 surdeus 👁️ 6Hello,
I have a project which is working perfectly fine when compiled with cross and segfaulting (or bus error) when compiled with zigbuild. It is always working with cross and always segfaulting (or bus error) with zigbuild. The target is aarch64-unknown-linux-gnu.
My project is using an external library (programmed in C++). I only have the header files and the *.so libraries.
I am using cxx to interface my rust code with the library.
Here is some (simplified) sample of what I have in my cpp file (for cxx) :
namespace whatever {
void my_callback(Something *p) {}
std::unique_ptr<ExternalClass> create_internal()
{
auto some_object = std::make_unique<ExternalClass>();
some_object->setCallBack(my_callback); // commenting this line => no segfault / no bus error
return some_object;
}
std::unique_ptr<MyClass> create()
{
auto some_object= std::make_unique<MyClass>();
return some_object;
}
class MyClass::impl {
friend MyClass;
std::unique_ptr<ExternalClass> some_object;
};
MyClass::MyClass(): impl(new class MyClass::impl) {
this->impl->some_object = create_internal();
}
}
ExternalClass is a class declared in the external lib.
in my header file:
namespace whatever {
class MyClass{
public :
MyClass();
private:
class impl;
std::shared_ptr<impl> impl;
};
std::unique_ptr<MyClass> create();
}
my rust code for cxx:
#[cxx::bridge(namespace = "whatever")]
pub(crate) mod ffi {
extern "Rust" {
fn some_function(id: u8);
}
unsafe extern "C++" {
include!("project/include/header.h");
type MyClass;
fn create() -> Result<UniquePtr<MyClass>>;
}
}
unsafe impl Send for ffi::MyClass{}
unsafe impl Sync for ffi::MyClass{}
And then, I am creating my object in my rust code using ffi::create() and putting it inside a OnceLock<> to use it from anywhere.
Not sure where to look. A lot of these stuff feels like black magic to me.
The coredump stack trace is basically:
#0 0x00_BAD_ADDRESS_ZZZZZZZZZZ n/a
#1 0x00000_ADDRESS_IN_APP_YYYY _ZNSt3__110__function12__value_funcIFvP16SomethingEED2B8ne200100Ev
#2 0x00000_ADDRESS_IN_APP_XXXX _ZN8whatever21createEv
#3 0x00000_ADDRESS_IN_APP_WWWW _ZN8whatever6MyClassC1Ev
[...]
Someone has an idea where to look?
7 posts - 3 participants
🏷️ Rust_feed