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

dylib function that returns custom type when retrieved produces Segmentation Fault on macOS #30

Closed
fasihrana opened this issue Sep 4, 2017 · 4 comments

Comments

@fasihrana
Copy link

fasihrana commented Sep 4, 2017

macOS Sierra: 10.12.6 (16G29)

This issue references the issue created for rust-json

Sample Code is as follows:

Code for the dynamic library function is as follows:

#[macro_use]
extern crate json;

use json::JsonValue;

#[no_mangle]
pub fn methods() -> JsonValue
{
	let rt = array![
		object!{
			"fn" => "method 1"
    		}
	];
	rt
}

Code for my main.rs file is as follows:

extern crate json;
extern crate libloading as lib;

use std::env;
use json::JsonValue;

unsafe fn call_dynamic(libname: &String) -> lib::Result<()> {
	let dylib = try!(lib::Library::new(libname));
	let findmethods: lib::Symbol<fn() -> JsonValue> = dylib.get(b"methods")?;
	let funcs = findmethods();
	println!("{:#}", funcs);
	Ok(())
}

fn main(){
	let args: Vec<String> = env::args().collect();
	unsafe {
		call_dynamic(&args[1]).unwrap();
	}
}
@nagisa
Copy link
Owner

nagisa commented Sep 4, 2017

This could be a duplicate of #5, although I do need a backtrace to make sure.

You should make sure that the functions you’re trying to load dynamically are using a well-known ABI such as the C one. The default does not provide any ABI guarantees. Using a non-fully-repr(C) structures is likely to run into the same problems here.

@fasihrana
Copy link
Author

I'm not sure how to generate a backtrace on macOS. Any steps you could link me to?

I had the same problem when I used a custom enum. Then I tried Serde Json with libloading and that works perfectly fine. So my immediate problem has "gone away", but would like to get to the bottom of the issue.

@nagisa
Copy link
Owner

nagisa commented Sep 6, 2017 via email

@nagisa
Copy link
Owner

nagisa commented Apr 5, 2020

Closing as there has been no activity.

@nagisa nagisa closed this as completed Apr 5, 2020
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

2 participants