Skip to content

Commit eb550f5

Browse files
committed
Remove __wbindgen_global_argument_ptr intrinsic
We don't actually need this since we can simply pass in a number like 8 for the return pointer all the time. There's no need to allocate more space in static data for a return pointer tha may not even get used!
1 parent e16dd15 commit eb550f5

File tree

3 files changed

+11
-38
lines changed

3 files changed

+11
-38
lines changed

crates/cli-support/src/js/binding.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,20 @@ impl<'a, 'b> Builder<'a, 'b> {
118118
if incoming_args {
119119
let mut webidl_params = webidl.params.iter();
120120

121-
// If we're returning via an out pointer then it's guaranteed to be the
122-
// first argument. This isn't an argument of the function shim we're
123-
// generating so synthesize the parameter and its value.
121+
// If we're returning via an out pointer then it's guaranteed to be
122+
// the first argument. This isn't an argument of the function shim
123+
// we're generating so synthesize the parameter and its value.
124+
//
125+
// For the actual value of the return pointer we just pick the first
126+
// properly aligned nonzero address. We use the address for a
127+
// BigInt64Array sometimes which means it needs to be 8-byte
128+
// aligned. Otherwise valid code is unlikely to ever be working
129+
// around address 8, so this should be a safe address to use for
130+
// returning data through.
124131
if binding.return_via_outptr.is_some() {
125132
drop(webidl_params.next());
126-
self.cx.expose_global_argument_ptr()?;
127133
self.args_prelude
128-
.push_str("const retptr = globalArgumentPtr();\n");
134+
.push_str("const retptr = 8;\n");
129135
arg_names.push("retptr".to_string());
130136
}
131137

crates/cli-support/src/js/mod.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,25 +1558,6 @@ impl<'a> Context<'a> {
15581558
})
15591559
}
15601560

1561-
fn expose_global_argument_ptr(&mut self) -> Result<(), Error> {
1562-
if !self.should_write_global("global_argument_ptr") {
1563-
return Ok(());
1564-
}
1565-
self.require_internal_export("__wbindgen_global_argument_ptr")?;
1566-
self.global(
1567-
"
1568-
let cachedGlobalArgumentPtr = null;
1569-
function globalArgumentPtr() {
1570-
if (cachedGlobalArgumentPtr === null) {
1571-
cachedGlobalArgumentPtr = wasm.__wbindgen_global_argument_ptr();
1572-
}
1573-
return cachedGlobalArgumentPtr;
1574-
}
1575-
",
1576-
);
1577-
Ok(())
1578-
}
1579-
15801561
fn expose_get_inherited_descriptor(&mut self) {
15811562
if !self.should_write_global("get_inherited_descriptor") {
15821563
return;

src/lib.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,20 +1017,6 @@ pub mod __rt {
10171017
}
10181018
}
10191019

1020-
pub const GLOBAL_STACK_CAP: usize = 16;
1021-
1022-
// Increase the alignment to 8 here because this can be used as a
1023-
// BigUint64Array pointer base which requires alignment 8
1024-
#[repr(align(8))]
1025-
struct GlobalData([u32; GLOBAL_STACK_CAP]);
1026-
1027-
static mut GLOBAL_STACK: GlobalData = GlobalData([0; GLOBAL_STACK_CAP]);
1028-
1029-
#[no_mangle]
1030-
pub unsafe extern "C" fn __wbindgen_global_argument_ptr() -> *mut u32 {
1031-
GLOBAL_STACK.0.as_mut_ptr()
1032-
}
1033-
10341020
/// This is a curious function necessary to get wasm-bindgen working today,
10351021
/// and it's a bit of an unfortunate hack.
10361022
///

0 commit comments

Comments
 (0)