diff --git a/Cargo.toml b/Cargo.toml index cda9752..0b126cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,4 +28,6 @@ native-cpu = ["snmalloc-sys/native-cpu"] local_dynamic_tls = ["snmalloc-sys/local_dynamic_tls"] win8compat = ["snmalloc-sys/win8compat"] usecxx17 = ["snmalloc-sys/usecxx17"] -check = ["snmalloc-sys/check"] \ No newline at end of file +check = ["snmalloc-sys/check"] +lto = ["snmalloc-sys/lto"] +notls = ["snmalloc-sys/notls"] diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index dcedae7..85452c8 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -28,3 +28,5 @@ local_dynamic_tls = [] win8compat = [] usecxx17 = [] check = [] +lto = [] +notls = [] diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index a431248..a1d02d8 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -108,12 +108,22 @@ fn main() { } if cfg!(feature = "cache-friendly") { - eprintln!("cache-friendly feature flag is deprecated and no longer has any effect. \ - it may be removed in a future release"); + eprintln!( + "cache-friendly feature flag is deprecated and no longer has any effect. \ + it may be removed in a future release" + ); // The following code no longer works // build.define("CACHE_FRIENDLY_OFFSET", "64"); } + if cfg!(feature = "lto") { + build.define("SNMALLOC_IPO", "ON"); + } + + if cfg!(feature = "notls") { + build.define("SNMALLOC_ENABLE_DYNAMIC_LOADING", "ON"); + } + build.compile(target); if target_env == "msvc" { @@ -140,14 +150,16 @@ fn main() { // no need } else { // link c++ runtime - println!("cargo:rustc-link-lib={}", - std::env::var("CXXSTDLIB").unwrap_or_else(|_| { - if cfg!(target_os = "macos") || cfg!(target_os = "openbsd") { - "c++".to_string() - } else { - "stdc++".to_string() - } - })) + println!( + "cargo:rustc-link-lib={}", + std::env::var("CXXSTDLIB").unwrap_or_else(|_| { + if cfg!(target_os = "macos") || cfg!(target_os = "openbsd") { + "c++".to_string() + } else { + "stdc++".to_string() + } + }) + ) } } @@ -305,13 +317,15 @@ fn main() { // not need for explicit c++ runtime } else { // link c++ runtime - println!("cargo:rustc-link-lib={}", - std::env::var("CXXSTDLIB").unwrap_or_else(|_| { - if cfg!(target_os = "macos") || cfg!(target_os = "openbsd") { - "c++".to_string() - } else { - "stdc++".to_string() - } - })) + println!( + "cargo:rustc-link-lib={}", + std::env::var("CXXSTDLIB").unwrap_or_else(|_| { + if cfg!(target_os = "macos") || cfg!(target_os = "openbsd") { + "c++".to_string() + } else { + "stdc++".to_string() + } + }) + ) } } diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index dc12688..b8e9e99 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit dc1268886a5d49d38a54e5d1402b5924a71fee0b +Subproject commit b8e9e99cf096357d37c67d423ccb657652879ba1 diff --git a/src/lib.rs b/src/lib.rs index cc31c31..457fcbf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -44,7 +44,6 @@ unsafe impl GlobalAlloc for SnMalloc { ffi::sn_rust_alloc(layout.align(), layout.size()) as _ } - /// De-allocate the memory at the given address with the given alignment and size. /// The client must assure the following things: /// - the memory is acquired using the same allocator and the pointer points to the start position. @@ -113,4 +112,15 @@ mod tests { alloc.dealloc(ptr, layout); } } + + #[test] + fn it_frees_large_alloc() { + unsafe { + let layout = Layout::from_size_align(1 << 20, 32).unwrap(); + let alloc = SnMalloc; + + let ptr = alloc.alloc(layout); + alloc.dealloc(ptr, layout); + } + } }