Hi,
I have the following setup. In src/test.cc:
extern "C" {
void *test() {
return new int();
}
}
and in src/main.rs:
use std::os::raw::c_void;
extern "C" {
#[link_name = "test"]
fn test() -> *const c_void;
}
fn main() {
println!("{:?}", unsafe { test() });
}
and build.rs:
use std::path::Path;
fn main() {
let dir = Path::new("src");
cc::Build::new()
.cpp(true)
.include(&dir)
.file(dir.join("test.cc"))
.compile("test");
}
cargo run works fine with x86_64-unknown-linux-gnu but when I try running with x86_64-unknown-linux-musl I get:
Segmentation fault (core dumped)
I think the error is something to do with rust and musl-g++ disagreeing about which c++ standard library to use. gbd confirms that the segfault happens in the call to new int();. Are there any pointers as to what is going wrong here? I am using unsafe to call the external function but I don't think I am doing anything to deserve a segfault.
SSCCE here: https://github.com/harrysarson/musl-rust-segfault. (I am using a musl toolchain compiled from https://github.com/richfelker/musl-cross-make because arch linux don't have a prebuilt musl c++ that I can install).