diff --git a/library/bdwgc/src/lib.rs b/library/bdwgc/src/lib.rs index e32dcca593223..3d336dbd60727 100644 --- a/library/bdwgc/src/lib.rs +++ b/library/bdwgc/src/lib.rs @@ -84,4 +84,6 @@ extern "C" { pub fn GC_ignore_warn_proc(proc: *mut u8, word: usize); pub fn GC_finalized_total() -> u64; + + pub fn GC_keep_alive(ptr: *mut u8); } diff --git a/library/std/src/gc.rs b/library/std/src/gc.rs index 7d1773104e560..c4d505176ca5a 100644 --- a/library/std/src/gc.rs +++ b/library/std/src/gc.rs @@ -173,6 +173,10 @@ pub fn thread_registered() -> bool { unsafe { bdwgc::GC_thread_is_registered() != 0 } } +pub fn keep_alive(ptr: *mut T) { + unsafe { bdwgc::GC_keep_alive(ptr as *mut u8) } +} + //////////////////////////////////////////////////////////////////////////////// // GC API //////////////////////////////////////////////////////////////////////////////// @@ -231,11 +235,7 @@ impl, U: ?Sized> DispatchFromDyn> for Gc {} #[cfg(all(not(bootstrap), not(test)))] impl Drop for Gc { fn drop(&mut self) { - unsafe { - // asm macro clobber by default, so this is enough to introduce a - // barrier. - core::arch::asm!("/* {0} */", in(reg) self); - } + keep_alive(self); } } diff --git a/src/bdwgc b/src/bdwgc index 0da451d7a9bee..5fe238773ec92 160000 --- a/src/bdwgc +++ b/src/bdwgc @@ -1 +1 @@ -Subproject commit 0da451d7a9bee23ce839a2f7e203afc97a77ad83 +Subproject commit 5fe238773ec92e3588b1420126d15fade7872973