build: prefer LSE on supported CPUs in official Linux ARM64 releases

Abierto
#67,336 2 comentarios 1 reacción 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
32/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
c, cpp, linux

Línea de trabajo

Start by tracing the official Linux ARM64 release build and link configuration that produces the __aarch64* atomic helpers; the issue does not identify the responsible flag or runtime library. Compare the output with GCC 13.3’s outlined helper, which dispatches on __aarch64_have_lse_atomics. Done means release validation confirms LSE dispatch on capable CPUs and exclusive fallback on CPUs without LSE, while preserving current minimum CPU requirements.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

What is the problem this feature will solve?

Official Linux ARM64 releases contain __aarch64* atomic helpers with only Armv8.0 exclusive load/store loops. They have no LSE fast path or CPU-feature dispatch, so these helpers continue to use exclusives even on LSE-capable CPUs.

Please fix the official Linux ARM64 build/toolchain configuration so that these atomic operations support and prefer LSE when available, with exclusive loops retained for CPUs without LSE. This issue is limited to Linux ARM64. The official Windows and macOS ARM64 binaries provide working examples of LSE code generation, described below.

Verified Linux reproduction

Downloaded from the official nodejs.org release index and verified against each release's published SHASUMS256.txt:

Official artifact Atomic helpers inspected Exclusive instructions in helpers LSE instructions in helpers
node-v26.13.0-linux-arm64.tar.xz 43 86 0
node-v27.0.0-alpha.0.0.0-linux-arm64.tar.xz 43 86 0

Commands, using GNU binutils on Ubuntu 24.04 AArch64:

version=v26.13.0
curl -fLO "https://nodejs.org/dist/$version/node-$version-linux-arm64.tar.xz"
curl -fLO "https://nodejs.org/dist/$version/SHASUMS256.txt"
grep " node-$version-linux-arm64.tar.xz$" SHASUMS256.txt | sha256sum -c -
tar -xf "node-$version-linux-arm64.tar.xz"
binary="node-$version-linux-arm64/bin/node"
nm "$binary" | grep '__aarch64'
objdump -d --disassemble=__aarch64_cas4_acq "$binary"
objdump -d --disassemble=__aarch64_ldadd4_acq_rel "$binary"

In v26.13.0, __aarch64_cas4_acq is:

00000000031922d4 <__aarch64_cas4_acq>:
 31922d4: mov   w16, w0
 31922d8: ldaxr w0, [x2]
 31922dc: cmp   w0, w16
 31922e0: b.ne  31922ec
 31922e4: stxr  w17, w1, [x2]
 31922e8: cbnz  w17, 31922d8
 31922ec: ret

__aarch64_ldadd4_acq_rel similarly contains only an exclusive loop:

00000000031921c0 <__aarch64_ldadd4_acq_rel>:
 31921c0: mov   w16, w0
 31921c4: ldaxr w0, [x1]
 31921c8: add   w17, w0, w16
 31921cc: stlxr w15, w17, [x1]
 31921d0: cbnz  w15, 31921c4
 31921d4: ret

The v27 alpha has the same exclusive-only helper implementations. A scan of executable disassembly found no LSE atomic instructions anywhere in the v26.13.0 binary. The v27 alpha does contain 56 LSE instructions elsewhere in V8 builtins, so the finding for that version is specifically about these atomic helpers, not the absence of LSE from the entire binary. This inspection covers instructions present in the distributed executable, not code generated at runtime by V8 or instructions in dynamically linked libraries.

Evidence from official Windows and macOS ARM64 releases

All artifacts below were downloaded from nodejs.org and checked against their release's published SHA-256 sums. The same stable v26.13.0 and v27.0.0-alpha.0.0.0 releases were inspected on all three platforms.

Platform Observed native atomic code generation
Linux ARM64 All 43 inspected __aarch64* helpers contain exclusive loops and no LSE path in either release.
Windows ARM64 _Interlocked* helpers contain CPU-feature dispatch, an LSE path, and an exclusive fallback in both releases.
macOS ARM64 Native atomic operations use inline LSE directly; no __aarch64_* outlined helper symbols were found.

Windows: runtime dispatch preserves compatibility. In v26.13.0, the official PDB matches the executable's GUID/age and identifies _InterlockedCompareExchange64 at 0x140634c70. The helper checks a feature flag, uses casal when LSE is enabled, and falls back to ldaxr/stlxr otherwise:

