GH-130396: Work around for broken pthread_get_stackaddr_np on Emscripten#131088
Conversation
… Emscripten Emscripten reports having `pthread_get_stackaddr_np` but it does nothing. I opened an upstream PR to actually fill in the stack information: emscripten-core/emscripten#23887 Until we can update to an Emscripten version that includes this fix, we can work around it by using `#define`s to replace `pthread_get_stackaddr_np` with the modified version.
freakboy3742
left a comment
There was a problem hiding this comment.
The general approach makes sense to me - although I'd like confirmation from @markshannon that he's OK with this as well.
In terms of functionality: this definitely works a lot better - I'm not getting the -sASSERTIONS error we were seeing in our pairing session earlier this week. However, it's not passing a full test run for me, for reasons that possibly seem related to (or, at least, intertwined with) this change:
$ ./python.sh -m test -v --rerun -W
...
0:02:30 load avg: 0.10 [250/485] test_ioctl skipped
0:02:30 load avg: 0.10 [251/485] test_ipaddress
0:02:30 load avg: 0.10 [251/485] test_ipaddress passed
0:02:30 load avg: 0.10 [252/485] test_isinstance
wasm://wasm/02937f2a:1
RangeError: Maximum call stack size exceeded
at wasm://wasm/02937f2a:wasm-function[12560]:0x65658a
at wasm://wasm/02937f2a:wasm-function[2087]:0x1ceea7
at wasm://wasm/02937f2a:wasm-function[2128]:0x1d01e1
at wasm://wasm/02937f2a:wasm-function[3676]:0x2b02da
at wasm://wasm/02937f2a:wasm-function[3677]:0x2b03c7
at wasm://wasm/02937f2a:wasm-function[2289]:0x1db42d
at wasm://wasm/02937f2a:wasm-function[3290]:0x26f6ef
at wasm://wasm/02937f2a:wasm-function[3291]:0x27f317
at wasm://wasm/02937f2a:wasm-function[760]:0x16d46b
at wasm://wasm/02937f2a:wasm-function[759]:0x16d397
Node.js v20.17.0
It happens a lot earlier in the test run if you use -uall (as we would be doing in a CI config):
$ ./python.sh -m test -v -uall --rerun -W
...
0:00:22 load avg: 0.10 [ 98/485] test_build_details
0:00:22 load avg: 0.10 [ 98/485] test_build_details passed
0:00:22 load avg: 0.10 [ 99/485] test_builtin
wasm://wasm/02937f2a:1
RangeError: Maximum call stack size exceeded
at wasm://wasm/02937f2a:wasm-function[2011]:0x1c23ef
at wasm://wasm/02937f2a:wasm-function[3218]:0x266cf6
at wasm://wasm/02937f2a:wasm-function[2011]:0x1c241d
at wasm://wasm/02937f2a:wasm-function[3218]:0x266cf6
at wasm://wasm/02937f2a:wasm-function[2011]:0x1c241d
at wasm://wasm/02937f2a:wasm-function[3218]:0x266cf6
at wasm://wasm/02937f2a:wasm-function[2011]:0x1c241d
at wasm://wasm/02937f2a:wasm-function[3218]:0x266cf6
at wasm://wasm/02937f2a:wasm-function[2011]:0x1c241d
at wasm://wasm/02937f2a:wasm-function[3218]:0x266cf6
Node.js v20.17.0
|
Pyodide gives much better stack traces on this sort of failure. I think one thing it does is call |
|
When I ran the tests locally with this fix I think they all passed, though I didn't pass |
I've been able to reproduce this failure locally (on macOS) and on the buildbot machine (linux). |
|
Indeed, I can reproduce it too. Maybe let's just add |
|
With the fix from #131158 applied, running on macOS, the test suite completes, but I get three test failures ( I'm also seeing failures with The new stack traces are really pretty though 😄 So - I'm happy to sign off on this; once we've got confirmation from @markshannon that he doesn't object to the approach, we can merge and we're one step closer to a buildbot! |
|
The fix for this just barely missed inclusion into Emscripten 4.0.5 but it will definitely be in 4.0.6. |
|
This approach seems fine to me. Protecting against stack overflow is very much a "practicality beats purity" thing. I used |
… Emscripten (python#131088) Implements a workaround implementation of `pthread_get_stackaddr_np` for Emscripten. This will be replaced by an implementation that will be included in Emscripten 4.0.6.

Emscripten reports having
pthread_get_stackaddr_npbut it does nothing. I opened an upstream PR to actually fill in the stack information: emscripten-core/emscripten#23887Until we can update to an Emscripten version that includes this fix, we can work around it by using
#defines to replacepthread_get_stackaddr_npwith the modified version.