-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Emscripten calls null GOT entry when side module loaded with allowUndefined: true
#22052
Comments
After many hours of debugging, I minimized the problem down to this: emscripten-core/emscripten#22052 Thanks to @henryiii for reporting. See thread here for my comments while I was debugging: scikit-hep/boost-histogram#938
I think this patch to --- a/src/library_dylink.js
+++ b/src/library_dylink.js
@@ -176,6 +176,16 @@ var LibraryDylink = {
// correctly.
rtn.required = true;
}
+ var value = resolveGlobalSymbol(symName, true).sym;
+ if (!value) {
+ return rtn;
+ }
+ if (typeof value == 'function') {
+ /** @suppress {checkTypes} */
+ rtn.value = addFunction(value, value.sig);
+ } else if (typeof value == 'number') {
+ rtn.value = value;
+ }
return rtn;
}
}, |
…fined: true` Resolves emscripten-core#22052
…fined: true` Resolves emscripten-core#22052
We should probably add a test for this? I wonder if there is some way to build a test that doesn't depend on using EM_JS? Do you know exactly which types of symbols are effected by this? Is |
+1 I'll add a test to #22053.
I am not sure. Many symbols don't seem to have this problem. I will investigate further and get back to you. |
Nevermind, |
After many hours of debugging, I minimized the problem down to this: emscripten-core/emscripten#22052 Thanks to @henryiii for reporting. See thread here for my comments while I was debugging: scikit-hep/boost-histogram#938 Resolves #2964.
After many hours of debugging, I minimized the problem down to this: emscripten-core/emscripten#22052 Thanks to @henryiii for reporting. See thread here for my comments while I was debugging: scikit-hep/boost-histogram#938 Resolves pyodide#2964.
I think the first bad commit is emscripten-releases e4ea05676d38c899d486aeb1553af4a0b5432317
|
No wait that one is e4ea05676d38c899d486aeb1553af4a0b5432317 good first bad is the next commit 9063e25ecf39470a96689f3896ca5d4462928eb6:
which is:
|
It seems like the issue was likely always there but somehow the C++ std library changes the set of undefined symbols present in the shared libraries. This does sounds like something really should be fixed. On the other hand, only uses who load code directly through the |
We'd like to transition to cc @ryanking13 who might have a better idea than I do about this. |
Do you know about that async version of dlopen? We have |
No I was not aware of those. We're trying to call into this from JavaScript not from C so there would be some extra code in order to use these C apis, but if they work better that could be a reason to switch. I think there are some other subtle differences between the shared library dependency search paths in native dlopen vs emscripten's dlopen that we're currently working around. Perhaps if we can figure out a few more bugfixes we can switch. It would be nice to see |
This would be worth taking a look at, thanks. Another reason we use the JS function directly is to locate shared libraries. I opened a separate issue about it #22126. |
That is very unlikely to happen sadly, since |
I made this library to deal with adapting between I think it's beneficial to split up the steps of
A lot of the time people just use return values immediately and don't need to store them, so in all of those cases this saves work. The JavaScript functions don't need to do extra steps to lookup the handle value; if the handle lookup needs to happen it occurs in C. And then we don't need special case This is a bit of a sidetrack though =) |
Sure that sounds like a good way of layering it. I would still probably want a simple variant all such function that just return a handle though, and perhaps a lower/level alternative one that returns the raw externref (which, as I say, I imagine very few folks would want in practice). IIRC, we have looked, for example, and moving the handle allocator to native code, but IIRC is was strictly worse since the JS side is extremely good and doing fast hashmaps and doing that in C has some overhead. I guess there are somethings that JS really is better at. |
Of course different applications are different, but in Pyodide there are only 8 places we explicitly create a handle now, whereas there were 87 places before we switched to externref, so we only need to make a handle under 10% of the time. This made a pretty large difference in performance for us. FWIW, I think when I changed the implementation from JavaScript to C I didn't see any change in performance. We don't implement a hash map in C, we just have the table and an array of metadata. You could also do it with a free list. |
The following code example looks up
GOT.__cxa_throw
which is0
and then calls it which throwsTypeError: getWasmTableEntry(...) is not a function
. CallingreportUndefinedSymbols
or removingallowUndefined: true
resolves the crash.module.cpp
main.c
build.sh
Then run with
node main.js
.Version of emscripten/emsdk:
Checked on 3.1.52, 3.1.58 and tip of tree:
The text was updated successfully, but these errors were encountered: