segmentation fault - Rust: Segfault when executing specific line of code from a dynamically loaded library -


I used a simple plug-in based system in Roost to gain some skills and gain experience to use the language I'm writing. My system loads libraries to start each plugin dynamically and executes them at runtime

This code is for loading and running the plugin input function: (This bit works fine )

  pub fn register_plugins & lt; 'Rp & gt; (& Amp; 'rp mut self) {p1 = match DynamicLibrary :: open (some ("librust_plugin_1.so")) {fine (Lib) = & gt; Lib, error (error) = & gt; Unsuccessful! ("Could not load library: {}", error)}; Let s1: extern "rust" fn (& PluginSystem) = unsafe {match p1.symbol ("init") {error (error) = & gt; Unsuccessful! ("Function init could not be loaded: {}", error), ok (init) = & gt; Mem :: transmute :: & lt; * Mut u8, _ & gt; (Init)}}; S1 (& self.ps); }  

This plugin has an init function within the Library:

  # [no_mangle] pub fn init (ps: and plug-in system) {ps. Register_plugin ("PS1"); // & lt; - Segfault this method has ps.add_new_hook_with_closure ("Onload," "ps1", "Display Greetings"., 10, test1); Println! ("Start Plugin."); }  

As commented, a plug-in system called segfault is within the string of string_plugin functions of string. This structure is borrowed from the calling method (in the first code segment).

This plugin has a register_plugin function in system:

  pub fn register_plugin (& mut self, plugin_name: & amp; str;) {if! Self.plugins.contains_key (& amp; plugin_name) {hm = hashmap :: new (); // & lt; - Segfault here self.plugins.insert (plugin_name, hm); }; }  

segfault occurs when executing hashMap :: new () in this code block;

I have tried to apply this function differently, as:

  pub fn register_plugin (and auto, plugin_name: & string) { Match.self.plugins.entry (plugin_name) {empty (entry) = & gt; {Entry.set (hashmap :: new ()); // & lt; - Segfault here} Capture (mut entry) => {}}}  

But I get exactly the same issue.

If I leave the register_plugin function, and I run the second code in the dynamically-loaded library, then it works fine. Actually there is only one code which segfaults on it hashmap :: new () .

Is this a bug or an existing problem, or am I doing something wrong?

More information: I have compiled rundown with debugging symbols to find the problem through stepping through a hashmap code. It seems that when debugging the code, while trying to execute the new function in the code, in code ,

 < Code> Pub unsafe FN Try (F: ||) - & gt; :: Main :: Results :: Results & lt; (), Box & lt; Any + Send & gt; & Gt; {Turn off: Closer = mem: Transmitter (F); Give ep = rust_try (try_fn, closed codename; c_void close, * mut c_void as closed). Return if ep.is_null () {OK (())} {my_ep = 'exception' as the form of EP; // & lt; - Rtdebug steps for this line! ("Caught {}", (* my_ep) .uwe.exception_class); Give reason = (* my_ep) .cause.take (); // & lt; - Segfaults here uw :: _Unwind_DeleteException (AP); Error (cause.unwrap ())};  

Segfault is caused by the cause.take () function, I think this is because my_ep.cause is zero or inaccessible, something generates an invalid exception And the try function is choking it and giving it to segfault. It is related to calling the hashmap code from a dynamically loaded library, but I do not know how it relates to is.

Thanks for any help.

EDIT: My platform is Linux X64, IIM is using a freshly made rig from GIT Master in the form of tomorrow (October 28 '14).

I have opened a problem on this about GitHub, with a minimal test case, and nothing Was solved in hours.

Actually, it was because rustc links to statistically linked libstd by default when constructing executables, and dynamically linking when creating libraries. The main one was using a static libstd, and at the runtime when the plugin loaded, the plugin uses a dynamic libstd.

For the main executable, rustc is fixed by adding -C preferred-dynamic .


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -