diff --git a/common.gypi b/common.gypi index d87205e5c320cf..22d493b5668e60 100644 --- a/common.gypi +++ b/common.gypi @@ -18,6 +18,7 @@ 'node_module_version%': '', 'node_tag%': '', + 'node_use_lto%': '', 'uv_library%': 'static_library', 'openssl_fips%': '', @@ -333,6 +334,13 @@ [ 'node_shared=="true"', { 'cflags': [ '-fPIC' ], }], + ['node_use_lto=="true"', { + 'conditions': [ [ 'clang==1', { + 'cflags': [ '-flto' ], + }, { + 'cflags': [ '-flto=16' ], + } ] ], + }], ], }], ['OS=="android"', { @@ -391,6 +399,13 @@ 'CLANG_CXX_LIBRARY': 'libc++', }, }], + ['node_use_lto=="true"', { + 'xcode_settings': { + 'OTHER_CFLAGS': [ + '-flto', + ], + }, + }], ], }], ['OS=="freebsd" and node_use_dtrace=="true"', { diff --git a/configure b/configure index 9cadfffbd060f1..f674d0e3107275 100755 --- a/configure +++ b/configure @@ -331,6 +331,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', @@ -838,6 +843,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']