Improve link_mem_intrinsics hack

Previously the `link_mem_intrinsics` hack actually had a runtime
overhead by storing a value into a global location, but it turns out we
can actually use a non-inlined function call as part of the *descriptor*
which requires this to be in the final binary, but we'll end up snip'ing
the value at the end.

All in all this should mean that it's not a zero-overhead solution for
linking these intrinsics! The `#[wasm_bindgen]` attribute already has
other problems if the descriptors don't show up, so that's the least of
our issues!
This commit is contained in:
Alex Crichton
2018-09-24 15:39:55 -07:00
parent d10ca579e4
commit b256b98e38
3 changed files with 5 additions and 25 deletions

View File

@ -846,21 +846,7 @@ pub mod __rt {
/// above. That means if this function is called and referenced we'll pull
/// in the object file and link the intrinsics.
///
/// Note that this is an `#[inline]` function to remove the function call
/// overhead we inject in functions, but right now it's unclear how to do
/// this in a zero-cost fashion. The lowest cost seems to be generating a
/// store that can't be optimized away (to a global), which is listed below.
///
/// Ideas for how to improve this are most welcome!
#[inline]
pub fn link_mem_intrinsics() {
// the above symbols only exist with the `std` feature enabled.
if !cfg!(feature = "std") {
return
}
use core::sync::atomic::*;
static FOO: AtomicUsize = ATOMIC_USIZE_INIT;
FOO.store(0, Ordering::SeqCst);
}
}