Skip to content

Commit 76ef7ac

Browse files
bzoztargos
authored andcommitted
build, win: make LTCG optional
Disables Link Time Code Generation by default. Adds ‘ltcg’ vcbuild option to enable it. LTCG will be used by default by release and CI builds. PR-URL: #21186 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 206e5bf commit 76ef7ac

3 files changed

Lines changed: 47 additions & 18 deletions

File tree

‎common.gypi‎

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
'node_use_v8_platform%': 'true',
1717
'node_use_bundled_v8%': 'true',
1818
'node_module_version%': '',
19+
'node_with_ltcg%': '',
1920

2021
'node_tag%': '',
2122
'uv_library%': 'static_library',
@@ -192,36 +193,51 @@
192193
'RuntimeLibrary': 0# MultiThreaded (/MT)
193194
}
194195
}
196+
}],
197+
['node_with_ltcg=="true"', {
198+
'msvs_settings': {
199+
'VCCLCompilerTool': {
200+
'WholeProgramOptimization': 'true'# /GL, whole program optimization, needed for LTCG
201+
},
202+
'VCLibrarianTool': {
203+
'AdditionalOptions': [
204+
'/LTCG:INCREMENTAL', # link time code generation
205+
]
206+
},
207+
'VCLinkerTool': {
208+
'OptimizeReferences': 2, # /OPT:REF
209+
'EnableCOMDATFolding': 2, # /OPT:ICF
210+
'LinkIncremental': 1, # disable incremental linking
211+
'AdditionalOptions': [
212+
'/LTCG:INCREMENTAL', # incremental link-time code generation
213+
]
214+
}
215+
}
216+
}, {
217+
'msvs_settings': {
218+
'VCCLCompilerTool': {
219+
'WholeProgramOptimization': 'false'
220+
},
221+
'VCLinkerTool': {
222+
'LinkIncremental': 2# enable incremental linking
223+
}
224+
}
195225
}]
196226
],
197227
'msvs_settings': {
198228
'VCCLCompilerTool': {
199229
'Optimization': 3, # /Ox, full optimization
200230
'FavorSizeOrSpeed': 1, # /Ot, favor speed over size
201231
'InlineFunctionExpansion': 2, # /Ob2, inline anything eligible
202-
'WholeProgramOptimization': 'true', # /GL, whole program optimization, needed for LTCG
203232
'OmitFramePointers': 'true',
204233
'EnableFunctionLevelLinking': 'true',
205234
'EnableIntrinsicFunctions': 'true',
206235
'RuntimeTypeInfo': 'false',
207236
'AdditionalOptions': [
208237
'/MP', # compile across multiple CPUs
209238
],
210-
},
211-
'VCLibrarianTool': {
212-
'AdditionalOptions': [
213-
'/LTCG', # link time code generation
214-
],
215-
},
216-
'VCLinkerTool': {
217-
'OptimizeReferences': 2, # /OPT:REF
218-
'EnableCOMDATFolding': 2, # /OPT:ICF
219-
'LinkIncremental': 1, # disable incremental linking
220-
'AdditionalOptions': [
221-
'/LTCG:INCREMENTAL', # incremental link-time code generation
222-
],
223-
},
224-
},
239+
}
240+
}
225241
}
226242
},
227243
# Forcibly disable -Werror. We support a wide range of compilers, it's

‎configure‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,11 @@ intl_optgroup.add_option('--with-icu-source',
425425
dest='with_icu_source',
426426
help='Intl mode: optional local path to icu/ dir, or path/URL of icu source archive.')
427427

