diff --git a/common.gypi b/common.gypi index 8da603d00f618e..5cfe457326774c 100644 --- a/common.gypi +++ b/common.gypi @@ -12,6 +12,7 @@ 'python%': 'python', 'node_tag%': '', + 'node_use_lto%': '', 'uv_library%': 'static_library', 'openssl_fips%': '', @@ -290,6 +291,13 @@ ], 'ldflags!': [ '-rdynamic' ], }], + ['node_use_lto=="true"', { + 'conditions': [ [ 'clang==1', { + 'cflags': [ '-flto' ], + }, { + 'cflags': [ '-flto=16' ], + } ] ], + }], ], }], [ 'OS=="android"', { @@ -343,6 +351,13 @@ 'CLANG_CXX_LANGUAGE_STANDARD': 'gnu++0x', # -std=gnu++0x }, }], + ['node_use_lto=="true"', { + 'xcode_settings': { + 'OTHER_CFLAGS': [ + '-flto', + ], + }, + }], ], }], ['OS=="freebsd" and node_use_dtrace=="true"', { diff --git a/configure b/configure index d622a6f0625a18..833ecbfa0b38ce 100755 --- a/configure +++ b/configure @@ -297,6 +297,11 @@ parser.add_option('--with-lttng', dest='with_lttng', help='build with Lttng (Only available to Linux)') +parser.add_option('--with-lto', + action='store_true', + dest='use_lto', + help='build with -flto flag (Link Time Optimization)') + parser.add_option('--with-etw', action='store_true', dest='with_etw', @@ -777,6 +782,8 @@ def configure_node(o): else: o['variables']['node_use_lttng'] = 'false' + o['variables']['node_use_lto'] = b(options.use_lto) + if options.no_ifaddrs: o['defines'] += ['SUNOS_NO_IFADDRS']