Skip to content

Emscripten build fails when WebAssembly reference types are disabled #161782

Description

@garbear

Bug report

CPython's Emscripten syscall overrides fail to compile when WebAssembly reference types are disabled with -mno-reference-types.

Python/emscripten_syscalls.c unconditionally uses __externref_t and reference-type builtins in its optional JavaScript Promise Integration (JSPI) read and poll wrappers. These types are unavailable when reference types are disabled, even if JSPI is never used.

Steps to reproduce

  1. Build CPython for wasm32-emscripten using Emscripten 7.0.0.
  2. Compile with -mno-reference-types.
  3. Build Python/emscripten_syscalls.c.

Actual result

Compilation fails with errors involving __externref_t (nine errors in the tested configuration).

Modules containing externref also cannot instantiate in older browsers such as Chromium 85.

Expected result

CPython should compile without WebAssembly reference types, retaining synchronous read and poll syscall implementations when JSPI is unavailable.

Suggested fix

Conditionally compile the reference-type-dependent JSPI wrappers using __wasm_reference_types__, and provide a no-op interpreter startup hook when reference types are disabled.

Validation

Tested against CPython main (226813c0f7834b55be51e912a3d8555e652d9026) using Emscripten 7.0.0 and Node.js 26.

With the proposed fix:

  • Both reference-type configurations compile successfully.
  • Eight focused runtime tests pass, covering startup, synchronous syscall fallbacks, JSPI read/poll, and error handling.
  • The disabled configuration contains no externref instructions.
  • The enabled object is byte-for-byte identical to the original implementation.

A full CPython build and test suite were not run.

Originally discovered while bringing up Kodi on a Samsung Q60B running Chromium 85.

Related downstream fix: xbmc/xbmc#30431

AI disclosure: GPT-6 Astra, Extra high

CPython versions tested on:

CPython main branch, 3.14

Operating systems tested on:

macOS

Linked PRs

Activity

  1. added 2 commits that reference this issue on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions