diff --git a/test/test_other.py b/test/test_other.py index acc284d42c1b..81ec355aedf1 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -63,12 +63,12 @@ def uses_canonical_tmp(func): test to satisfy the leak detector. """ @wraps(func) - def decorated(self): + def decorated(self, *args, **kwargs): # Before running the test completely remove the canonical_tmp if os.path.exists(self.canonical_temp_dir): shutil.rmtree(self.canonical_temp_dir) try: - func(self) + func(self, *args, **kwargs) finally: # Make sure the test isn't lying about the fact that it uses # canonical_tmp @@ -1206,6 +1206,25 @@ def test_wl_stackfirst(self): err = self.expect_fail(cmd + ['-sGLOBAL_BASE=1024']) self.assertContained('error: --stack-first is not compatible with -sGLOBAL_BASE', err) + @parameterized({ + # In a simple -O0 build we do not set --low-memory-unused (as the stack is + # first, which is nice for debugging but bad for code size (larger globals) + # and bad for the low-memory-unused trick. + '': ([], False), + # When we optimize, we do. + 'O2': (['-O2'], True), + # But a low global base prevents it. + 'O2_GB_512': (['-O2', '-sGLOBAL_BASE=512'], False), + # A large-enough global base allows it. + 'O2_GB_1024': (['-O2', '-sGLOBAL_BASE=1024'], True), + # Forcing the stack to be first in the linker prevents it. + 'linker_flag': (['-O2', '-Wl,--stack-first'], False), + }) + def test_binaryen_low_memory_unused(self, args, low_memory_unused): + cmd = [EMCC, test_file('hello_world.c'), '-v'] + args + err = self.run_process(cmd, stdout=PIPE, stderr=PIPE).stderr + self.assertContainedIf('--low-memory-unused ', err, low_memory_unused) + def test_l_link(self): # Linking with -lLIBNAME and -L/DIRNAME should work, also should work with spaces create_file('main.c', ''' diff --git a/tools/link.py b/tools/link.py index 48b517ecfecb..24bad45f443c 100644 --- a/tools/link.py +++ b/tools/link.py @@ -357,8 +357,9 @@ def get_binaryen_passes(memfile): if optimizing: passes += [building.opt_level_to_str(settings.OPT_LEVEL, settings.SHRINK_LEVEL)] # when optimizing, use the fact that low memory is never used (1024 is a - # hardcoded value in the binaryen pass) - if optimizing and settings.GLOBAL_BASE >= 1024: + # hardcoded value in the binaryen pass). we also cannot do it when the stack + # is first, as then the stack is in the low memory that should be unused. + if optimizing and settings.GLOBAL_BASE >= 1024 and not settings.STACK_FIRST: passes += ['--low-memory-unused'] if settings.AUTODEBUG: # adding '--flatten' here may make these even more effective