-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Basic dynamic loading support #32
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
no difference unless the module is wrapped in a closure.
clicks "Cancel" in the prompt dialog.
Very nice! I'll have time to look at this a little later, but one idea I had meanwhile: I think you can work around the library problem by just including the entire library in the parent. That is, include all the library in the main file, and none of it in the shared libraries. This is obviously inefficient since you include lots of functions that aren't needed. However the entire size of the whole library.js is really not that big. So solving this properly can be left for later, meanwhile this is a trivial workaround, and it will keep library calls fast. |
I think combining the two would be one way to go. This way the libraries are a little more portable, since they can define any functions that they need but can't find, but can still be fast if the parent includes the whole library. To keep it flexible, I can add a setting so one can manually configure how to include the library:
Of course that means an extra burden on the user to configure it correctly, but emscripten doesn't strike me as a project aimed at beginners, at least in its current state. |
I am less concerned about user complexity, more about code complexity. More options is more complicated to get right. But if you already have it working or think it isn't hard, that's cool. Ok, I read the code, focusing on integration with emscripten. I didn't take a very careful look inside the dlopen() implementation yet. Looks great, but some minor comments:
And one more substantial one:
One way is to generate not absolute offsets but some identifier, like {{{FUNCTION_INDEX:5}}} etc in shared libs. Then you replace all of those (for 5) with the same absolute value (calculated from the known FUNCTION_TABLE at runtime) and likewise for the rest. There are probably better ways though, this is just off the top of my head. |
Yeah, will do. I'm used to CoffeeScript, which converts it automatically.
Otherwise it would raise a ReferenceError. Alternatively, we could do
My bad. If we're using globals in the parent anyway, we can explicitly define globals in the lib using
Will do.
Will do. I still need to look into the case where both the parent and the lib define
Oh, I thought I did. Will fix. |
Child no longer includes library, using the parent's instead.
* Fixed loose "in" check for library functions in jsifier.js. * Made __globalConstructor__ a var in preamble_sharedlib.js.
['memset', 'malloc', 'free'].forEach(function(ident) { | ||
if (INCLUDE_FULL_LIBRARY) { | ||
assert(!BUILD_AS_SHARED_LIB, 'Cannot have both INCLUDE_FULL_LIBRARY and BUILD_AS_SHARED_LIB set.') | ||
var libFuncsToInclude = Object.keys(Library); |
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.
Please use keys(), which we define ourselves. Object.keys is not present in older engines.
Great stuff! :) Ok, this is ready to be merged, pending on (1) the few minor comments I just added as notes, and (2) that enough automatic tests pass. |
Add support for Emscripten 3.1.1
I've added a basic implementation of dlfcn.h and a compilation mode for dynamically loaded libraries. I doubt this is going to cut it for serious applications, but it works for the few trivial cases I've tried.
Notes:
dlopen()
call with theRTLD_GLOBAL
flag export identifiers to the actual global scope instead of the parent's Module? Should it do that for library functions?Also included is support for exporting non-function globals.
I'll add a test case or two, hopefully tomorrow. In the meantime if you could take a look and tell me if anything looks amiss, I'd appreciate it.