Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
build,win: enable full LTO
  • Loading branch information
StefanStojanovic committed Apr 15, 2026
commit b46b727fd8bbd6a1163038b994abd25f260a97ef
26 changes: 26 additions & 0 deletions common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,32 @@
},],
['OS=="win"', {
'conditions': [
['enable_lto=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': ['-flto=full'],
},
'VCLibrarianTool': {
'AdditionalOptions': ['-flto=full'],
},
'VCLinkerTool': {
'AdditionalOptions': ['-flto=full'],
},
},
},],
['enable_thin_lto=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': ['-flto=thin'],
},
'VCLibrarianTool': {
'AdditionalOptions': ['-flto=thin'],
},
'VCLinkerTool': {
'AdditionalOptions': ['-flto=thin'],
},
},
},],
['enable_pgo_generate=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
Expand Down
33 changes: 29 additions & 4 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@
help="Enable compiling with lto of a binary. This feature is only available "
"with gcc 5.4.1+ or clang 3.9.1+.")

parser.add_argument("--enable-thin-lto",
action="store_true",
dest="enable_thin_lto",
default=None,
help="Enable compiling with thin lto of a binary. This feature is only available "
"on windows.")

parser.add_argument("--link-module",
action="append",
dest="linked_module",
Expand Down Expand Up @@ -919,7 +926,8 @@
action='store_true',
dest='with_ltcg',
default=None,
help='Use Thin LTO. This feature is only available on Windows.')
help='Use Thin LTO scoped to node.exe and libnode only. '
'This feature is only available on Windows.')

parser.add_argument('--write-snapshot-as-array-literals',
action='store_true',
Expand Down Expand Up @@ -1932,11 +1940,27 @@ def configure_node(o):
o['variables']['enable_pgo_generate'] = b(options.enable_pgo_generate)
o['variables']['enable_pgo_use'] = b(options.enable_pgo_use)

if flavor == 'win' and (options.enable_lto):
if flavor != 'win' and options.enable_thin_lto:
raise Exception(
'Use Link Time Code Generation instead.')
'Use --enable-lto instead.')

# LTO mutual exclusion
if flavor == 'win':
lto_options = []
if options.enable_lto:
lto_options.append('--enable-lto')
if options.enable_thin_lto:
lto_options.append('--enable-thin-lto')
if options.with_ltcg:
lto_options.append('--with-ltcg')
if len(lto_options) > 1:
raise Exception(
f'Only one LTO option can be specified at a time: {", ".join(lto_options)}. '
'Use --enable-lto for Full LTO (global), '
'--enable-thin-lto for Thin LTO (global), '
'or --with-ltcg for Thin LTO (scoped to node.exe and libnode).')

if options.enable_lto:
if options.enable_lto and flavor != 'win':
gcc_version_checked = (5, 4, 1)
clang_version_checked = (3, 9, 1)
if not gcc_version_ge(gcc_version_checked) and not clang_version_ge(clang_version_checked):
Expand All @@ -1947,6 +1971,7 @@ def configure_node(o):
f'or clang {clang_version_checked_str}+ only.')

o['variables']['enable_lto'] = b(options.enable_lto)
o['variables']['enable_thin_lto'] = b(options.enable_thin_lto)

if options.node_use_large_pages or options.node_use_large_pages_script_lld:
warn('''The `--use-largepages` and `--use-largepages-script-lld` options
Expand Down
10 changes: 10 additions & 0 deletions deps/openssl/openssl-cli.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,15 @@
['enable_lto=="true"', {
'ldflags': [ '-fno-lto' ],
}],
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': ['-fno-lto'],
},
'VCLinkerTool': {
'AdditionalOptions': ['-fno-lto'],
},
},
}],
],
}
10 changes: 10 additions & 0 deletions deps/openssl/openssl.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@
['enable_lto=="true"', {
'ldflags': [ '-fno-lto' ],
}],
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': ['-fno-lto'],
},
'VCLinkerTool': {
'AdditionalOptions': ['-fno-lto'],
},
},
}],
]
}, {
# openssl-fipsmodule target
Expand Down
42 changes: 41 additions & 1 deletion node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@
},
}],
# Whole-program optimization: either Thin LTO or PGO
['node_with_ltcg=="true" or enable_pgo_generate=="true" or enable_pgo_use=="true"', {
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true" or enable_pgo_generate=="true" or enable_pgo_use=="true"', {
'msvs_settings': {
'VCLinkerTool': {
'OptimizeReferences': 2, # /OPT:REF
Expand Down Expand Up @@ -1471,6 +1471,16 @@
['enable_lto=="true"', {
'ldflags': [ '-fno-lto' ],
}],
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': ['-fno-lto'],
},
'VCLinkerTool': {
'AdditionalOptions': ['-fno-lto'],
},
},
}],
],
}, # cctest

Expand Down Expand Up @@ -1535,6 +1545,16 @@
['enable_lto=="true"', {
'ldflags': [ '-fno-lto' ],
}],
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': ['-fno-lto'],
},
'VCLinkerTool': {
'AdditionalOptions': ['-fno-lto'],
},
},
}],
],
}, # embedtest

Expand Down Expand Up @@ -1612,6 +1632,16 @@
['enable_lto=="true"', {
'ldflags': [ '-fno-lto' ],
}],
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': ['-fno-lto'],
},
'VCLinkerTool': {
'AdditionalOptions': ['-fno-lto'],
},
},
}],
]
}, # overlapped-checker
{
Expand Down Expand Up @@ -1738,6 +1768,16 @@
['enable_lto=="true"', {
'ldflags': [ '-fno-lto' ],
}],
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': ['-fno-lto'],
},
'VCLinkerTool': {
'AdditionalOptions': ['-fno-lto'],
},
},
}],
],
}, # node_mksnapshot
], # end targets
Expand Down
40 changes: 40 additions & 0 deletions tools/icu/icu-generic.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,16 @@
['enable_lto=="true"', {
'ldflags': [ '-fno-lto' ],
}],
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': ['-fno-lto'],
},
'VCLinkerTool': {
'AdditionalOptions': ['-fno-lto'],
},
},
}],
],
},
# This tool is used to rebuild res_index.res manifests
Expand All @@ -473,6 +483,16 @@
['enable_lto=="true"', {
'ldflags': [ '-fno-lto' ],
}],
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': ['-fno-lto'],
},
'VCLinkerTool': {
'AdditionalOptions': ['-fno-lto'],
},
},
}],
],
},
# This tool is used to package, unpackage, repackage .dat files
Expand All @@ -491,6 +511,16 @@
['enable_lto=="true"', {
'ldflags': [ '-fno-lto' ],
}],
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': ['-fno-lto'],
},
'VCLinkerTool': {
'AdditionalOptions': ['-fno-lto'],
},
},
}],
],
},
# this is used to convert .dat directly into .obj
Expand All @@ -508,6 +538,16 @@
['enable_lto=="true"', {
'ldflags': [ '-fno-lto' ],
}],
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': ['-fno-lto'],
},
'VCLinkerTool': {
'AdditionalOptions': ['-fno-lto'],
},
},
}],
],
},
],
Expand Down
10 changes: 10 additions & 0 deletions tools/v8_gypfiles/d8.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@
['enable_lto=="true"', {
'ldflags': [ '-fno-lto' ],
}],
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': ['-fno-lto'],
},
'VCLinkerTool': {
'AdditionalOptions': ['-fno-lto'],
},
},
}],
],
},
],
Expand Down
Loading