Skip to content

build: re-enable ThinLTO on macOS#51819

Merged
MarshallOfSound merged 4 commits into
43-x-yfrom
trop/43-x-y-bp-build-re-enable-thinlto-on-macos-1780323710572
Jun 1, 2026
Merged

build: re-enable ThinLTO on macOS#51819
MarshallOfSound merged 4 commits into
43-x-yfrom
trop/43-x-y-bp-build-re-enable-thinlto-on-macos-1780323710572

Conversation

@trop

@trop trop Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Backport of #51669

See that PR for details.

Notes: Enabled ThinLTO on macOS builds.

trop Bot and others added 2 commits June 1, 2026 14:21
Re-enable ThinLTO on macOS. Add a patch to the bundled Node.js source
that anchors weak vtables and N-API entry points so they survive
clang's -fwhole-program-vtables under ThinLTO. See the patch's commit
message for details.

Co-authored-by: Charles Kerr <charles@charleskerr.com>
The previous approach (out-of-line member definitions plus explicit
template instantiations) still produces weak_odr vtables, which Mach-O
ThinLTO localizes during code generation even when other LTO partitions
reference them. This breaks the link of executables that link libnode
(electron_natives_codecache, node_mksnapshot) with undefined vtable
symbol errors.

Replace that part of the node patch with explicit specializations of
the affected instantiations:

  - StaticExternalByteResource<uint8_t, char, ExternalOneByteStringResource>
  - StaticExternalByteResource<uint16_t, uint16_t, ExternalStringResource>
  - NgRcBufPointer<Http2RcBufferPointerTraits>::External

An explicit specialization is an ordinary class that can have a key
function (an out-of-line destructor), so its vtable is a strong symbol
that LTO must keep external. The primary templates and all user code
are unchanged, and no linker or compiler optimizations are disabled.

The non-template fixes (MemoryRetainerNode, JSGraphJSNode key
functions) and the N-API __attribute__((used)) changes are kept as-is.

Co-authored-by: Samuel Attard <sam@electronjs.org>
@trop trop Bot requested a review from a team as a code owner June 1, 2026 14:22
@trop trop Bot requested a review from ckerr June 1, 2026 14:22
@trop trop Bot mentioned this pull request Jun 1, 2026
5 tasks
@trop trop Bot added 43-x-y backport This is a backport PR semver/none labels Jun 1, 2026
@MarshallOfSound MarshallOfSound merged commit 05c3037 into 43-x-y Jun 1, 2026
61 checks passed
@MarshallOfSound MarshallOfSound deleted the trop/43-x-y-bp-build-re-enable-thinlto-on-macos-1780323710572 branch June 1, 2026 18:18
@release-clerk

release-clerk Bot commented Jun 1, 2026

Copy link
Copy Markdown

Release Notes Persisted

Enabled ThinLTO on macOS builds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants