Skip to content

Commit c02fb88

Browse files
Octavian Soldeatargos
Octavian Soldea
authored andcommitted
build: enabling lto at configure
This modification allows for compiling with link time optimization (lto) using the flag --enable-lto. Refs: #7400 PR-URL: #21677 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 4b613d3 commit c02fb88

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

common.gypi

+11
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,17 @@
176176
['OS!="mac" and OS!="win"', {
177177
'cflags': [ '-fno-omit-frame-pointer' ],
178178
}],
179+
['OS=="linux"', {
180+
'variables': {
181+
'lto': ' -flto=4 -fuse-linker-plugin -ffat-lto-objects ',
182+
},
183+
'conditions': [
184+
['enable_lto=="true"', {
185+
'cflags': ['<(lto)'],
186+
'ldflags': ['<(lto)'],
187+
},],
188+
],
189+
},],
179190
['OS == "android"', {
180191
'cflags': [ '-fPIE' ],
181192
'ldflags': [ '-fPIE', '-pie' ]

configure

+24
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ parser.add_option("--enable-vtune-profiling",
157157
"JavaScript code executed in nodejs. This feature is only available "
158158
"for x32, x86, and x64 architectures.")
159159

160+
parser.add_option("--enable-lto",
161+
action="store_true",
162+
dest="enable_lto",
163+
help="Enable compiling with lto of a binary. This feature is only available "
164+
"on linux with gcc and g++.")
160165

161166
parser.add_option("--link-module",
162167
action="append",
@@ -932,6 +937,25 @@ def configure_node(o):
932937
else:
933938
o['variables']['node_enable_v8_vtunejit'] = 'false'
934939

940+
if flavor != 'linux' and (options.enable_lto):
941+
raise Exception(
942+
'The lto option is supported only on linux.')
943+
944+
if flavor == 'linux':
945+
if options.enable_lto:
946+
version_checked = (5, 4, 1)
947+
for compiler in [(CC, 'c'), (CXX, 'c++')]:
948+
ok, is_clang, clang_version, compiler_version = \
949+
try_check_compiler(compiler[0], compiler[1])
950+
compiler_version_num = tuple(map(int, compiler_version))
951+
if is_clang or compiler_version_num < version_checked:
952+
version_checked_str = ".".join(map(str, version_checked))
953+
raise Exception(
954+
'The option --enable-lto is supported for gcc and gxx %s'
955+
' or newer only.' % (version_checked_str))
956+
957+
o['variables']['enable_lto'] = b(options.enable_lto)
958+
935959
if flavor in ('solaris', 'mac', 'linux', 'freebsd'):
936960
use_dtrace = not options.without_dtrace
937961
# Don't enable by default on linux and freebsd

0 commit comments

Comments
 (0)