; Windows ARM64 v26.13.0: _InterlockedCompareExchange64
adrp  x16, feature_flag_page
ldr   w16, [x16, #0x60]
tbz   w16, #0, fallback
casal x2, x1, [x0]
mov   x0, x2
ret
fallback:
cbz   x16, initialize_feature_detection
retry:
ldaxr x3, [x0]
cmp   x3, x2
b.ne  done
stlxr w16, x1, [x0]
cbnz  w16, retry
done:
mov   x0, x3
ret

This was also checked after installing the official v26.13.0 ARM64 MSI in a UTM Windows 11 Pro ARM64 VM (10.0.26300). The installed C:\Program Files\nodejs\node.exe runs as arm64/win32 and is byte-identical to the inspected official executable (SHA-256 4c9baa047c4ae555050179f25a63153f1c962af32e2aad97735fb550750c5e7a). Reading the running Node process's memory after a crypto workload showed the helper flag at image RVA 0x5310060 was 0x80000001: initialized with LSE enabled. Windows IsProcessorFeaturePresent(34) returned true. The loaded helper at RVA 0x634c70 contained the dispatch code above, which selects its LSE path with that flag value. Individual instructions were not single-stepped. Windows still has exclusive instructions outside these helpers; this comparison specifically establishes working helper dispatch.

macOS: direct inline LSE. For example, v26.13.0's OpenSSL atomic functions contain:

; macOS ARM64 v26.13.0: CRYPTO_atomic_add
ldaddal w1, w8, [x0]
add     w8, w8, w1
str     w8, [x2]
mov     w0, #1
ret

; CRYPTO_atomic_add64 uses ldaddal x1, x8, [x0].
; CRYPTO_atomic_and uses ldclral; CRYPTO_atomic_or uses ldsetal.

These functions have no feature check or exclusive fallback. Static executable disassembly found 6,513 LSE instruction matches in v26.13.0 and 7,385 in the alpha. The lone apparent exclusive instruction in each was a data word inside OpenSSL's _vpsm4_ex_consts constant table, not an exclusive-loop implementation. Both official macOS executables were run successfully on an ARM64 Mac. Their Mach-O metadata declares macOS 13.5 minimum and SDK 15.5; exact compiler command lines were not recovered.

Windows demonstrates that selecting LSE does not require dropping the exclusive fallback. macOS demonstrates that official Node.js native code already uses LSE extensively. Linux has a broader CPU compatibility baseline, so runtime selection is the appropriate comparison rather than copying macOS's unconditional LSE requirement.

What is the feature you are proposing to solve the problem?

Please investigate and fix the official Linux ARM64 compiler/runtime/link configuration to select LSE atomic implementations on capable CPUs and exclusive implementations otherwise.

Ubuntu 24.04's GCC 13.3 default outlined __aarch64_cas4_acq helper already illustrates a Linux-compatible implementation: it checks __aarch64_have_lse_atomics, executes casa when supported, and falls back to an ldaxr/stxr loop otherwise. An Armv8.0 compilation baseline therefore does not by itself require exclusive-only helpers.

The requested result is:

  • LSE-capable Linux ARM64 CPUs select the LSE helper path.
  • CPUs without LSE retain the exclusive fallback and the current minimum CPU requirements.
  • Release-build validation verifies that the distributed helpers contain both paths and that feature dispatch selects the appropriate path.

The disassembly establishes the current behavior, but does not identify the responsible build flag, compiler-runtime library, or link-time choice. No end-to-end performance improvement has been measured; contended-atomic benchmarks would help quantify the benefit. Instruction counts cover the distributed executables, not dynamically linked libraries or V8 code generated at runtime.

What alternatives have you considered?

Users can build Node.js with a compiler/runtime that provides runtime-dispatched outlined atomics. Explicitly compiling for an LSE-capable CPU also enables LSE, but raises the minimum CPU requirements. The official Linux release should provide CPU-aware selection so users do not need custom builds.

Lenguaje dominante
JavaScript
Estrellas
124k
Forks
38k
Merge medio
4 d 2 h
PR fusionados (30 d)
266

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de nodejs/node

Todos los issues de nodejs/node

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.