Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
'msvs_multi_core_compile': '0', # we do enable multicore compiles, but not using the V8 way
'enable_pgo_generate%': '0',
'enable_pgo_use%': '0',
'clang_profile_lib%': '',
'python%': 'python',

'node_shared%': 'false',
Expand Down Expand Up @@ -242,6 +243,65 @@
},],
],
},],
['OS=="win"', {
'conditions': [
['enable_lto=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': ['-flto=full'],
},
'VCLibrarianTool': {
'AdditionalOptions': ['-flto=full'],
},
'VCLinkerTool': {
'AdditionalOptions': ['-flto=full'],
},
},
},],
['enable_thin_lto=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': ['-flto=thin'],
},
'VCLibrarianTool': {
'AdditionalOptions': ['-flto=thin'],
},
'VCLinkerTool': {
'AdditionalOptions': ['-flto=thin'],
},
},
},],
],
'target_conditions': [
['_toolset=="target"', {
'conditions': [
['enable_pgo_generate=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': ['-fprofile-generate'],
},
'VCLinkerTool': {
'AdditionalOptions': [
'/NODEFAULTLIB:clang_rt.profile.lib',
'"<(clang_profile_lib)"',
],
},
},
},],
['enable_pgo_use=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': ['-fprofile-use=$(SolutionDir)node.profdata'],
},
'VCLinkerTool': {
'AdditionalOptions': ['-fprofile-use=$(SolutionDir)node.profdata'],
},
},
},],
],
},],
],
},],
['OS == "android"', {
'cflags': [ '-fPIC', '-I<(android_ndk_path)/sources/android/cpufeatures' ],
'ldflags': [ '-fPIC' ]
Expand Down
71 changes: 57 additions & 14 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,14 @@
dest="enable_pgo_generate",
default=None,
help="Enable profiling with pgo of a binary. This feature is only available "
"on linux with gcc and g++ 5.4.1 or newer.")
"on linux with gcc and g++ 5.4.1 or newer and on windows.")

parser.add_argument("--enable-pgo-use",
action="store_true",
dest="enable_pgo_use",
default=None,
help="Enable use of the profile generated with --enable-pgo-generate. This "
"feature is only available on linux with gcc and g++ 5.4.1 or newer.")
"feature is only available on linux with gcc and g++ 5.4.1 or newer and on windows.")

parser.add_argument("--enable-lto",
action="store_true",
Expand All @@ -218,6 +218,13 @@
help="Enable compiling with lto of a binary. This feature is only available "
"with gcc 5.4.1+ or clang 3.9.1+.")

parser.add_argument("--enable-thin-lto",
action="store_true",
dest="enable_thin_lto",
default=None,
help="Enable compiling with thin lto of a binary. This feature is only available "
"on windows.")

parser.add_argument("--link-module",
action="append",
dest="linked_module",
Expand Down Expand Up @@ -919,7 +926,8 @@
action='store_true',
dest='with_ltcg',
default=None,
help='Use Link Time Code Generation. This feature is only available on Windows.')
help='Use Thin LTO scoped to node.exe and libnode only. '
'This feature is only available on Windows.')

parser.add_argument('--write-snapshot-as-array-literals',
action='store_true',
Expand Down Expand Up @@ -1909,9 +1917,9 @@ def configure_node(o):
else:
o['variables']['node_enable_v8_vtunejit'] = 'false'

if flavor != 'linux' and (options.enable_pgo_generate or options.enable_pgo_use):
if (flavor != 'linux' and flavor != 'win') and (options.enable_pgo_generate or options.enable_pgo_use):
raise Exception(
'The pgo option is supported only on linux.')
'The pgo option is supported only on linux and windows.')

if flavor == 'linux':
if options.enable_pgo_generate or options.enable_pgo_use:
Expand All @@ -1922,21 +1930,55 @@ def configure_node(o):
'The options --enable-pgo-generate and --enable-pgo-use '
f'are supported for gcc and gxx {version_checked_str} or newer only.')

if options.enable_pgo_generate and options.enable_pgo_use:
raise Exception(
'Only one of the --enable-pgo-generate or --enable-pgo-use options '
'can be specified at a time. You would like to use '
'--enable-pgo-generate first, profile node, and then recompile '
'with --enable-pgo-use')
if options.enable_pgo_generate and options.enable_pgo_use:
raise Exception(
'Only one of the --enable-pgo-generate or --enable-pgo-use options '
'can be specified at a time. You would like to use '
'--enable-pgo-generate first, profile node, and then recompile '
'with --enable-pgo-use')

o['variables']['enable_pgo_generate'] = b(options.enable_pgo_generate)
o['variables']['enable_pgo_use'] = b(options.enable_pgo_use)

if flavor == 'win' and (options.enable_lto):
if flavor == 'win' and (options.enable_pgo_generate or options.enable_pgo_use):
lib_suffix = 'aarch64' if target_arch == 'arm64' else 'x86_64'
lib_name = f'clang_rt.profile-{lib_suffix}.lib'
msvc_dir = target_arch # 'x64' or 'arm64'

vc_tools_dir = os.environ.get('VCToolsInstallDir', '')
if vc_tools_dir:
clang_profile_lib = os.path.join(vc_tools_dir, 'lib', msvc_dir, lib_name)
if os.path.isfile(clang_profile_lib):
o['variables']['clang_profile_lib'] = clang_profile_lib
else:
raise Exception(
f'PGO profile runtime library not found at {clang_profile_lib}. '
'Ensure the ClangCL toolset is installed.')
else:
raise Exception(
'VCToolsInstallDir not set. Run from a Visual Studio command prompt.')

