diff --git a/common.gypi b/common.gypi index 0ce17772cf5e25..43cbd973fdfd38 100644 --- a/common.gypi +++ b/common.gypi @@ -28,6 +28,7 @@ 'clang%': 0, 'error_on_warn%': 'false', 'suppress_all_error_on_warn%': 'false', + 'control_flow_guard%': 'false', 'openssl_product': '<(STATIC_LIB_PREFIX)openssl<(STATIC_LIB_SUFFIX)', 'openssl_no_asm%': 0, @@ -310,6 +311,11 @@ '/Zm2000', ], }], + ['control_flow_guard=="true"', { + 'AdditionalOptions': [ + '/guard:cf', # Control Flow Guard + ], + }], ], 'BufferSecurityCheck': 'true', 'DebugInformationFormat': 1, # /Z7 embed info in .obj files @@ -336,6 +342,11 @@ ['target_arch=="arm64"', { 'TargetMachine' : 0, # NotSet. MACHINE:ARM64 is inferred from the input files. }], + ['control_flow_guard=="true"', { + 'AdditionalOptions': [ + '/guard:cf', # Control Flow Guard + ], + }], ], 'GenerateDebugInformation': 'true', 'SuppressStartupBanner': 'true', diff --git a/configure.py b/configure.py index 8e140ac6d67c66..6b91212c7bcd4c 100755 --- a/configure.py +++ b/configure.py @@ -819,6 +819,12 @@ default=None, 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 parser.add_argument('--without-report', action='store_true', @@ -1443,6 +1449,7 @@ def configure_node(o): o['variables']['node_prefix'] = options.prefix o['variables']['node_install_npm'] = b(not options.without_npm) 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']['debug_node'] = b(options.debug_node) o['default_configuration'] = 'Debug' if options.debug else 'Release' diff --git a/vcbuild.bat b/vcbuild.bat index eb8e5194f0fb8a..d2dbf423e5a9b6 100644 --- a/vcbuild.bat +++ b/vcbuild.bat @@ -72,6 +72,7 @@ set no_shared_roheap= set doc= set extra_msbuild_args= set compile_commands= +set cfg= set exit_code=0 :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"=="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"=="cfg" set cfg=1&goto arg-ok echo Error: invalid command line option `%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 ccache_path set configure_flags=%configure_flags% --use-ccache-win 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" ( echo "32-bit Windows builds are not supported anymore."