Skip to content

Commit

Permalink
build: enabling lto at configure
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Octavian Soldea authored and targos committed Jul 14, 2018
1 parent 4b613d3 commit c02fb88
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
11 changes: 11 additions & 0 deletions common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,17 @@
['OS!="mac" and OS!="win"', {
'cflags': [ '-fno-omit-frame-pointer' ],
}],
['OS=="linux"', {
'variables': {
'lto': ' -flto=4 -fuse-linker-plugin -ffat-lto-objects ',
},
'conditions': [
['enable_lto=="true"', {
'cflags': ['<(lto)'],
'ldflags': ['<(lto)'],
},],
],
},],
['OS == "android"', {
'cflags': [ '-fPIE' ],
'ldflags': [ '-fPIE', '-pie' ]
Expand Down
24 changes: 24 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ parser.add_option("--enable-vtune-profiling",
"JavaScript code executed in nodejs. This feature is only available "
"for x32, x86, and x64 architectures.")

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

parser.add_option("--link-module",
action="append",
Expand Down Expand Up @@ -932,6 +937,25 @@ def configure_node(o):
else:
o['variables']['node_enable_v8_vtunejit'] = 'false'

if flavor != 'linux' and (options.enable_lto):
raise Exception(
'The lto option is supported only on linux.')

if flavor == 'linux':
if options.enable_lto:
version_checked = (5, 4, 1)
for compiler in [(CC, 'c'), (CXX, 'c++')]:
ok, is_clang, clang_version, compiler_version = \
try_check_compiler(compiler[0], compiler[1])
compiler_version_num = tuple(map(int, compiler_version))
if is_clang or compiler_version_num < version_checked:
version_checked_str = ".".join(map(str, version_checked))
raise Exception(
'The option --enable-lto is supported for gcc and gxx %s'
' or newer only.' % (version_checked_str))

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

if flavor in ('solaris', 'mac', 'linux', 'freebsd'):
use_dtrace = not options.without_dtrace
# Don't enable by default on linux and freebsd
Expand Down

0 comments on commit c02fb88

Please sign in to comment.