if flavor != 'win' and options.enable_thin_lto:
raise Exception(
'Use Link Time Code Generation instead.')
'Use --enable-lto instead.')

# LTO mutual exclusion
if flavor == 'win':
lto_options = []
if options.enable_lto:
lto_options.append('--enable-lto')
if options.enable_thin_lto:
lto_options.append('--enable-thin-lto')
if options.with_ltcg:
lto_options.append('--with-ltcg')
if len(lto_options) > 1:
raise Exception(
f'Only one LTO option can be specified at a time: {", ".join(lto_options)}. '
'Use --enable-lto for Full LTO (global), '
'--enable-thin-lto for Thin LTO (global), '
'or --with-ltcg for Thin LTO (scoped to node.exe and libnode).')

if options.enable_lto:
if options.enable_lto and flavor != 'win':
gcc_version_checked = (5, 4, 1)
clang_version_checked = (3, 9, 1)
if not gcc_version_ge(gcc_version_checked) and not clang_version_ge(clang_version_checked):
Expand All @@ -1947,6 +1989,7 @@ def configure_node(o):
f'or clang {clang_version_checked_str}+ only.')

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

if options.node_use_large_pages or options.node_use_large_pages_script_lld:
warn('''The `--use-largepages` and `--use-largepages-script-lld` options
Expand Down
10 changes: 10 additions & 0 deletions deps/openssl/openssl-cli.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,15 @@
['enable_lto=="true"', {
'ldflags': [ '-fno-lto' ],
}],
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': ['-fno-lto'],
},
'VCLinkerTool': {
'AdditionalOptions': ['-fno-lto'],
},
},
}],
],
}
10 changes: 10 additions & 0 deletions deps/openssl/openssl.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@
['enable_lto=="true"', {
'ldflags': [ '-fno-lto' ],
}],
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': ['-fno-lto'],
},
'VCLinkerTool': {
'AdditionalOptions': ['-fno-lto'],
},
},
}],
]
}, {
# openssl-fipsmodule target
Expand Down
80 changes: 65 additions & 15 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -730,35 +730,34 @@
'Ws2_32.lib',
],
}],
# Thin LTO for node_main.cc and linker (scoped to node_exe)
['node_with_ltcg=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'WholeProgramOptimization': 'true' # /GL, whole program optimization, needed for LTCG
'AdditionalOptions': ['-flto=thin'],
},
'VCLibrarianTool': {
'AdditionalOptions': [
'/LTCG:INCREMENTAL', # link time code generation
],
'VCLinkerTool': {
'AdditionalOptions': ['-flto=thin'],
},
},
}],
# Whole-program optimization: either Thin LTO or PGO
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true" or enable_pgo_generate=="true" or enable_pgo_use=="true"', {
'msvs_settings': {
'VCLinkerTool': {
'OptimizeReferences': 2, # /OPT:REF
'EnableCOMDATFolding': 2, # /OPT:ICF
'LinkIncremental': 1, # disable incremental linking
'AdditionalOptions': [
'/LTCG:INCREMENTAL', # incremental link-time code generation
],
}
}
},
},
}, {
# No whole-program optimization
'msvs_settings': {
'VCCLCompilerTool': {
'WholeProgramOptimization': 'false'
},
'VCLinkerTool': {
'LinkIncremental': 2 # enable incremental linking
'LinkIncremental': 2, # enable incremental linking
},
},
}],
}],
['node_use_node_snapshot=="true"', {
'dependencies': [
'node_mksnapshot',
Expand Down Expand Up @@ -1161,6 +1160,17 @@
[ 'debug_nghttp2==1', {
'defines': [ 'NODE_DEBUG_NGHTTP2=1' ]
}],
# Thin LTO for node sources (scoped to libnode, not global)
['node_with_ltcg=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': ['-flto=thin'],
},
'VCLibrarianTool': {
'AdditionalOptions': ['-flto=thin'],
},
},
}],
],
'actions': [
{
Expand Down Expand Up @@ -1461,6 +1471,16 @@
['enable_lto=="true"', {
'ldflags': [ '-fno-lto' ],
}],
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': ['-fno-lto'],
},
'VCLinkerTool': {
'AdditionalOptions': ['-fno-lto'],
},
},
}],
],
}, # cctest

Expand Down Expand Up @@ -1525,6 +1545,16 @@
['enable_lto=="true"', {
'ldflags': [ '-fno-lto' ],
}],
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': ['-fno-lto'],
},
'VCLinkerTool': {
'AdditionalOptions': ['-fno-lto'],
},
},
}],
],
}, # embedtest

Expand Down Expand Up @@ -1602,6 +1632,16 @@
['enable_lto=="true"', {
'ldflags': [ '-fno-lto' ],
}],
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': ['-fno-lto'],
},
'VCLinkerTool': {
'AdditionalOptions': ['-fno-lto'],
},
},
}],
]
}, # overlapped-checker
{
Expand Down Expand Up @@ -1728,6 +1768,16 @@
['enable_lto=="true"', {
'ldflags': [ '-fno-lto' ],
}],
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': ['-fno-lto'],
},
'VCLinkerTool': {
'AdditionalOptions': ['-fno-lto'],
},
},
}],
],
}, # node_mksnapshot
], # end targets
Expand Down
Loading
Loading