Skip to content

Commit b46b727

Browse files
build,win: enable full LTO
1 parent c5f9f10 commit b46b727

9 files changed

Lines changed: 255 additions & 6 deletions

File tree

common.gypi

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,32 @@
244244
},],
245245
['OS=="win"', {
246246
'conditions': [
247+
['enable_lto=="true"', {
248+
'msvs_settings': {
249+
'VCCLCompilerTool': {
250+
'AdditionalOptions': ['-flto=full'],
251+
},
252+
'VCLibrarianTool': {
253+
'AdditionalOptions': ['-flto=full'],
254+
},
255+
'VCLinkerTool': {
256+
'AdditionalOptions': ['-flto=full'],
257+
},
258+
},
259+
},],
260+
['enable_thin_lto=="true"', {
261+
'msvs_settings': {
262+
'VCCLCompilerTool': {
263+
'AdditionalOptions': ['-flto=thin'],
264+
},
265+
'VCLibrarianTool': {
266+
'AdditionalOptions': ['-flto=thin'],
267+
},
268+
'VCLinkerTool': {
269+
'AdditionalOptions': ['-flto=thin'],
270+
},
271+
},
272+
},],
247273
['enable_pgo_generate=="true"', {
248274
'msvs_settings': {
249275
'VCCLCompilerTool': {

configure.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,13 @@
218218
help="Enable compiling with lto of a binary. This feature is only available "
219219
"with gcc 5.4.1+ or clang 3.9.1+.")
220220

221+
parser.add_argument("--enable-thin-lto",
222+
action="store_true",
223+
dest="enable_thin_lto",
224+
default=None,
225+
help="Enable compiling with thin lto of a binary. This feature is only available "
226+
"on windows.")
227+
221228
parser.add_argument("--link-module",
222229
action="append",
223230
dest="linked_module",
@@ -919,7 +926,8 @@
919926
action='store_true',
920927
dest='with_ltcg',
921928
default=None,
922-
help='Use Thin LTO. This feature is only available on Windows.')
929+
help='Use Thin LTO scoped to node.exe and libnode only. '
930+
'This feature is only available on Windows.')
923931

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

1935-
if flavor == 'win' and (options.enable_lto):
1943+
if flavor != 'win' and options.enable_thin_lto:
19361944
raise Exception(
1937-
'Use Link Time Code Generation instead.')
1945+
'Use --enable-lto instead.')
1946+
1947+
# LTO mutual exclusion
1948+
if flavor == 'win':
1949+
lto_options = []
1950+
if options.enable_lto:
1951+
lto_options.append('--enable-lto')
1952+
if options.enable_thin_lto:
1953+
lto_options.append('--enable-thin-lto')
1954+
if options.with_ltcg:
1955+
lto_options.append('--with-ltcg')
1956+
if len(lto_options) > 1:
1957+
raise Exception(
1958+
f'Only one LTO option can be specified at a time: {", ".join(lto_options)}. '
1959+
'Use --enable-lto for Full LTO (global), '
1960+
'--enable-thin-lto for Thin LTO (global), '
1961+
'or --with-ltcg for Thin LTO (scoped to node.exe and libnode).')
19381962

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

19491973
o['variables']['enable_lto'] = b(options.enable_lto)
1974+
o['variables']['enable_thin_lto'] = b(options.enable_thin_lto)
19501975

19511976
if options.node_use_large_pages or options.node_use_large_pages_script_lld:
19521977
warn('''The `--use-largepages` and `--use-largepages-script-lld` options

deps/openssl/openssl-cli.gypi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,15 @@
2525
['enable_lto=="true"', {
2626
'ldflags': [ '-fno-lto' ],
2727
}],
28+
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
29+
'msvs_settings': {
30+
'VCCLCompilerTool': {
31+
'AdditionalOptions': ['-fno-lto'],
32+
},
33+
'VCLinkerTool': {
34+
'AdditionalOptions': ['-fno-lto'],
35+
},
36+
},
37+
}],
2838
],
2939
}

deps/openssl/openssl.gyp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@
7777
['enable_lto=="true"', {
7878
'ldflags': [ '-fno-lto' ],
7979
}],
80+
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
81+
'msvs_settings': {
82+
'VCCLCompilerTool': {
83+
'AdditionalOptions': ['-fno-lto'],
84+
},
85+
'VCLinkerTool': {
86+
'AdditionalOptions': ['-fno-lto'],
87+
},
88+
},
89+
}],
8090
]
8191
}, {
8292
# openssl-fipsmodule target

node.gyp

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@
742742
},
743743
}],
744744
# Whole-program optimization: either Thin LTO or PGO
745-
['node_with_ltcg=="true" or enable_pgo_generate=="true" or enable_pgo_use=="true"', {
745+
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true" or enable_pgo_generate=="true" or enable_pgo_use=="true"', {
746746
'msvs_settings': {
747747
'VCLinkerTool': {
748748
'OptimizeReferences': 2, # /OPT:REF
@@ -1471,6 +1471,16 @@
14711471
['enable_lto=="true"', {
14721472
'ldflags': [ '-fno-lto' ],
14731473
}],
1474+
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
1475+
'msvs_settings': {
1476+
'VCCLCompilerTool': {
1477+
'AdditionalOptions': ['-fno-lto'],
1478+
},
1479+
'VCLinkerTool': {
1480+
'AdditionalOptions': ['-fno-lto'],
1481+
},
1482+
},
1483+
}],
14741484
],
14751485
}, # cctest
14761486

@@ -1535,6 +1545,16 @@
15351545
['enable_lto=="true"', {
15361546
'ldflags': [ '-fno-lto' ],
15371547
}],
1548+
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
1549+
'msvs_settings': {
1550+
'VCCLCompilerTool': {
1551+
'AdditionalOptions': ['-fno-lto'],
1552+
},
1553+
'VCLinkerTool': {
1554+
'AdditionalOptions': ['-fno-lto'],
1555+
},
1556+
},
1557+
}],
15381558
],
15391559
}, # embedtest
15401560

@@ -1612,6 +1632,16 @@
16121632
['enable_lto=="true"', {
16131633
'ldflags': [ '-fno-lto' ],
16141634
}],
1635+
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
1636+
'msvs_settings': {
1637+
'VCCLCompilerTool': {
1638+
'AdditionalOptions': ['-fno-lto'],
1639+
},
1640+
'VCLinkerTool': {
1641+
'AdditionalOptions': ['-fno-lto'],
1642+
},
1643+
},
1644+
}],
16151645
]
16161646
}, # overlapped-checker
16171647
{
@@ -1738,6 +1768,16 @@
17381768
['enable_lto=="true"', {
17391769
'ldflags': [ '-fno-lto' ],
17401770
}],
1771+
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
1772+
'msvs_settings': {
1773+
'VCCLCompilerTool': {
1774+
'AdditionalOptions': ['-fno-lto'],
1775+
},
1776+
'VCLinkerTool': {
1777+
'AdditionalOptions': ['-fno-lto'],
1778+
},
1779+
},
1780+
}],
17411781
],
17421782
}, # node_mksnapshot
17431783
], # end targets

tools/icu/icu-generic.gyp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,16 @@
456456
['enable_lto=="true"', {
457457
'ldflags': [ '-fno-lto' ],
458458
}],
459+
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
460+
'msvs_settings': {
461+
'VCCLCompilerTool': {
462+
'AdditionalOptions': ['-fno-lto'],
463+
},
464+
'VCLinkerTool': {
465+
'AdditionalOptions': ['-fno-lto'],
466+
},
467+
},
468+
}],
459469
],
460470
},
461471
# This tool is used to rebuild res_index.res manifests
@@ -473,6 +483,16 @@
473483
['enable_lto=="true"', {
474484
'ldflags': [ '-fno-lto' ],
475485
}],
486+
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
487+
'msvs_settings': {
488+
'VCCLCompilerTool': {
489+
'AdditionalOptions': ['-fno-lto'],
490+
},
491+
'VCLinkerTool': {
492+
'AdditionalOptions': ['-fno-lto'],
493+
},
494+
},
495+
}],
476496
],
477497
},
478498
# This tool is used to package, unpackage, repackage .dat files
@@ -491,6 +511,16 @@
491511
['enable_lto=="true"', {
492512
'ldflags': [ '-fno-lto' ],
493513
}],
514+
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
515+
'msvs_settings': {
516+
'VCCLCompilerTool': {
517+
'AdditionalOptions': ['-fno-lto'],
518+
},
519+
'VCLinkerTool': {
520+
'AdditionalOptions': ['-fno-lto'],
521+
},
522+
},
523+
}],
494524
],
495525
},
496526
# this is used to convert .dat directly into .obj
@@ -508,6 +538,16 @@
508538
['enable_lto=="true"', {
509539
'ldflags': [ '-fno-lto' ],
510540
}],
541+
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
542+
'msvs_settings': {
543+
'VCCLCompilerTool': {
544+
'AdditionalOptions': ['-fno-lto'],
545+
},
546+
'VCLinkerTool': {
547+
'AdditionalOptions': ['-fno-lto'],
548+
},
549+
},
550+
}],
511551
],
512552
},
513553
],

tools/v8_gypfiles/d8.gyp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@
6767
['enable_lto=="true"', {
6868
'ldflags': [ '-fno-lto' ],
6969
}],
70+
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
71+
'msvs_settings': {
72+
'VCCLCompilerTool': {
73+
'AdditionalOptions': ['-fno-lto'],
74+
},
75+
'VCLinkerTool': {
76+
'AdditionalOptions': ['-fno-lto'],
77+
},
78+
},
79+
}],
7080
],
7181
},
7282
],

0 commit comments

Comments
 (0)