- let path = Path::new(plugin);
- let res = DynamicLibrary::open(path);
- match res {
- Ok(_) => debug!("LLVM plugin loaded succesfully {} ({})", path.display(), plugin),
- Err(e) => bug!("couldn't load plugin: {}", e),
- }
- mem::forget(res);
+ let lib = Library::new(plugin).unwrap_or_else(|e| bug!("couldn't load plugin: {}", e));
+ debug!("LLVM plugin loaded successfully {:?} ({})", lib, plugin);
+
+ // Intentionally leak the dynamic library. We can't ever unload it
+ // since the library can make things that will live arbitrarily long.
+ mem::forget(lib);