2016-09-17 04:53:14 +08:00
|
|
|
#![feature(drop_types_in_const)]
|
|
|
|
|
|
|
|
extern crate libloading;
|
|
|
|
|
|
|
|
use std::sync::{Once, ONCE_INIT};
|
|
|
|
|
|
|
|
use libloading::Library;
|
|
|
|
|
|
|
|
static mut GCC_S: Option<Library> = None;
|
|
|
|
|
2016-09-18 08:54:29 +08:00
|
|
|
#[cfg(not(windows))]
|
2016-09-17 04:53:14 +08:00
|
|
|
fn gcc_s() -> &'static Library {
|
2016-09-18 08:54:29 +08:00
|
|
|
#[cfg(not(target_os = "macos"))]
|
|
|
|
const LIBGCC_S: &'static str = "libgcc_s.so.1";
|
|
|
|
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
const LIBGCC_S: &'static str = "libgcc_s.1.dylib";
|
|
|
|
|
2016-09-17 04:53:14 +08:00
|
|
|
unsafe {
|
|
|
|
static INIT: Once = ONCE_INIT;
|
|
|
|
|
|
|
|
INIT.call_once(|| {
|
2016-09-18 08:54:29 +08:00
|
|
|
GCC_S = Some(Library::new(LIBGCC_S).unwrap());
|
2016-09-17 04:53:14 +08:00
|
|
|
});
|
|
|
|
GCC_S.as_ref().unwrap()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-18 08:54:29 +08:00
|
|
|
#[cfg(windows)]
|
2016-09-27 13:22:10 +08:00
|
|
|
pub fn get(_sym: &str) -> Option<usize> {
|
|
|
|
None
|
2016-09-18 08:54:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(windows))]
|
2016-09-27 13:22:10 +08:00
|
|
|
pub fn get(sym: &str) -> Option<usize> {
|
|
|
|
unsafe {
|
|
|
|
gcc_s().get(sym.as_bytes()).ok().map(|s| *s)
|
2016-09-17 04:53:14 +08:00
|
|
|
}
|
|
|
|
}
|