@@ -143,10 +143,12 @@ ${argConvertions}
143
143
} ) ;
144
144
}
145
145
146
- function processLibraryFunction ( snippet , ident , finalName ) {
147
- // It is possible that when printing the function as a string on Windows, the js interpreter we are in returns the string with Windows
148
- // line endings \r\n. This is undesirable, since line endings are managed in the form \n in the output for binary file writes, so
149
- // make sure the endings are uniform.
146
+ function processLibraryFunction ( snippet , ident , finalName , deps ) {
147
+ // It is possible that when printing the function as a string on Windows,
148
+ // the js interpreter we are in returns the string with Windows line endings
149
+ // \r\n. This is undesirable, since line endings are managed in the form \n
150
+ // in the output for binary file writes, so make sure the endings are
151
+ // uniform.
150
152
snippet = snippet . toString ( ) . replace ( / \r \n / gm, '\n' ) ;
151
153
152
154
// name the function; overwrite if it's already named
@@ -163,20 +165,37 @@ function ${name}(${args}) {
163
165
return ret;
164
166
}` ) ;
165
167
}
168
+
166
169
if ( MEMORY64 ) {
167
170
const sig = LibraryManager . library [ ident + '__sig' ] ;
168
171
if ( sig && sig . includes ( 'p' ) ) {
169
172
snippet = convertPointerParams ( snippet , sig ) ;
170
173
}
171
174
}
175
+
172
176
return snippet ;
173
177
}
174
178
179
+ function addImplicitDeps ( snippet , deps ) {
180
+ // There are some very common dependencies that we inject automatically
181
+ // by conservatively scanning the input functions for their usage.
182
+ // Specifically, these are dependencies that are automatically generated by
183
+ // the {{{ makeDynCall }}} macro which is very common.
184
+ const autoDeps = [ 'getDynCaller' , 'getWasmTableEntry' ] ;
185
+ for ( const dep of autoDeps ) {
186
+ if ( snippet . includes ( dep + '(' ) ) {
187
+ deps . push ( '$' + dep ) ;
188
+ }
189
+ }
190
+ }
191
+
175
192
// functionStub
176
193
function functionStubHandler ( item ) {
177
- // In LLVM, exceptions generate a set of functions of form __cxa_find_matching_catch_1(), __cxa_find_matching_catch_2(), etc.
178
- // where the number specifies the number of arguments. In Emscripten, route all these to a single function '__cxa_find_matching_catch'
179
- // that variadically processes all of these functions using JS 'arguments' object.
194
+ // In LLVM, exceptions generate a set of functions of form
195
+ // __cxa_find_matching_catch_1(), __cxa_find_matching_catch_2(), etc. where
196
+ // the number specifies the number of arguments. In Emscripten, route all
197
+ // these to a single function '__cxa_find_matching_catch' that variadically
198
+ // processes all of these functions using JS 'arguments' object.
180
199
if ( item . identMangled . startsWith ( '___cxa_find_matching_catch_' ) ) {
181
200
if ( DISABLE_EXCEPTION_THROWING ) {
182
201
error ( 'DISABLE_EXCEPTION_THROWING was set (likely due to -fno-exceptions), which means no C++ exception throwing support code is linked in, but exception catching code appears. Either do not set DISABLE_EXCEPTION_THROWING (if you do want exception throwing) or compile all source files with -fno-except (so that no exceptions support code is required); also make sure DISABLE_EXCEPTION_CATCHING is set to the right value - if you want exceptions, it should be off, and vice versa.' ) ;
@@ -301,9 +320,11 @@ function ${name}(${args}) {
301
320
}
302
321
} else if ( typeof snippet == 'object' ) {
303
322
snippet = stringifyWithFunctions ( snippet ) ;
323
+ addImplicitDeps ( snippet , deps ) ;
304
324
} else if ( typeof snippet == 'function' ) {
305
325
isFunction = true ;
306
- snippet = processLibraryFunction ( snippet , ident , finalName ) ;
326
+ snippet = processLibraryFunction ( snippet , ident , finalName , deps ) ;
327
+ addImplicitDeps ( snippet , deps ) ;
307
328
libraryFunctions . push ( finalName ) ;
308
329
}
309
330
0 commit comments