-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
GH-130396: Work around for broken pthread_get_stackaddr_np
on Emscripten
#131088
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
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 |
The goal of Emscripten is to behave as much like linux as possible, subject to other the architecture and platform constraints and the desire to minimize code size. So in cases like this, finding discrepancies with normal linux and resolving them in Emscripten is ideal. If there were a cheap way to ask about the true stack in addition to the spill stack, that would be great but as it is at least we can ask about the spill stack correctly. Maybe now if we set the size of the spill stack to be kind of small the stack checks will work a bit more often. |
… 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 (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_np
but 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
#define
s to replacepthread_get_stackaddr_np
with the modified version.