Skip to content
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

Add functions for access emscripten stack layout information #11437

Merged
merged 3 commits into from
Jun 17, 2020
Merged

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Jun 17, 2020

This change adds emscripten_stack_get_base/free/end/current.

This is a cut down version of #11162 which uses wasm assembly
rather than relying on binaryen changes.

@sbc100 sbc100 changed the title WIP: Add functions for access emscripten stack layout information Add functions for access emscripten stack layout information Jun 17, 2020
@sbc100 sbc100 requested review from kripken and juj June 17, 2020 19:09
Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

tests/core/test_stack_get_free.out is empty?

lgtm aside from test issues

src/library_stack.js Show resolved Hide resolved
src/library_stack.js Outdated Show resolved Hide resolved
system/include/emscripten/stack.h Outdated Show resolved Hide resolved
system/include/emscripten/stack.h Outdated Show resolved Hide resolved

uintptr_t prevFree = emscripten_stack_get_free();
for(int i = 0; i < 10; ++i) {
void *p = alloca(emscripten_random() >= 0 ? 256*1024 : 255 * 1024);
Copy link
Member

Choose a reason for hiding this comment

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

the use of random here seems odd. is this to confuse the optimizer?

(also, spaces around * look inconsistent)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just copied this test from the other PR :) But yes I agree its strange.. @juj, why this?

This change adds emscripten_stack_get_base/free/end/current.

This is a cut down version of #11162 which uses wasm assembly
rather than relying on binaryen changes.

Also remove old emscripten_get_stack_base/emscripten_get_stack_top
from src/library.js.  emscripten_get_stack_top never worked anyway
since its was not marked as asm and therefore not referencing
the arm-internal version of STACKTOP.
@sbc100
Copy link
Collaborator Author

sbc100 commented Jun 17, 2020

I think this is good to land now. It believe it covers a lot of the original intent of #11162.

What I haven't included is the PROXIED_MAIN_TOTAL_STACK thing... @juj, I assume its OK to do that as a separate PR? Does that also need to land before fastcomp removal?

@sbc100 sbc100 merged commit 1b58a80 into master Jun 17, 2020
@sbc100 sbc100 deleted the stack_free branch June 17, 2020 23:07
if
call emscripten_stack_get_end
global.set __stack_end
end_if
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hey, thanks for working on this!

Having this in a .s file is a cool approach. However, this if branch makes this suboptimal compared to the solution that was presented in #11162 + WebAssembly/binaryen#2849 that did not need the branch :( (the original solution was just a single sub.

Any change we could get rid of this comparison?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, that sounds perfectly reasonable. Should be trivial change. I'm OK doing it, or you do you want to?

Copy link
Collaborator

@juj juj Jul 30, 2020

Choose a reason for hiding this comment

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

Thanks, if you have the cycles, that would be much appreciated!

@sbc100 sbc100 mentioned this pull request Jul 28, 2020
sbc100 pushed a commit that referenced this pull request Jul 31, 2020
This is a followup on #11437 which added this API.  Sadly today the
linker doesn't know the final memory layout so until we fix #11773
this extra `init` function is needed.

The alternative, which is to modify binaryen and emscripten to inject
the stack end value post-link is IMHO way to much complexity to justify
the convenience of not having the call this init function.

Once we fix #11773 the init function can become uneeded/no-op.
sbc100 pushed a commit that referenced this pull request Aug 5, 2020
This is a followup on #11437 which added this API.  Sadly today the
linker doesn't know the final memory layout so until we fix #11773
this extra `init` function is needed.

The alternative, which is to modify binaryen and emscripten to inject
the stack end value post-link is IMHO way to much complexity to justify
the convenience of not having the call this init function.

Once we fix #11773 the init function can become uneeded/no-op.
sbc100 pushed a commit that referenced this pull request Aug 6, 2020
This is a followup on #11437 which added this API.  Sadly today the
linker doesn't know the final memory layout so until we fix #11773
this extra `init` function is needed.

The alternative, which is to modify binaryen and emscripten to inject
the stack end value post-link is IMHO way to much complexity to justify
the convenience of not having the call this init function.

Once we fix #11773 the init function can become uneeded/no-op.
sbc100 pushed a commit that referenced this pull request Aug 6, 2020
This is a followup on #11437 which added this API.  Sadly today the
linker doesn't know the final memory layout so until we fix #11773
this extra `init` function is needed.

The alternative, which is to modify binaryen and emscripten to inject
the stack end value post-link is IMHO way to much complexity to justify
the convenience of not having the call this init function.

Once we fix #11773 the init function can become uneeded/no-op.
sbc100 pushed a commit that referenced this pull request Aug 6, 2020
This is a followup on #11437 which added this API.  Sadly today the
linker doesn't know the final memory layout so until we fix #11773
this extra `init` function is needed.

The alternative, which is to modify binaryen and emscripten to inject
the stack end value post-link is IMHO way to much complexity to justify
the convenience of not having the call this init function.

Once we fix #11773 the init function can become uneeded/no-op.
sbc100 added a commit that referenced this pull request Aug 7, 2020
This is a followup on #11437 which added this API.  Sadly today the
linker doesn't know the final memory layout so until we fix #11773
this extra `init` function is needed.

The alternative, which is to modify binaryen and emscripten to inject
the stack end value post-link is IMHO way to much complexity to justify
the convenience of not having the call this init function.

Once we fix #11773 the init function can become unneeded/no-op.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants