-
Notifications
You must be signed in to change notification settings - Fork 3.4k
jsifier: Make JS libraries aliases work even when native export exists #19046
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
5bf875a
to
07f4985
Compare
6d7c15d
to
282bb0a
Compare
8ae41e7
to
ceb804f
Compare
28fbf6b
to
76fe398
Compare
An alternative to this PR would be to revert #19033, but I think I like this solution better. |
Followup to #19033. Updating the `test_closure_full_js_library` to include webgl2 caused a lot of `JSC_REFERENCE_BEFORE_DECLARE` closure errors. This is because we had JS aliases who's target was defined both in JS and in native code. In this case the jsifier was choosing not to include the JS version, which in the case of the GL symbols not what we want. This is why, prior to #19033, we were duplicating the library entries. This this change JS symbol aliases now force the alias target to be included from the JS library, even in the case that the native code also emits its own version of a symbol. This happens in the case of pthreads + MAIN_MODULE + OFFSCREEN_FRAMEBUFFER. In this mode webgl2.c defines (and also exports) the entire set of GL library symbols. In this case we still want the `emscripten_XX` aliases to point to the original JS versions, no the natively exported version. Sadly it looks like we have at testing gab for that particular combination.
Can you explain why that isn't what we want? (If a symbol is defined in both JS and C I'd expect us to always want the C version?) |
IIRC, in the case of GL we have wrappers in that look like this:
On the JS side we have:
Normally this is not a problem since the native C/C++ wrapper called glGetString is not even exported, but in the case of In this particular case we want the JS alias to point to the JS function, and not the native one. I'm not sure if that we always what we want but it also doesn't seem unreasonable. |
This all sounds good to me, though didn't check the code in detail. Btw, I am wondering if we should rename |
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 see, thanks. lgtm.
Separately from this, it might be worth thinking about simplifying that. One idea might be to reverse the aliasing, that is, make js_glFoo
contain the actual JS code, and add an alias from glFoo
to js_glFoo
. Then native code would implement glFoo
and call out to js_glFoo
and no alias would be needed in that case, which seem simpler. But possibly I'm forgetting some issue...
Agreed, I think these are possible simplifications we can do here. I'll add a comment here and we can look into followups. |
This test was updated in #19046, but went through CI before #19067 landed which made duplicate signatures into a warning. `glDrawRangeElements` is defined both in `library_glemu.js` and in `library_webgl2.js` with the former taking precedence because it is included later. This change avoid the duplicate definition.
This test was updated in #19046, but went through CI before #19067 landed which made duplicate signatures into a warning. `glDrawRangeElements` is defined both in `library_glemu.js` and in `library_webgl2.js` with the former taking precedence because it is included later. This change avoid the duplicate definition.
Followup to #19033.
Updating the
test_closure_full_js_library
to include webgl2 caused a lot ofJSC_REFERENCE_BEFORE_DECLARE
closure errors.This is because we had JS aliases who's target was defined both in JS and in native code. In this case the jsifier was choosing not to include the JS version, which in the case of the GL symbols not what we want. I imagine this is why, prior to #19033, we were duplicating the library entries.
This this change JS symbol aliases now force the alias target to be included from the JS library, even in the case that the native code also emits its own version of a symbol.
This happens in the case of pthreads + MAIN_MODULE + OFFSCREEN_FRAMEBUFFER. In this mode webgl2.c defines (and also exports) the entire set of GL library symbols. In this case we still want the
emscripten_XX
aliases to point to the original JS versions, not the exported native version.Sadly it looks like we have at testing gap for that particular combination.