Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it might make sense to test the '-mno-bulk-memory' and '-mno-bulk-memory-opt' separately?

IIUC '-mno-bulk-memory' implies '-mno-bulk-memory-opt'?

So self.emcc('hello_world.c', ['-O3', '-o', 'nobulk.js', '-mno-bulk-memory'] should not get bulk memory either?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC '-mno-bulk-memory' implies '-mno-bulk-memory-opt'?

From the LLVM POV, I'm not sure it does sadly.

self.assertFalse(has_data_count('nobulk.wasm'))

@crossplatform
def test_html_preprocess(self):
src_file = test_file('module/test_stdin.c')
Expand Down
22 changes: 14 additions & 8 deletions tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 [<feature_name>, <lowering_flag>] pairs.
# List of [<feature_name>, <lowering_flag>, <feature_flags>] 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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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')
Expand Down