From 9aa749f76f6da1291835859eac0673384dcccd94 Mon Sep 17 00:00:00 2001 From: Octavian Soldea Date: Thu, 5 Jul 2018 11:19:22 -0700 Subject: [PATCH 1/2] build: enabling lto at configure This modification allows for compiling with link time optimization (lto) using the flag --enable-lto. Refs: https://github.com/nodejs/node/issues/7400 --- common.gypi | 11 +++++++++++ configure | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/common.gypi b/common.gypi index d25a434b03d433..023e4f84cfcd5c 100644 --- a/common.gypi +++ b/common.gypi @@ -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' ] diff --git a/configure b/configure index 3a9ab42414569e..db27ef0b807456 100755 --- a/configure +++ b/configure @@ -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", @@ -932,6 +937,23 @@ 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]) + if is_clang or compiler_version < version_checked: + raise Exception( + 'The option --enable-lto is supported for ' + 'gcc and gxx 5.4.1 or newer only.') + + 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 From f2f7dba82ef72b9a1b8abec0cd666342fa2a6585 Mon Sep 17 00:00:00 2001 From: Octavian Soldea Date: Fri, 6 Jul 2018 16:45:46 -0700 Subject: [PATCH 2/2] build: enabling lto at configure This commit is a refactoring for testing that the compilers used for lto are gcc and g++ only. --- configure | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/configure b/configure index db27ef0b807456..2f57dcaa2f73a0 100755 --- a/configure +++ b/configure @@ -943,14 +943,16 @@ def configure_node(o): if flavor == 'linux': if options.enable_lto: - version_checked = '5.4.1' + 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]) - if is_clang or compiler_version < version_checked: + 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 5.4.1 or newer only.') + '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)