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

wasmz.test_cubescript fails on the upstream backend #9527

Open
kripken opened this issue Sep 27, 2019 · 8 comments
Open

wasmz.test_cubescript fails on the upstream backend #9527

kripken opened this issue Sep 27, 2019 · 8 comments
Assignees
Labels

Comments

@kripken
Copy link
Member

kripken commented Sep 27, 2019

None of our CI tests that combination, so this was missed. It might be a very old breakage, I didn't check how far back it is, I just noticed it as I ran some random tests.

Fails on

exception thrown: RuntimeError: function signature mismatch,RuntimeError: function signature mismatch

update: this is due to eval_ctors.

@kripken kripken changed the title wasmz.test_cubescript fails wasmz.test_cubescript fails on the upstream backend Sep 27, 2019
@sbc100 sbc100 self-assigned this Sep 27, 2019
@kripken
Copy link
Member Author

kripken commented Sep 27, 2019

@sbc100 Sorry, I forgot to assign this to myself, but I've already started to look into it, and have a partial theory. Unless you've already made progress towards a fix, I can probably finish it?

@sbc100
Copy link
Collaborator

sbc100 commented Sep 27, 2019

Awesome! Please take it

@sbc100 sbc100 assigned kripken and unassigned sbc100 Sep 27, 2019
@kripken
Copy link
Member Author

kripken commented Sep 27, 2019

It looks like this is a regression from the sbrk optimizations I did a while back.

sbrk is now implemented entirely in wasm, which allows eval-ctors to do a lot more work - it thinks it can eval mallocs at compile time. However, we set the location of the brk in JS at runtime, which it doesn't see, so it sees a 0 there, and can mess things up...

To fix this, we need to apply not just the sbrk ptr location (already done), but also its initial value, at compile time. I also think this is necessary regardless of eval-ctors, for standalone mode, where there is no JS.

edit: this happens in cubescript because it has a bunch of global ctors that malloc and write a little data, and nothing else that prevents ctor evalling.

edit: luckily this was easy to debug using wasm-reduce, it turned a 154,012 byte binary into 314 bytes, which I could read and fully understand.

@kripken
Copy link
Member Author

kripken commented Sep 30, 2019

This is actually more serious than I thought. We allow JS to dynamicalliy allocate during startup, so ctor-eval should not make any assumptions about that value. Will disable that optimization (only affects -Oz) and rethink how to enable it properly.

kripken added a commit that referenced this issue Oct 2, 2019
Emscripten side of WebAssembly/binaryen#2366 (that must roll first), this tells
binaryen to set the value in the wasm binary, which fixes standalone wasm
module's sbrk() usage (as normally we set this is JS).

This also disables eval-ctors for the wasm backend, see #9527 , which made an
incorrect assumption about the sbrk initial location - JS may modify it during
startup, so we can't assume it's constant. This affects only -Oz so it's
probably not many users.

After this PR we should be correct in both standalone and non-standalone modes,
and later we can look into re-enabling eval-ctors.
kripken added a commit that referenced this issue Nov 7, 2019
We did not turn it on by default because of #9527, but a risk
remained that a user could manually turn it on, which could
lead to that bug or to WebAssembly/binaryen#2418

This skips running it, and shows a debug note. This seems
better than erroring as that would mean fastcomp projects
must change their build flags for upstream.

Avoids WebAssembly/binaryen#2418
but does not fix it (we'll need to fix that too, to turn it back on
eventually.)
@stale
Copy link

stale bot commented Sep 30, 2020

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.

@stale stale bot added the wontfix label Sep 30, 2020
@sbc100
Copy link
Collaborator

sbc100 commented Sep 30, 2020

Oh this is exciting.. now that we no longer dynamically allocate I think we can re-enable ctor evaluation!

@stale stale bot removed the wontfix label Sep 30, 2020
@kripken
Copy link
Member Author

kripken commented Sep 30, 2020

Hmm yes, it might be easier now, good point...

belraquib pushed a commit to belraquib/emscripten that referenced this issue Dec 23, 2020
Emscripten side of WebAssembly/binaryen#2366 (that must roll first), this tells
binaryen to set the value in the wasm binary, which fixes standalone wasm
module's sbrk() usage (as normally we set this is JS).

This also disables eval-ctors for the wasm backend, see emscripten-core#9527 , which made an
incorrect assumption about the sbrk initial location - JS may modify it during
startup, so we can't assume it's constant. This affects only -Oz so it's
probably not many users.

After this PR we should be correct in both standalone and non-standalone modes,
and later we can look into re-enabling eval-ctors.
belraquib pushed a commit to belraquib/emscripten that referenced this issue Dec 23, 2020
We did not turn it on by default because of emscripten-core#9527, but a risk
remained that a user could manually turn it on, which could
lead to that bug or to WebAssembly/binaryen#2418

This skips running it, and shows a debug note. This seems
better than erroring as that would mean fastcomp projects
must change their build flags for upstream.

Avoids WebAssembly/binaryen#2418
but does not fix it (we'll need to fix that too, to turn it back on
eventually.)
@stale
Copy link

stale bot commented Apr 17, 2022

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.

@stale stale bot added the wontfix label Apr 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants