-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Put stack first when not optimizing for size #18154
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
Conversation
be7ae72 to
b5c5696
Compare
c71a1a1 to
6489437
Compare
dschuff
left a comment
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.
Is there anything useful we can say in the changelog? Maybe just highlighting the user-visible difference in stack overflow behavior in unoptimized builds?
8ec1baa to
843dec7
Compare
f8a077b to
31b275b
Compare
|
Added a ChangeLog entry |
kripken
left a comment
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 ptrToString changes are from the other PR I think?)
f5074b6 to
d92f169
Compare
yes sorry, when I stack PRs like that and then one of them gets merged, it confuses github. Please ignore. |
0290330 to
07ac46a
Compare
|
I just found out that one of our users is doing something like the following in JS: |
|
|
Using Also, the value of |
|
oh, yeah, you're right. I was looking for a way that also correctly accounts for the globals size. |
730e936 to
c55df19
Compare
Also, when not using santizers (which currently rely on using the start of memory). This allows STACK_OVERFLOW_CHECK=1 to detect stack overflow conditions better without relying on the STACK_OVERFLOW_CHECK=2 binaryen pass. This works because when stack is placed first in memory stack overflow results in SP dropping below zero which is a runtime error. We can then distinguish such runtime errors by looking at the SP value at the time of the crash. This change is part of a sequence of the effort to reduce the default stack size. The hope here is that we will be able to accurately catch overflows in debug builds even without the STACK_OVERFLOW_CHECK=2 binaryen pass, thus minimizing the impact of reducing the stack size. See #14177
|
When a function needs to push its stack frame to accommodate for new items, does LLVM not do a stack overflow check right there and then in debug/other suitable builds? Needing to rely on the stack being in front of the memory address to get stack overflow to work seems silly and brittle, since it complicates build modes, and the same strategy can't extend to pthreads. |
No, by default in debug builds you don't get precise stack checking like that. In emscripten we have I had initially proposed that we make There may also be other llvm options to enable stack checking, but I think that would require specific command line flags for all compilation units (not just a link flag), and I don't think we use them all in emscripten today. We only use the non-llvm |
|
Thanks - yeah, I was thinking LLVM would be able to do this out of the box, seems odd if it doesn't. Though if/since it doesn't, then relying on the Wasm VM trap behavior does make sense. |
Also, when not using santizers (which currently rely on using the start
of memory).
This allows STACK_OVERFLOW_CHECK=1 to detect stack overflow conditions
better without relying on the STACK_OVERFLOW_CHECK=2 binaryen pass.
This works because when stack is placed first in memory stack overflow
results in SP dropping below zero which is a runtime error. We can
then distinguish such runtime errors by looking at the SP value at the
time of the crash.
This change is part of a sequence of the effort to reduce the default
stack size. The hope here is that we will be able to accurately catch
overflows in debug builds even without the STACK_OVERFLOW_CHECK=2
binaryen pass, thus minimizing the impact of reducing the stack size.
See #14177