From 4524aa1f55f73243d4a78a3c2e9b11c730771d41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Fri, 6 Nov 2026 11:41:18 +0100 Subject: [PATCH] build: enable V8 Sparkplug+ with short builtin calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sparkplug+ patches calls in Sparkplug baseline code to typed builtins based on the feedback it observes. V8 compiles it in only when V8_ENABLE_SPARKPLUG_PLUS is defined, which its gn build does on x64, arm64 and loong64. Node's gyp files never defined it, so --sparkplug-plus was a read-only flag fixed to false. V8 only uses Sparkplug+ when short builtin calls are enabled, because it patches pc-relative calls. Enable it on those architectures when short builtin calls are enabled, which Node does by default on x64, and add --v8-disable-sparkplug-plus to opt out. Assisted-by: Claude Code Signed-off-by: Gürgün Dayıoğlu --- configure.py | 18 ++++++++++++++++++ tools/v8_gypfiles/features.gypi | 8 ++++++++ 2 files changed, 26 insertions(+) diff --git a/configure.py b/configure.py index d9d75443e7c6..c27148781d86 100755 --- a/configure.py +++ b/configure.py @@ -56,6 +56,7 @@ valid_intl_modes = ('none', 'small-icu', 'full-icu', 'system-icu') icu_versions = json.loads((tools_path / 'icu' / 'icu_versions.json').read_text(encoding='utf-8')) maglev_enabled_architectures = ('x64', 'arm', 'arm64', 'ppc64', 's390x', 'riscv64') +sparkplug_plus_enabled_architectures = ('x64', 'arm64', 'loong64') # builtins may be removed later if they have been disabled by options shareable_builtins = {'undici/undici': 'deps/undici/undici.js', @@ -1235,6 +1236,17 @@ default=None, help=f"Disable V8's Maglev compiler. {maglev_enabled_by_default_help}") +sparkplug_plus_enabled_by_default_help = ( + f"(Sparkplug+ is enabled on {','.join(sparkplug_plus_enabled_architectures)} " + "when short builtin calls are enabled, which is the default on x64)") + +parser.add_argument('--v8-disable-sparkplug-plus', + action='store_true', + dest='v8_disable_sparkplug_plus', + default=None, + help="Disable V8's Sparkplug+ (dynamic patching of baseline code). " + + sparkplug_plus_enabled_by_default_help) + parser.add_argument('--v8-enable-short-builtin-calls', action='store_true', dest='v8_enable_short_builtin_calls', @@ -2281,6 +2293,12 @@ def configure_v8(o, configs): o['variables']['v8_enable_hugepage'] = 1 if options.v8_enable_hugepage else 0 if options.v8_enable_short_builtin_calls or o['variables']['target_arch'] == 'x64': o['variables']['v8_enable_short_builtin_calls'] = 1 + # Sparkplug+ patches pc-relative builtin calls in baseline code, so V8 only + # uses it when short builtin calls are enabled. + o['variables']['v8_enable_sparkplug_plus'] = B( + not options.v8_disable_sparkplug_plus and + o['variables']['target_arch'] in sparkplug_plus_enabled_architectures and + o['variables'].get('v8_enable_short_builtin_calls') == 1) if options.v8_enable_snapshot_compression: o['variables']['v8_enable_snapshot_compression'] = 1 if all(opt in sys.argv for opt in ['--v8-enable-object-print', '--v8-disable-object-print']): diff --git a/tools/v8_gypfiles/features.gypi b/tools/v8_gypfiles/features.gypi index 305c81eab34d..87bbacebb1c3 100644 --- a/tools/v8_gypfiles/features.gypi +++ b/tools/v8_gypfiles/features.gypi @@ -287,6 +287,11 @@ # Sets -DV8_ENABLE_SPARKPLUG. 'v8_enable_sparkplug%': 1, + # Enable Sparkplug+ (dynamic patching of Sparkplug baseline code). + # Requires v8_enable_sparkplug. + # Sets -DV8_ENABLE_SPARKPLUG_PLUS. + 'v8_enable_sparkplug_plus%': 0, + # Whether custom embedder snapshots may extend (= allocate new objects in) # ReadOnlySpace. 'v8_enable_extensible_ro_snapshot%': 1, @@ -533,6 +538,9 @@ ['v8_enable_sparkplug==1', { 'defines': ['V8_ENABLE_SPARKPLUG',], }], + ['v8_enable_sparkplug==1 and v8_enable_sparkplug_plus==1', { + 'defines': ['V8_ENABLE_SPARKPLUG_PLUS',], + }], ['v8_enable_maglev==1', { 'defines': ['V8_ENABLE_MAGLEV',], }],