Don't run ATMAINS unless there is _main function exported (#13901)
Fixes: #13791
This commit is contained in:
Родитель
d9a7dbb6d4
Коммит
6e794e6b9f
|
@ -125,6 +125,8 @@ def update_settings_glue(metadata, DEBUG):
|
|||
if shared.Settings.INITIAL_TABLE == -1:
|
||||
shared.Settings.INITIAL_TABLE = metadata['tableSize'] + 1
|
||||
|
||||
shared.Settings.HAS_MAIN = shared.Settings.MAIN_MODULE or shared.Settings.STANDALONE_WASM or '_main' in shared.Settings.IMPLEMENTED_FUNCTIONS
|
||||
|
||||
# When using dynamic linking the main function might be in a side module.
|
||||
# To be safe assume they do take input parametes.
|
||||
shared.Settings.MAIN_READS_PARAMS = metadata['mainReadsParams'] or shared.Settings.MAIN_MODULE
|
||||
|
@ -142,7 +144,8 @@ def update_settings_glue(metadata, DEBUG):
|
|||
|
||||
def apply_static_code_hooks(forwarded_json, code):
|
||||
code = shared.do_replace(code, '<<< ATINITS >>>', str(forwarded_json['ATINITS']))
|
||||
code = shared.do_replace(code, '<<< ATMAINS >>>', str(forwarded_json['ATMAINS']))
|
||||
if shared.Settings.HAS_MAIN:
|
||||
code = shared.do_replace(code, '<<< ATMAINS >>>', str(forwarded_json['ATMAINS']))
|
||||
if shared.Settings.EXIT_RUNTIME:
|
||||
code = shared.do_replace(code, '<<< ATEXITS >>>', str(forwarded_json['ATEXITS']))
|
||||
return code
|
||||
|
|
|
@ -15,14 +15,6 @@ var addedLibraryItems = {};
|
|||
// Each such proxied function is identified via an ordinal number (this is not the same namespace as function pointers in general).
|
||||
var proxiedFunctionTable = ["null" /* Reserve index 0 for an undefined function*/];
|
||||
|
||||
// Used internally. set when there is a main() function.
|
||||
// Also set when in a linkable module, as the main() function might
|
||||
// arrive from a dynamically-linked library, and not necessarily
|
||||
// the current compilation unit.
|
||||
// Also set for STANDALONE_WASM since the _start function is needed to call
|
||||
// static ctors, even if there is no user main.
|
||||
var HAS_MAIN = ('_main' in IMPLEMENTED_FUNCTIONS) || MAIN_MODULE || STANDALONE_WASM;
|
||||
|
||||
// Mangles the given C/JS side function name to assembly level function name (adds an underscore)
|
||||
function mangleCSymbolName(f) {
|
||||
return f[0] == '$' ? f.substr(1) : '_' + f;
|
||||
|
|
|
@ -319,7 +319,9 @@ function run(args) {
|
|||
|
||||
initRuntime();
|
||||
|
||||
#if HAS_MAIN
|
||||
preMain();
|
||||
#endif
|
||||
|
||||
#if MODULARIZE
|
||||
readyPromiseResolve(Module);
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
// === Auto-generated postamble setup entry stuff ===
|
||||
{{{ exportRuntime() }}}
|
||||
|
||||
#if hasExportedFunction('_main') // Only if user is exporting a C main(), we will generate a run() function that can be used to launch main.
|
||||
#if HAS_MAIN // Only if user is exporting a C main(), we will generate a run() function that can be used to launch main.
|
||||
function run() {
|
||||
#if MEMORYPROFILER
|
||||
emscriptenMemoryProfiler.onPreloadComplete();
|
||||
|
|
|
@ -395,6 +395,7 @@ function initRuntime() {
|
|||
callRuntimeCallbacks(__ATINIT__);
|
||||
}
|
||||
|
||||
#if HAS_MAIN
|
||||
function preMain() {
|
||||
#if STACK_OVERFLOW_CHECK
|
||||
checkStackCookie();
|
||||
|
@ -405,6 +406,7 @@ function preMain() {
|
|||
<<< ATMAINS >>>
|
||||
callRuntimeCallbacks(__ATMAIN__);
|
||||
}
|
||||
#endif
|
||||
|
||||
function exitRuntime() {
|
||||
#if STACK_OVERFLOW_CHECK
|
||||
|
|
|
@ -185,3 +185,11 @@ var GENERATE_SOURCE_MAP = 0;
|
|||
var STACK_BASE = 0;
|
||||
var STACK_MAX = 0;
|
||||
var HEAP_BASE = 0;
|
||||
|
||||
// Used internally. set when there is a main() function.
|
||||
// Also set when in a linkable module, as the main() function might
|
||||
// arrive from a dynamically-linked library, and not necessarily
|
||||
// the current compilation unit.
|
||||
// Also set for STANDALONE_WASM since the _start function is needed to call
|
||||
// static ctors, even if there is no user main.
|
||||
var HAS_MAIN = 0;
|
||||
|
|
|
@ -108,7 +108,7 @@ function ready() {
|
|||
#if MODULARIZE && EXPORT_READY_PROMISE
|
||||
readyPromiseResolve(Module);
|
||||
#endif // MODULARIZE
|
||||
#if INVOKE_RUN && hasExportedFunction('_main')
|
||||
#if INVOKE_RUN && HAS_MAIN
|
||||
#if USE_PTHREADS
|
||||
if (!ENVIRONMENT_IS_PTHREAD) {
|
||||
#endif
|
||||
|
|
Загрузка…
Ссылка в новой задаче