-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Enable EXPORT_ALL in main modules with the wasm backend #10079
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
I'm confused though because you explicitly disabled EXPORT_ALL for MAIN_MODULE in #7371 |
Oh good point, I forgot that... well, I guess we need a very different approach here then... |
This is all very confusing. I would have thought that EXPORT_ALL should be enabled by default with MAIN_MODULE=1 and disabled with MAIN_MODULE=2. Does that make sense? So I think that #7371 maybe should have only effected the =1 case, and not the =2 case? |
Yeah, the behavior of The Module object is used to interface between main and side modules, is perhaps the tricky thing here. So exporting onto Module, which is what |
I agree that approach. I'm still a little confused about the downside of It sounds like t here are two differnt levels of export here and that EXPORT_ALL is controlling both of them? |
emcc.py
Outdated
# the EXPORT_ALL flag, which provides those methods on Module, which is | ||
# used to look up imports as necessary. | ||
if shared.Settings.WASM_BACKEND: | ||
shared.Settings.EXPORT_ALL = 1 |
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.
I think we need to do this both for SIDE_MODULE=1 and MAIN_MODULE=1, down below on ling 1170 would make sense to me.
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.
This still needs doing I think.
emcc.py
Outdated
elif shared.Settings.SIDE_MODULE: | ||
assert not shared.Settings.MAIN_MODULE | ||
options.memory_init_file = False # memory init file is not supported with asm.js side modules, must be executable synchronously (for dlopen) | ||
if not shared.Settings.WASM_BACKEND: | ||
shared.Settings.EXPORT_ALL = 1 |
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.
I think you can just do this once down on line 1166, no? Right below where we set LINKABLE = 1
?
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.
Still needs doing.
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.
Thanks, done.
Oh, I was wrong in part of the analysis before. I saw that fastcomp adds all the JS library methods to But, as agreed earlier, let's only do it in Also stop doing EXPORT_ALL in the test runner: do it in emcc.py when needed |
src/support.js
Outdated
#if ASSERTIONS | ||
// this resolved symbol must exist, as we are about to try to | ||
// add it to the table; error clearly here instead of there. | ||
assert(f, 'could not resolve: ' + name); |
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.
resolveSymbol already includes an assert which more detail than this.
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.
Thanks, I forgot to build with assertions when I tested this I think...
emcc.py
Outdated
elif shared.Settings.SIDE_MODULE: | ||
assert not shared.Settings.MAIN_MODULE | ||
options.memory_init_file = False # memory init file is not supported with asm.js side modules, must be executable synchronously (for dlopen) | ||
if not shared.Settings.WASM_BACKEND: | ||
shared.Settings.EXPORT_ALL = 1 |
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.
Still needs doing.
shared.Settings.LINKABLE = 1 | ||
shared.Settings.EXPORT_ALL = 1 |
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.
If WASM_BACKEND?
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.
I think there is no harm to do it in fastcomp too, and it makes the two paths more similar. Also, I'm not sure that there isn't a fastcomp bug that isn't fixed by this, but I didn't investigate. But maybe I'm forgetting something?
) In mode 1 we should provide the entire JS library to other modules, if they want to import something from there. This was always needed, but the test suite did it manually. With this PR we can remove it from the test suite as we do it automatically, which is safer for users. Note that there is no change to mode 2, in which we do DCE as normal and the user must specify what to export to other modules. In that case the user must export JS library methods as required.
Fastcomp adds all the JS library to the asmLibraryArg object which is
provided as "env" to wasm modules, which lets them access those methods.
In the wasm backend we use a more straightforward method of flipping
the
EXPORT_ALL
flag, which provides those methods on Module, which isused to look up imports as necessary.
EXPORT_ALL
is also noticed by metadce (when present, it doesn't try toremove wasm exports) so this likely fixes another bug as well, see the
metadce output changes (the additions were metadce'd out before,
possibly incorrectly if a side module needs them).
Fixes #9793