Skip to content

Commit

Permalink
Remove EMIT_EMSCRIPTEN_METADATA settings
Browse files Browse the repository at this point in the history
We have been warning about the deprecation of this setting
for about a year now (since 2.0.9).

As explained in #12231, the major use cases for this metadata
are no longer valid since the embedder should on longer need to
know the memory layout of the module (since the memory and table
are both created and setup within the wasm module these days).

Fixes: #12231
  • Loading branch information
sbc100 committed Oct 18, 2021
1 parent fba2b8f commit 9fe5470
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 94 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ See docs/process.md for more on how version tagging works.
- Support a new CMake propert `EMSCRIPTEN_SYSTEM_PROCESSOR` which can be used
to override the default value of `CMAKE_SYSTEM_PROCESSOR` set by the
toolchain file.
- Remove support for the `EMIT_EMSCRIPTEN_METADATA` setting. This setting has
been deprecated for some time now and we don't know of any remained reasons to
keep it around.

2.0.31 - 10/01/2021
-------------------
Expand Down
4 changes: 0 additions & 4 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3175,10 +3175,6 @@ def phase_binaryen(target, options, wasm_target):

# after generating the wasm, do some final operations

if settings.EMIT_EMSCRIPTEN_METADATA:
diagnostics.warning('deprecated', 'We hope to remove support for EMIT_EMSCRIPTEN_METADATA. See https://github.com/emscripten-core/emscripten/issues/12231')
webassembly.add_emscripten_metadata(wasm_target)

if final_js:
if settings.SUPPORT_BIG_ENDIAN:
final_js = building.little_endian_heap(final_js)
Expand Down
7 changes: 1 addition & 6 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1321,12 +1321,6 @@ var WASM_BIGINT = 0;
// [link]
var EMIT_PRODUCERS_SECTION = 0;

// If set then generated WASM files will contain a custom
// "emscripten_metadata" section that contains information necessary
// to execute the file without the accompanying JS file.
// [link]
var EMIT_EMSCRIPTEN_METADATA = 0;

// Emits emscripten license info in the JS output.
// [link]
var EMIT_EMSCRIPTEN_LICENSE = 0;
Expand Down Expand Up @@ -2048,4 +2042,5 @@ var LEGACY_SETTINGS = [
['WORKAROUND_IOS_9_RIGHT_SHIFT_BUG', [0], 'Wasm2JS does not support iPhone 4s, iPad 2, iPad 3, iPad Mini 1, Pod Touch 5 (devices with end-of-life at iOS 9.3.5) and older'],
['RUNTIME_FUNCS_TO_IMPORT', [[]], 'No longer needed'],
['LIBRARY_DEPS_TO_AUTOEXPORT', [[]], 'No longer needed'],
['EMIT_EMSCRIPTEN_METADATA', [0], 'No longer supported'],
];
17 changes: 0 additions & 17 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -8800,23 +8800,6 @@ def test_no_excessive_invoke_functions_are_generated_when_exceptions_are_enabled
self.assertNotContained('invoke_ii', output)
self.assertNotContained('invoke_v', output)

def test_emscripten_metadata(self):
self.run_process([EMCC, test_file('hello_world.c')])
self.assertNotIn(b'emscripten_metadata', read_binary('a.out.wasm'))

self.run_process([EMCC, test_file('hello_world.c'),
'-s', 'EMIT_EMSCRIPTEN_METADATA'])
self.assertIn(b'emscripten_metadata', read_binary('a.out.wasm'))

# Test is standalone mode too.
self.run_process([EMCC, test_file('hello_world.c'), '-o', 'out.wasm',
'-s', 'EMIT_EMSCRIPTEN_METADATA'])
self.assertIn(b'emscripten_metadata', read_binary('out.wasm'))

# make sure wasm executes correctly
ret = self.run_process(config.NODE_JS + ['a.out.js'], stdout=PIPE).stdout
self.assertContained('hello, world!\n', ret)

@parameterized({
'O0': (False, ['-O0']), # noqa
'O0_emit': (True, ['-O0', '-s', 'EMIT_EMSCRIPTEN_LICENSE']), # noqa
Expand Down
67 changes: 0 additions & 67 deletions tools/webassembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,13 @@
import sys

from . import utils
from .settings import settings

sys.path.append(utils.path_from_root('third_party'))

import leb128

logger = logging.getLogger('webassembly')


# For the Emscripten-specific WASM metadata section, follows semver, changes
# whenever metadata section changes structure.
# NB: major version 0 implies no compatibility
# NB: when changing the metadata format, we should only append new fields, not
# reorder, modify, or remove existing ones.
EMSCRIPTEN_METADATA_MAJOR, EMSCRIPTEN_METADATA_MINOR = (0, 3)
# For the JS/WASM ABI, specifies the minimum ABI version required of
# the WASM runtime implementation by the generated WASM binary. It follows
# semver and changes whenever C types change size/signedness or
# syscalls change signature. By semver, the maximum ABI version is
# implied to be less than (EMSCRIPTEN_ABI_MAJOR + 1, 0). On an ABI
# change, increment EMSCRIPTEN_ABI_MINOR if EMSCRIPTEN_ABI_MAJOR == 0
# or the ABI change is backwards compatible, otherwise increment
# EMSCRIPTEN_ABI_MAJOR and set EMSCRIPTEN_ABI_MINOR = 0.
EMSCRIPTEN_ABI_MAJOR, EMSCRIPTEN_ABI_MINOR = (0, 29)

WASM_PAGE_SIZE = 65536

MAGIC = b'\0asm'
Expand All @@ -61,55 +43,6 @@ def readSLEB(iobuf):
return leb128.i.decode_reader(iobuf)[0]


def add_emscripten_metadata(wasm_file):
mem_size = settings.INITIAL_MEMORY // WASM_PAGE_SIZE
global_base = settings.GLOBAL_BASE

logger.debug('creating wasm emscripten metadata section with mem size %d' % mem_size)
name = b'\x13emscripten_metadata' # section name, including prefixed size
contents = (
# metadata section version
toLEB(EMSCRIPTEN_METADATA_MAJOR) +
toLEB(EMSCRIPTEN_METADATA_MINOR) +

# NB: The structure of the following should only be changed
# if EMSCRIPTEN_METADATA_MAJOR is incremented
# Minimum ABI version
toLEB(EMSCRIPTEN_ABI_MAJOR) +
toLEB(EMSCRIPTEN_ABI_MINOR) +

# Wasm backend, always 1 now
toLEB(1) +

toLEB(mem_size) +
toLEB(0) +
toLEB(global_base) +
toLEB(0) +
# dynamictopPtr, always 0 now
toLEB(0) +

# tempDoublePtr, always 0 in wasm backend
toLEB(0) +

toLEB(int(settings.STANDALONE_WASM))

# NB: more data can be appended here as long as you increase
# the EMSCRIPTEN_METADATA_MINOR
)

orig = utils.read_binary(wasm_file)
with open(wasm_file, 'wb') as f:
f.write(orig[0:8]) # copy magic number and version
# write the special section
f.write(b'\0') # user section is code 0
# need to find the size of this section
size = len(name) + len(contents)
f.write(toLEB(size))
f.write(name)
f.write(contents)
f.write(orig[8:])


class SecType(IntEnum):
CUSTOM = 0
TYPE = 1
Expand Down

0 comments on commit 9fe5470

Please sign in to comment.