428+
parser.add_option('--with-ltcg',
429+
action='store_true',
430+
dest='with_ltcg',
431+
help='Use Link Time Code Generation. This feature is only available on Windows.')
432+
428433
intl_optgroup.add_option('--download',
429434
action='store',
430435
dest='download_list',
@@ -953,6 +958,10 @@ def configure_node(o):
953958
else:
954959
o['variables']['node_use_perfctr'] = 'false'
955960

961+
o['variables']['node_with_ltcg'] = b(options.with_ltcg)
962+
if flavor != 'win' and options.with_ltcg:
963+
raise Exception('Link Time Code Generation is only supported on Windows.')
964+
956965
if options.tag:
957966
o['variables']['node_tag'] = '-' + options.tag
958967
else:

‎vcbuild.bat‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ cd %~dp0
1515
setconfig=Release
1616
settarget=Build
1717
settarget_arch=x64
18+
setltcg=
1819
settarget_env=
1920
setnoprojgen=
2021
setprojgen=
@@ -61,7 +62,7 @@ set doc=
6162
:next-arg
6263
if"%1"==""goto args-done
6364
if /i "%1"=="debug"setconfig=Debug&goto arg-ok
64-
if /i "%1"=="release"setconfig=Release&goto arg-ok
65+
if /i "%1"=="release"setconfig=Release&set ltcg=1&goto arg-ok
6566
if /i "%1"=="clean"settarget=Clean&goto arg-ok
6667
if /i "%1"=="ia32"settarget_arch=x86&goto arg-ok
6768
if /i "%1"=="x86"settarget_arch=x86&goto arg-ok
@@ -75,6 +76,7 @@ if /i "%1"=="sign" set sign=1&goto arg-ok
7576
if /i "%1"=="nosnapshot"setnosnapshot=1&goto arg-ok
7677
if /i "%1"=="noetw"setnoetw=1&goto arg-ok
7778
if /i "%1"=="noperfctr"setnoperfctr=1&goto arg-ok
79+
if /i "%1"=="ltcg"setltcg=1&goto arg-ok
7880
if /i "%1"=="licensertf"setlicensertf=1&goto arg-ok
7981
if /i "%1"=="test"settest_args=%test_args% -J %common_test_suites%&set lint_cpp=1&set lint_js=1&set lint_md=1&goto arg-ok
8082
if /i "%1"=="test-ci"settest_args=%test_args%%test_ci_args% -p tap --logfile test.tap %common_test_suites%&set cctest_args=%cctest_args% --gtest_output=tap:cctest.tap&goto arg-ok
@@ -150,6 +152,7 @@ if defined build_release (
150152
setdownload_arg="--download=all"
151153
seti18n_arg=small-icu
152154
setprojgen=1
155+
setltcg=1
153156
)
154157

155158
:: assign path to node_exe
@@ -162,6 +165,7 @@ if "%config%"=="Debug" set configure_flags=%configure_flags% --debug
162165
ifdefined nosnapshot setconfigure_flags=%configure_flags% --without-snapshot
163166
ifdefined noetw setconfigure_flags=%configure_flags% --without-etw&setnoetw_msi_arg=/p:NoETW=1
164167
ifdefined noperfctr setconfigure_flags=%configure_flags% --without-perfctr&setnoperfctr_msi_arg=/p:NoPerfCtr=1
168+
ifdefined ltcg setconfigure_flags=%configure_flags% --with-ltcg
165169
ifdefined release_urlbase setconfigure_flags=%configure_flags% --release-urlbase=%release_urlbase%
166170
ifdefined download_arg setconfigure_flags=%configure_flags%%download_arg%
167171
ifdefined enable_vtune_arg setconfigure_flags=%configure_flags% --enable-vtune-profiling
@@ -656,7 +660,7 @@ del .used_configure_flags
656660
gotoexit
657661

658662
:help
659-
echo vcbuild.bat [debug/release] [msi] [doc] [test/test-ci/test-all/test-addons/test-addons-napi/test-internet/test-pummel/test-simple/test-message/test-gc/test-tick-processor/test-known-issues/test-node-inspect/test-check-deopts/test-npm/test-async-hooks/test-v8/test-v8-intl/test-v8-benchmarks/test-v8-all] [ignore-flaky] [static/dll] [noprojgen] [projgen] [small-icu/full-icu/without-intl] [nobuild] [nosnapshot] [noetw] [noperfctr] [licensetf] [sign] [ia32/x86/x64] [vs2017] [download-all] [enable-vtune] [lint/lint-ci/lint-js/lint-js-ci/lint-md] [lint-md-build] [package] [build-release] [upload] [no-NODE-OPTIONS] [link-module path-to-module] [debug-http2] [debug-nghttp2] [clean] [no-cctest] [openssl-no-asm]
663+
echo vcbuild.bat [debug/release] [msi] [doc] [test/test-ci/test-all/test-addons/test-addons-napi/test-internet/test-pummel/test-simple/test-message/test-gc/test-tick-processor/test-known-issues/test-node-inspect/test-check-deopts/test-npm/test-async-hooks/test-v8/test-v8-intl/test-v8-benchmarks/test-v8-all] [ignore-flaky] [static/dll] [noprojgen] [projgen] [small-icu/full-icu/without-intl] [nobuild] [nosnapshot] [noetw] [noperfctr] [ltcg] [licensetf] [sign] [ia32/x86/x64] [vs2017] [download-all] [enable-vtune] [lint/lint-ci/lint-js/lint-js-ci/lint-md] [lint-md-build] [package] [build-release] [upload] [no-NODE-OPTIONS] [link-module path-to-module] [debug-http2] [debug-nghttp2] [clean] [no-cctest] [openssl-no-asm]
660664
echo Examples:
661665
echo vcbuild.bat : builds release build
662666
echo vcbuild.bat debug : builds debug build

0 commit comments

Comments
 (0)