win,build: add option to enable Control Flow Guard

PR-URL: https://github.com/nodejs/node/pull/56605
Fixes: https://github.com/nodejs/node/issues/42100
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
This commit is contained in:
Hüseyin Açacak 2025-03-07 10:09:26 +03:00 committed by GitHub
parent 365faa7a4f
commit f161033bd5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 0 deletions

View File

@ -28,6 +28,7 @@
'clang%': 0, 'clang%': 0,
'error_on_warn%': 'false', 'error_on_warn%': 'false',
'suppress_all_error_on_warn%': 'false', 'suppress_all_error_on_warn%': 'false',
'control_flow_guard%': 'false',
'openssl_product': '<(STATIC_LIB_PREFIX)openssl<(STATIC_LIB_SUFFIX)', 'openssl_product': '<(STATIC_LIB_PREFIX)openssl<(STATIC_LIB_SUFFIX)',
'openssl_no_asm%': 0, 'openssl_no_asm%': 0,
@ -310,6 +311,11 @@
'/Zm2000', '/Zm2000',
], ],
}], }],
['control_flow_guard=="true"', {
'AdditionalOptions': [
'/guard:cf', # Control Flow Guard
],
}],
], ],
'BufferSecurityCheck': 'true', 'BufferSecurityCheck': 'true',
'DebugInformationFormat': 1, # /Z7 embed info in .obj files 'DebugInformationFormat': 1, # /Z7 embed info in .obj files
@ -336,6 +342,11 @@
['target_arch=="arm64"', { ['target_arch=="arm64"', {
'TargetMachine' : 0, # NotSet. MACHINE:ARM64 is inferred from the input files. 'TargetMachine' : 0, # NotSet. MACHINE:ARM64 is inferred from the input files.
}], }],
['control_flow_guard=="true"', {
'AdditionalOptions': [
'/guard:cf', # Control Flow Guard
],
}],
], ],
'GenerateDebugInformation': 'true', 'GenerateDebugInformation': 'true',
'SuppressStartupBanner': 'true', 'SuppressStartupBanner': 'true',

View File

@ -819,6 +819,12 @@ parser.add_argument('--without-corepack',
default=None, default=None,
help='do not install the bundled Corepack') help='do not install the bundled Corepack')
parser.add_argument('--control-flow-guard',
action='store_true',
dest='enable_cfg',
default=None,
help='enable Control Flow Guard (CFG)')
# Dummy option for backwards compatibility # Dummy option for backwards compatibility
parser.add_argument('--without-report', parser.add_argument('--without-report',
action='store_true', action='store_true',
@ -1443,6 +1449,7 @@ def configure_node(o):
o['variables']['node_prefix'] = options.prefix o['variables']['node_prefix'] = options.prefix
o['variables']['node_install_npm'] = b(not options.without_npm) o['variables']['node_install_npm'] = b(not options.without_npm)
o['variables']['node_install_corepack'] = b(not options.without_corepack) o['variables']['node_install_corepack'] = b(not options.without_corepack)
o['variables']['control_flow_guard'] = b(options.enable_cfg)
o['variables']['node_use_amaro'] = b(not options.without_amaro) o['variables']['node_use_amaro'] = b(not options.without_amaro)
o['variables']['debug_node'] = b(options.debug_node) o['variables']['debug_node'] = b(options.debug_node)
o['default_configuration'] = 'Debug' if options.debug else 'Release' o['default_configuration'] = 'Debug' if options.debug else 'Release'

View File

@ -72,6 +72,7 @@ set no_shared_roheap=
set doc= set doc=
set extra_msbuild_args= set extra_msbuild_args=
set compile_commands= set compile_commands=
set cfg=
set exit_code=0 set exit_code=0
:next-arg :next-arg
@ -150,6 +151,7 @@ if /i "%1"=="no-shared-roheap" set no_shared_roheap=1&goto arg-ok
if /i "%1"=="doc" set doc=1&goto arg-ok if /i "%1"=="doc" set doc=1&goto arg-ok
if /i "%1"=="binlog" set extra_msbuild_args=/binaryLogger:out\%config%\node.binlog&goto arg-ok if /i "%1"=="binlog" set extra_msbuild_args=/binaryLogger:out\%config%\node.binlog&goto arg-ok
if /i "%1"=="compile-commands" set compile_commands=1&goto arg-ok if /i "%1"=="compile-commands" set compile_commands=1&goto arg-ok
if /i "%1"=="cfg" set cfg=1&goto arg-ok
echo Error: invalid command line option `%1`. echo Error: invalid command line option `%1`.
exit /b 1 exit /b 1
@ -210,6 +212,7 @@ if defined no_shared_roheap set configure_flags=%configure_flags% --disable-shar
if defined DEBUG_HELPER set configure_flags=%configure_flags% --verbose if defined DEBUG_HELPER set configure_flags=%configure_flags% --verbose
if defined ccache_path set configure_flags=%configure_flags% --use-ccache-win if defined ccache_path set configure_flags=%configure_flags% --use-ccache-win
if defined compile_commands set configure_flags=%configure_flags% -C if defined compile_commands set configure_flags=%configure_flags% -C
if defined cfg set configure_flags=%configure_flags% --control-flow-guard
if "%target_arch%"=="x86" ( if "%target_arch%"=="x86" (
echo "32-bit Windows builds are not supported anymore." echo "32-bit Windows builds are not supported anymore."