diff --git a/emcc.py b/emcc.py index 961eb788be9ae..430ffc7f71a9e 100755 --- a/emcc.py +++ b/emcc.py @@ -3001,6 +3001,8 @@ def do_binaryen(target, asm_target, options, memfile, wasm_binary_target, # (we can't add this value when we placed post-emscripten in the proper position in the list of # passes because that was before the value was computed) options.binaryen_passes += ['--pass-arg=emscripten-sbrk-ptr@%d' % shared.Settings.DYNAMICTOP_PTR] + if shared.Settings.STANDALONE_WASM: + options.binaryen_passes += ['--pass-arg=emscripten-sbrk-val@%d' % shared.Settings.DYNAMIC_BASE] if DEBUG: shared.safe_copy(wasm_binary_target, os.path.join(shared.get_emscripten_temp_dir(), os.path.basename(wasm_binary_target) + '.pre-byn')) cmd = [os.path.join(binaryen_bin, 'wasm-opt'), wasm_binary_target, '-o', wasm_binary_target] + options.binaryen_passes diff --git a/emscripten.py b/emscripten.py index 836bd16eee83b..86b12a36bb385 100644 --- a/emscripten.py +++ b/emscripten.py @@ -798,6 +798,8 @@ def apply_memory(js): logger.debug('global_base: %d stack_base: %d, stack_max: %d, dynamic_base: %d, static bump: %d', memory.global_base, memory.stack_base, memory.stack_max, memory.dynamic_base, memory.static_bump) + shared.Settings.DYNAMIC_BASE = memory.dynamic_base + return js diff --git a/src/runtime_init_memory.js b/src/runtime_init_memory.js index 0289bbae47b75..93682b73d6d79 100644 --- a/src/runtime_init_memory.js +++ b/src/runtime_init_memory.js @@ -77,7 +77,9 @@ updateGlobalBufferAndViews(buffer); #if USE_PTHREADS if (!ENVIRONMENT_IS_PTHREAD) { // Pthreads have already initialized these variables in src/worker.js, where they were passed to the thread worker at startup time #endif +#if !STANDALONE_WASM // in standalone mode the value is in the wasm HEAP32[DYNAMICTOP_PTR>>2] = DYNAMIC_BASE; +#endif // !STANDALONE_WASM #if USE_PTHREADS } #endif diff --git a/src/settings.js b/src/settings.js index 1ec9d034f3289..28706a60119e9 100644 --- a/src/settings.js +++ b/src/settings.js @@ -1642,6 +1642,10 @@ var MAIN_READS_PARAMS = 1; // The computed location of the pointer to the sbrk position. var DYNAMICTOP_PTR = -1; +// The computed initial value of the program break (the sbrk position), which +// is called DYNAMIC_BASE as it is the start of dynamically-allocated memory. +var DYNAMIC_BASE = -1; + // Legacy settings that have been removed or renamed. // For renamed settings the format is: // [OLD_NAME, NEW_NAME] diff --git a/tests/other/metadce/hello_world_Oz.exports b/tests/other/metadce/hello_world_Oz.exports index f2ad6c76f0115..18ebd85217ed7 100644 --- a/tests/other/metadce/hello_world_Oz.exports +++ b/tests/other/metadce/hello_world_Oz.exports @@ -1 +1,2 @@ c +d diff --git a/tests/other/metadce/hello_world_Oz.funcs b/tests/other/metadce/hello_world_Oz.funcs index f10dcee226a53..5817f30a9676e 100644 --- a/tests/other/metadce/hello_world_Oz.funcs +++ b/tests/other/metadce/hello_world_Oz.funcs @@ -4,6 +4,7 @@ $__fwritex $__overflow $__stdio_write $__towrite +$__wasm_call_ctors $fwrite $main $memcpy diff --git a/tests/other/metadce/minimal_Oz.exports b/tests/other/metadce/minimal_Oz.exports index 78981922613b2..422c2b7ab3b3c 100644 --- a/tests/other/metadce/minimal_Oz.exports +++ b/tests/other/metadce/minimal_Oz.exports @@ -1 +1,2 @@ a +b diff --git a/tests/other/metadce/minimal_Oz.funcs b/tests/other/metadce/minimal_Oz.funcs index 66ddb2638a16b..08504a53bdb1b 100644 --- a/tests/other/metadce/minimal_Oz.funcs +++ b/tests/other/metadce/minimal_Oz.funcs @@ -1 +1,2 @@ +$__wasm_call_ctors $add diff --git a/tests/test_other.py b/tests/test_other.py index c95bbf8f75964..f155bf315f054 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -7348,6 +7348,7 @@ def test(p1, p2, p3, last, expected): print(first, second, third) assert first < second and second < third, [first, second, third] + @no_wasm_backend('ctor evaller disabled, see https://github.com/emscripten-core/emscripten/issues/9527') @uses_canonical_tmp @with_env_modify({'EMCC_DEBUG': '1'}) def test_eval_ctors_debug_output(self): @@ -8089,7 +8090,7 @@ def strip_numeric_suffixes(funcname): # in -O3, -Os and -Oz we metadce, and they shrink it down to the minimal output we want 'O3': (['-O3'], 2, [], [], 85, 0, 2, 2), # noqa 'Os': (['-Os'], 2, [], [], 85, 0, 2, 2), # noqa - 'Oz': (['-Oz'], 2, [], [], 54, 0, 1, 1), # noqa + 'Oz': (['-Oz'], 2, [], [], 85, 0, 2, 2), # noqa }) @no_fastcomp() def test_binaryen_metadce_minimal(self, *args): @@ -8130,7 +8131,7 @@ def test_binaryen_metadce_cxx_fastcomp(self, *args): 'O2': (['-O2'], 7, [], ['waka'], 10183, 6, 14, 24), # noqa 'O3': (['-O3'], 4, [], [], 1957, 4, 2, 12), # noqa; in -O3, -Os and -Oz we metadce 'Os': (['-Os'], 4, [], [], 1963, 4, 2, 12), # noqa - 'Oz': (['-Oz'], 4, [], [], 1929, 4, 1, 11), # noqa + 'Oz': (['-Oz'], 4, [], [], 1929, 4, 2, 12), # noqa # finally, check what happens when we export nothing. wasm should be almost empty 'export_nothing': (['-Os', '-s', 'EXPORTED_FUNCTIONS=[]'], diff --git a/tools/shared.py b/tools/shared.py index b18e1e1f7f95f..26e8a8bab1c6d 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -1170,7 +1170,10 @@ def apply_opt_level(cls, opt_level, shrink_level=0, noisy=False): cls.attrs['ASSERTIONS'] = 0 cls.attrs['ALIASING_FUNCTION_POINTERS'] = 1 if shrink_level >= 2: - cls.attrs['EVAL_CTORS'] = 1 + # Ctor evalling in the wasm backend is disabled due to + # https://github.com/emscripten-core/emscripten/issues/9527 + if not Settings.WASM_BACKEND: + cls.attrs['EVAL_CTORS'] = 1 def keys(self): return self.attrs.keys()