diff --git a/test/test_other.py b/test/test_other.py index 380d35af0814e..bdb4ab20b0b21 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -9974,6 +9974,23 @@ def compile(flags): compile(['-sMIN_SAFARI_VERSION=140100', '-mbulk-memory']) verify_features_sec_linked('nontrapping-fptoint', False) + def test_no_bulk_memory(self): + # The test_wasm_features test (above) uses the feature section to confirm + # if a feature is present, but that doesn't work in optimizing builds + # since we strip the feature section in release builds. + # This test confirms that no DATACOUNT section is present in the final + # binary. + + def has_data_count(filename): + with webassembly.Module(filename) as wasm: + return wasm.get_section(webassembly.SecType.DATACOUNT) + + self.emcc('hello_world.c', ['-O3', '-o', 'bulk.js']) + self.assertTrue(has_data_count('bulk.wasm')) + + self.emcc('hello_world.c', ['-O3', '-o', 'nobulk.js', '-mno-bulk-memory', '-mno-bulk-memory-opt']) + self.assertFalse(has_data_count('nobulk.wasm')) + @crossplatform def test_html_preprocess(self): src_file = test_file('module/test_stdin.c') diff --git a/tools/link.py b/tools/link.py index 2242b07b18706..5f2b8b56a20b2 100644 --- a/tools/link.py +++ b/tools/link.py @@ -34,6 +34,7 @@ webassembly, ) from .cmdline import OFormat +from .feature_matrix import Feature from .minimal_runtime_shell import generate_minimal_runtime_html from .settings import ( DEPRECATED_SETTINGS, @@ -367,16 +368,21 @@ def get_binaryen_lowering_passes(): # This can happen if the feature is explicitly disabled on the command line, # or when targeting an VM/engine that does not support the feature. - # List of [, ] pairs. + # List of [, , ] triples. features = [ - [feature_matrix.Feature.SIGN_EXT, '--signext-lowering'], - [feature_matrix.Feature.NON_TRAPPING_FPTOINT, '--llvm-nontrapping-fptoint-lowering'], - [feature_matrix.Feature.BULK_MEMORY, '--llvm-memory-copy-fill-lowering'], + [Feature.SIGN_EXT, '--signext-lowering', ['--enable-sign-ext']], + [Feature.NON_TRAPPING_FPTOINT, '--llvm-nontrapping-fptoint-lowering', ['--enable-nontrapping-float-to-int']], + [Feature.BULK_MEMORY, '--llvm-memory-copy-fill-lowering', ['--enable-bulk-memory', '--enable-bulk-memory-opt']], ] - for feature, lowering_flag in features: + for feature, lowering_flag, feature_flags in features: if not feature_matrix.caniuse(feature): logger.debug(f'lowering {feature.name} feature due to incompatible target browser engines') + for f in feature_flags: + # Remove features from binaryen_features, otherwise future runs of binaryen + # could re-introduce the feature. + if f in building.binaryen_features: + building.binaryen_features.remove(f) passes.append(lowering_flag) return passes @@ -1044,7 +1050,7 @@ def limit_incoming_module_api(): if user_settings.get('WASM_BIGINT') and settings.WASM_BIGINT: exit_with_error('WASM_BIGINT=1 is not compatible with wasm2js') settings.WASM_BIGINT = 0 - feature_matrix.disable_feature(feature_matrix.Feature.JS_BIGINT_INTEGRATION) + feature_matrix.disable_feature(Feature.JS_BIGINT_INTEGRATION) if options.oformat == OFormat.WASM and not settings.SIDE_MODULE: # if the output is just a wasm file, it will normally be a standalone one, @@ -1583,8 +1589,8 @@ def limit_incoming_module_api(): # TODO(sbc): Find make a generic way to expose the feature matrix to JS # compiler rather then adding them all ad-hoc as internal settings - settings.SUPPORTS_PROMISE_ANY = feature_matrix.caniuse(feature_matrix.Feature.PROMISE_ANY) - default_setting('WASM_BIGINT', feature_matrix.caniuse(feature_matrix.Feature.JS_BIGINT_INTEGRATION)) + settings.SUPPORTS_PROMISE_ANY = feature_matrix.caniuse(Feature.PROMISE_ANY) + default_setting('WASM_BIGINT', feature_matrix.caniuse(Feature.JS_BIGINT_INTEGRATION)) if settings.AUDIO_WORKLET: add_system_js_lib('libwebaudio.js')