Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ See docs/process.md for more on how version tagging works.
- `emscripten_get_now()` (and `clock_gettime(CLOCK_MONOTONIC)`) in pthreads
builds now reads `performance.timeOrigin` once per thread. In Safari its value
can vary between reads, which made the clock go backwards. (#28272)
- Add workaround for `atomic.wait32` bug in Chrome 85 (which ships in Tizen 6.5
TVs). Note: Support for Chrome versions this old will likely be removed in
future releases. (#28313)

7.0.0 - 11/06/26
----------------
Expand Down
10 changes: 9 additions & 1 deletion system/lib/pthread/emscripten_futex_wait.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ static double dummy() {

weak_alias(dummy, _emscripten_next_timer);

// V8's Liftoff in Chromium 85 can clobber the caller's register-cached locals
// across memory.atomic.wait32, so wait in a separate function. The volatile
// pointer keeps Binaryen from inlining it back.
static int atomic_wait32(int* addr, int val, int64_t ns) {
return __builtin_wasm_memory_atomic_wait32(addr, val, ns);
}
static int (*volatile atomic_wait32_fn)(int*, int, int64_t) = atomic_wait32;
Comment on lines +142 to +147

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this can be changed to:

Suggested change
// across memory.atomic.wait32, so wait in a separate function. The volatile
// pointer keeps Binaryen from inlining it back.
static int atomic_wait32(int* addr, int val, int64_t ns) {
return __builtin_wasm_memory_atomic_wait32(addr, val, ns);
}
static int (*volatile atomic_wait32_fn)(int*, int, int64_t) = atomic_wait32;
// across memory.atomic.wait32, so wait in a separate function.
EMSCRIPTEN_NOINLINE
static int atomic_wait32(int* addr, int val, int64_t ns) {
return __builtin_wasm_memory_atomic_wait32(addr, val, ns);
}

(and atomic_wait32_fn -> atomic_wait32 below)

after PR #28406 lands. /cc @kripken

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, good idea @kleisauke !


static int _do_futex_wait(volatile void *addr, uint32_t val, double max_wait_ms) {
if ((((intptr_t)addr)&3) != 0) {
return -EINVAL;
Expand Down Expand Up @@ -178,7 +186,7 @@ static int _do_futex_wait(volatile void *addr, uint32_t val, double max_wait_ms)
uintptr_t expected_null = 0;
if (atomic_compare_exchange_strong(&self->wait_addr, &expected_null, (uintptr_t)addr)) {
DBG("emscripten_futex_wait atomic.wait ns=%lld", max_wait_ns);
ret = __builtin_wasm_memory_atomic_wait32((int*)addr, val, max_wait_ns);
ret = atomic_wait32_fn((int*)addr, val, max_wait_ns);
} else {
DBG("emscripten_futex_wait skipping atomic.wait due to NOTIFY_BIT");
// CAS failed, NOTIFY_BIT must have been set. In this case we don't
Expand Down
9 changes: 5 additions & 4 deletions test/codesize/test_codesize_minimal_pthreads.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 6829,
"a.out.js.gz": 3357,
"a.out.nodebug.wasm": 18950,
"a.out.nodebug.wasm.gz": 8760,
"total": 25779,
"total_gz": 12117,
"a.out.nodebug.wasm": 18979,
"a.out.nodebug.wasm.gz": 8784,
"total": 25808,
"total_gz": 12141,
"sent": [
"a (memory)",
"b (exit)",
Expand Down Expand Up @@ -108,6 +108,7 @@
"$a_inc",
"$a_store",
"$add",
"$atomic_wait32",
"$call_callback_then_free_ctx",
"$call_cancel_then_free_ctx",
"$call_then_finish_task",
Expand Down
9 changes: 5 additions & 4 deletions test/codesize/test_codesize_minimal_pthreads_memgrowth.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 7287,
"a.out.js.gz": 3578,
"a.out.nodebug.wasm": 18951,
"a.out.nodebug.wasm.gz": 8761,
"total": 26238,
"total_gz": 12339,
"a.out.nodebug.wasm": 18980,
"a.out.nodebug.wasm.gz": 8785,
"total": 26267,
"total_gz": 12363,
"sent": [
"a (memory)",
"b (exit)",
Expand Down Expand Up @@ -108,6 +108,7 @@
"$a_inc",
"$a_store",
"$add",
"$atomic_wait32",
"$call_callback_then_free_ctx",
"$call_cancel_then_free_ctx",
"$call_then_finish_task",
Expand Down